Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

drm/ttm: merge ttm_bo_api.h and ttm_bo_driver.h v2

Merge and cleanup the two headers into a single description of the
object API. Also move all the documentation to the implementation and
drop unnecessary includes from the header.

No functional change.

v2: minimal checkpatch.pl cleanup

Signed-off-by: Christian König <christian.koenig@amd.com>
Reviewed-by: Arunpravin Paneer Selvam <Arunpravin.PaneerSelvam@amd.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20221125102137.1801-4-christian.koenig@amd.com

+410 -557
+1 -2
drivers/gpu/drm/amd/amdgpu/amdgpu.h
··· 52 52 #include <linux/pci.h> 53 53 #include <linux/aer.h> 54 54 55 - #include <drm/ttm/ttm_bo_api.h> 56 - #include <drm/ttm/ttm_bo_driver.h> 55 + #include <drm/ttm/ttm_bo.h> 57 56 #include <drm/ttm/ttm_placement.h> 58 57 #include <drm/ttm/ttm_execbuf_util.h> 59 58
+1
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
··· 25 25 #include <linux/pagemap.h> 26 26 #include <linux/sched/mm.h> 27 27 #include <linux/sched/task.h> 28 + #include <drm/ttm/ttm_tt.h> 28 29 29 30 #include "amdgpu_object.h" 30 31 #include "amdgpu_gem.h"
+2
drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.h
··· 28 28 29 29 struct hmm_range; 30 30 31 + struct drm_file; 32 + 31 33 struct amdgpu_device; 32 34 struct amdgpu_bo; 33 35 struct amdgpu_bo_va;
+2
drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
··· 32 32 33 33 #include <drm/amdgpu_drm.h> 34 34 #include <drm/drm_syncobj.h> 35 + #include <drm/ttm/ttm_tt.h> 36 + 35 37 #include "amdgpu_cs.h" 36 38 #include "amdgpu.h" 37 39 #include "amdgpu_trace.h"
+2
drivers/gpu/drm/amd/amdgpu/amdgpu_cs.h
··· 23 23 #ifndef __AMDGPU_CS_H__ 24 24 #define __AMDGPU_CS_H__ 25 25 26 + #include <linux/ww_mutex.h> 27 + 26 28 #include "amdgpu_job.h" 27 29 #include "amdgpu_bo_list.h" 28 30 #include "amdgpu_ring.h"
+1
drivers/gpu/drm/amd/amdgpu/amdgpu_dma_buf.c
··· 37 37 #include "amdgpu_dma_buf.h" 38 38 #include "amdgpu_xgmi.h" 39 39 #include <drm/amdgpu_drm.h> 40 + #include <drm/ttm/ttm_tt.h> 40 41 #include <linux/dma-buf.h> 41 42 #include <linux/dma-fence-array.h> 42 43 #include <linux/pci-p2pdma.h>
-1
drivers/gpu/drm/amd/amdgpu/amdgpu_fdinfo.h
··· 30 30 #include <linux/rbtree.h> 31 31 #include <drm/gpu_scheduler.h> 32 32 #include <drm/drm_file.h> 33 - #include <drm/ttm/ttm_bo_driver.h> 34 33 #include <linux/sched/mm.h> 35 34 36 35 #include "amdgpu_sync.h"
+1
drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c
··· 34 34 #include <drm/amdgpu_drm.h> 35 35 #include <drm/drm_drv.h> 36 36 #include <drm/drm_gem_ttm_helper.h> 37 + #include <drm/ttm/ttm_tt.h> 37 38 38 39 #include "amdgpu.h" 39 40 #include "amdgpu_display.h"
+1
drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c
··· 35 35 #include "amdgpu_xgmi.h" 36 36 37 37 #include <drm/drm_drv.h> 38 + #include <drm/ttm/ttm_tt.h> 38 39 39 40 /** 40 41 * amdgpu_gmc_pdb0_alloc - allocate vram for pdb0
+2 -2
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
··· 44 44 #include <linux/module.h> 45 45 46 46 #include <drm/drm_drv.h> 47 - #include <drm/ttm/ttm_bo_api.h> 48 - #include <drm/ttm/ttm_bo_driver.h> 47 + #include <drm/ttm/ttm_bo.h> 49 48 #include <drm/ttm/ttm_placement.h> 50 49 #include <drm/ttm/ttm_range_manager.h> 50 + #include <drm/ttm/ttm_tt.h> 51 51 52 52 #include <drm/amdgpu_drm.h> 53 53 #include <drm/drm_drv.h>
+1
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
··· 33 33 34 34 #include <drm/amdgpu_drm.h> 35 35 #include <drm/drm_drv.h> 36 + #include <drm/ttm/ttm_tt.h> 36 37 #include "amdgpu.h" 37 38 #include "amdgpu_trace.h" 38 39 #include "amdgpu_amdkfd.h"
+1 -1
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h
··· 29 29 #include <linux/rbtree.h> 30 30 #include <drm/gpu_scheduler.h> 31 31 #include <drm/drm_file.h> 32 - #include <drm/ttm/ttm_bo_driver.h> 32 + #include <drm/ttm/ttm_bo.h> 33 33 #include <linux/sched/mm.h> 34 34 35 35 #include "amdgpu_sync.h"
+1
drivers/gpu/drm/amd/amdkfd/kfd_svm.c
··· 23 23 24 24 #include <linux/types.h> 25 25 #include <linux/sched/task.h> 26 + #include <drm/ttm/ttm_tt.h> 26 27 #include "amdgpu_sync.h" 27 28 #include "amdgpu_object.h" 28 29 #include "amdgpu_vm.h"
+2
drivers/gpu/drm/drm_gem_ttm_helper.c
··· 3 3 #include <linux/module.h> 4 4 5 5 #include <drm/drm_gem_ttm_helper.h> 6 + #include <drm/ttm/ttm_placement.h> 7 + #include <drm/ttm/ttm_tt.h> 6 8 7 9 /** 8 10 * DOC: overview
+1
drivers/gpu/drm/drm_gem_vram_helper.c
··· 19 19 #include <drm/drm_simple_kms_helper.h> 20 20 21 21 #include <drm/ttm/ttm_range_manager.h> 22 + #include <drm/ttm/ttm_tt.h> 22 23 23 24 static const struct drm_gem_object_funcs drm_gem_vram_object_funcs; 24 25
+1 -1
drivers/gpu/drm/i915/gem/i915_gem_object_types.h
··· 10 10 #include <linux/mmu_notifier.h> 11 11 12 12 #include <drm/drm_gem.h> 13 - #include <drm/ttm/ttm_bo_api.h> 13 + #include <drm/ttm/ttm_bo.h> 14 14 #include <uapi/drm/i915_drm.h> 15 15 16 16 #include "i915_active.h"
+1 -1
drivers/gpu/drm/i915/gem/i915_gem_ttm.c
··· 5 5 6 6 #include <linux/shmem_fs.h> 7 7 8 - #include <drm/ttm/ttm_bo_driver.h> 9 8 #include <drm/ttm/ttm_placement.h> 9 + #include <drm/ttm/ttm_tt.h> 10 10 #include <drm/drm_buddy.h> 11 11 12 12 #include "i915_drv.h"
+1 -1
drivers/gpu/drm/i915/gem/i915_gem_ttm_move.c
··· 3 3 * Copyright © 2021 Intel Corporation 4 4 */ 5 5 6 - #include <drm/ttm/ttm_bo_driver.h> 6 + #include <drm/ttm/ttm_tt.h> 7 7 8 8 #include "i915_deps.h" 9 9 #include "i915_drv.h"
+1 -1
drivers/gpu/drm/i915/i915_deps.c
··· 6 6 #include <linux/dma-fence.h> 7 7 #include <linux/slab.h> 8 8 9 - #include <drm/ttm/ttm_bo_api.h> 9 + #include <drm/ttm/ttm_bo.h> 10 10 11 11 #include "i915_deps.h" 12 12
+1 -1
drivers/gpu/drm/i915/i915_ttm_buddy_manager.c
··· 5 5 6 6 #include <linux/slab.h> 7 7 8 - #include <drm/ttm/ttm_bo_driver.h> 9 8 #include <drm/ttm/ttm_placement.h> 9 + #include <drm/ttm/ttm_bo.h> 10 10 11 11 #include <drm/drm_buddy.h> 12 12
-1
drivers/gpu/drm/i915/intel_region_ttm.c
··· 2 2 /* 3 3 * Copyright © 2021 Intel Corporation 4 4 */ 5 - #include <drm/ttm/ttm_bo_driver.h> 6 5 #include <drm/ttm/ttm_device.h> 7 6 #include <drm/ttm/ttm_range_manager.h> 8 7
+1
drivers/gpu/drm/nouveau/nouveau_bo.c
··· 28 28 */ 29 29 30 30 #include <linux/dma-mapping.h> 31 + #include <drm/ttm/ttm_tt.h> 31 32 32 33 #include "nouveau_drv.h" 33 34 #include "nouveau_chan.h"
+2 -1
drivers/gpu/drm/nouveau/nouveau_bo.h
··· 1 1 /* SPDX-License-Identifier: MIT */ 2 2 #ifndef __NOUVEAU_BO_H__ 3 3 #define __NOUVEAU_BO_H__ 4 - #include <drm/ttm/ttm_bo_driver.h> 5 4 #include <drm/drm_gem.h> 5 + #include <drm/ttm/ttm_bo.h> 6 + #include <drm/ttm/ttm_placement.h> 6 7 7 8 struct nouveau_channel; 8 9 struct nouveau_cli;
+1 -2
drivers/gpu/drm/nouveau/nouveau_drv.h
··· 51 51 #include <drm/drm_drv.h> 52 52 #include <drm/drm_file.h> 53 53 54 - #include <drm/ttm/ttm_bo_api.h> 55 - #include <drm/ttm/ttm_bo_driver.h> 54 + #include <drm/ttm/ttm_bo.h> 56 55 #include <drm/ttm/ttm_placement.h> 57 56 58 57 #include <drm/drm_audio_component.h>
+2 -1
drivers/gpu/drm/nouveau/nouveau_mem.c
··· 19 19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 20 20 * OTHER DEALINGS IN THE SOFTWARE. 21 21 */ 22 + #include <drm/ttm/ttm_tt.h> 23 + 22 24 #include "nouveau_mem.h" 23 25 #include "nouveau_drv.h" 24 26 #include "nouveau_bo.h" 25 27 26 - #include <drm/ttm/ttm_bo_driver.h> 27 28 28 29 #include <nvif/class.h> 29 30 #include <nvif/if000a.h>
+1 -1
drivers/gpu/drm/nouveau/nouveau_mem.h
··· 1 1 #ifndef __NOUVEAU_MEM_H__ 2 2 #define __NOUVEAU_MEM_H__ 3 - #include <drm/ttm/ttm_bo_api.h> 3 + #include <drm/ttm/ttm_bo.h> 4 4 struct ttm_tt; 5 5 6 6 #include <nvif/mem.h>
+1
drivers/gpu/drm/nouveau/nouveau_prime.c
··· 23 23 */ 24 24 25 25 #include <linux/dma-buf.h> 26 + #include <drm/ttm/ttm_tt.h> 26 27 27 28 #include "nouveau_drv.h" 28 29 #include "nouveau_gem.h"
+1
drivers/gpu/drm/nouveau/nouveau_sgdma.c
··· 1 1 // SPDX-License-Identifier: MIT 2 2 #include <linux/pagemap.h> 3 3 #include <linux/slab.h> 4 + #include <drm/ttm/ttm_tt.h> 4 5 5 6 #include "nouveau_drv.h" 6 7 #include "nouveau_mem.h"
+1 -2
drivers/gpu/drm/qxl/qxl_drv.h
··· 42 42 #include <drm/drm_ioctl.h> 43 43 #include <drm/drm_gem.h> 44 44 #include <drm/qxl_drm.h> 45 - #include <drm/ttm/ttm_bo_api.h> 46 - #include <drm/ttm/ttm_bo_driver.h> 45 + #include <drm/ttm/ttm_bo.h> 47 46 #include <drm/ttm/ttm_execbuf_util.h> 48 47 #include <drm/ttm/ttm_placement.h> 49 48
+2 -2
drivers/gpu/drm/qxl/qxl_ttm.c
··· 29 29 #include <drm/drm_file.h> 30 30 #include <drm/drm_debugfs.h> 31 31 #include <drm/qxl_drm.h> 32 - #include <drm/ttm/ttm_bo_api.h> 33 - #include <drm/ttm/ttm_bo_driver.h> 32 + #include <drm/ttm/ttm_bo.h> 34 33 #include <drm/ttm/ttm_placement.h> 35 34 #include <drm/ttm/ttm_range_manager.h> 35 + #include <drm/ttm/ttm_tt.h> 36 36 37 37 #include "qxl_drv.h" 38 38 #include "qxl_object.h"
+1 -2
drivers/gpu/drm/radeon/radeon.h
··· 73 73 #include <linux/mmu_notifier.h> 74 74 #endif 75 75 76 - #include <drm/ttm/ttm_bo_api.h> 77 - #include <drm/ttm/ttm_bo_driver.h> 76 + #include <drm/ttm/ttm_bo.h> 78 77 #include <drm/ttm/ttm_placement.h> 79 78 #include <drm/ttm/ttm_execbuf_util.h> 80 79
+2
drivers/gpu/drm/radeon/radeon_prime.c
··· 29 29 #include <drm/drm_prime.h> 30 30 #include <drm/radeon_drm.h> 31 31 32 + #include <drm/ttm/ttm_tt.h> 33 + 32 34 #include "radeon.h" 33 35 #include "radeon_prime.h" 34 36
+2 -2
drivers/gpu/drm/radeon/radeon_ttm.c
··· 42 42 #include <drm/drm_file.h> 43 43 #include <drm/drm_prime.h> 44 44 #include <drm/radeon_drm.h> 45 - #include <drm/ttm/ttm_bo_api.h> 46 - #include <drm/ttm/ttm_bo_driver.h> 45 + #include <drm/ttm/ttm_bo.h> 47 46 #include <drm/ttm/ttm_placement.h> 48 47 #include <drm/ttm/ttm_range_manager.h> 48 + #include <drm/ttm/ttm_tt.h> 49 49 50 50 #include "radeon_reg.h" 51 51 #include "radeon.h"
+74 -7
drivers/gpu/drm/ttm/ttm_bo.c
··· 31 31 32 32 #define pr_fmt(fmt) "[TTM] " fmt 33 33 34 - #include <drm/ttm/ttm_bo_driver.h> 34 + #include <drm/ttm/ttm_bo.h> 35 35 #include <drm/ttm/ttm_placement.h> 36 + #include <drm/ttm/ttm_tt.h> 37 + 36 38 #include <linux/jiffies.h> 37 39 #include <linux/slab.h> 38 40 #include <linux/sched.h> ··· 383 381 bo->destroy(bo); 384 382 } 385 383 384 + /** 385 + * ttm_bo_put 386 + * 387 + * @bo: The buffer object. 388 + * 389 + * Unreference a buffer object. 390 + */ 386 391 void ttm_bo_put(struct ttm_buffer_object *bo) 387 392 { 388 393 kref_put(&bo->kref, ttm_bo_release); ··· 476 467 return ret; 477 468 } 478 469 470 + /** 471 + * ttm_bo_eviction_valuable 472 + * 473 + * @bo: The buffer object to evict 474 + * @place: the placement we need to make room for 475 + * 476 + * Check if it is valuable to evict the BO to make room for the given placement. 477 + */ 479 478 bool ttm_bo_eviction_valuable(struct ttm_buffer_object *bo, 480 479 const struct ttm_place *place) 481 480 { ··· 743 726 return ttm_bo_add_move_fence(bo, man, *mem, ctx->no_wait_gpu); 744 727 } 745 728 746 - /* 747 - * Creates space for memory region @mem according to its type. 729 + /** 730 + * ttm_bo_mem_space 748 731 * 749 - * This function first searches for free space in compatible memory types in 750 - * the priority order defined by the driver. If free space isn't found, then 751 - * ttm_bo_mem_force_space is attempted in priority order to evict and find 752 - * space. 732 + * @bo: Pointer to a struct ttm_buffer_object. the data of which 733 + * we want to allocate space for. 734 + * @proposed_placement: Proposed new placement for the buffer object. 735 + * @mem: A struct ttm_resource. 736 + * @ctx: if and how to sleep, lock buffers and alloc memory 737 + * 738 + * Allocate memory space for the buffer object pointed to by @bo, using 739 + * the placement flags in @placement, potentially evicting other idle buffer objects. 740 + * This function may sleep while waiting for space to become available. 741 + * Returns: 742 + * -EBUSY: No space available (only if no_wait == 1). 743 + * -ENOMEM: Could not allocate memory for the buffer object, either due to 744 + * fragmentation or concurrent allocators. 745 + * -ERESTARTSYS: An interruptible sleep was interrupted by a signal. 753 746 */ 754 747 int ttm_bo_mem_space(struct ttm_buffer_object *bo, 755 748 struct ttm_placement *placement, ··· 865 838 return ret; 866 839 } 867 840 841 + /** 842 + * ttm_bo_validate 843 + * 844 + * @bo: The buffer object. 845 + * @placement: Proposed placement for the buffer object. 846 + * @ctx: validation parameters. 847 + * 848 + * Changes placement and caching policy of the buffer object 849 + * according proposed placement. 850 + * Returns 851 + * -EINVAL on invalid proposed placement. 852 + * -ENOMEM on out-of-memory condition. 853 + * -EBUSY if no_wait is true and buffer busy. 854 + * -ERESTARTSYS if interrupted by a signal. 855 + */ 868 856 int ttm_bo_validate(struct ttm_buffer_object *bo, 869 857 struct ttm_placement *placement, 870 858 struct ttm_operation_ctx *ctx) ··· 1072 1030 * buffer object vm functions. 1073 1031 */ 1074 1032 1033 + /** 1034 + * ttm_bo_unmap_virtual 1035 + * 1036 + * @bo: tear down the virtual mappings for this BO 1037 + */ 1075 1038 void ttm_bo_unmap_virtual(struct ttm_buffer_object *bo) 1076 1039 { 1077 1040 struct ttm_device *bdev = bo->bdev; ··· 1086 1039 } 1087 1040 EXPORT_SYMBOL(ttm_bo_unmap_virtual); 1088 1041 1042 + /** 1043 + * ttm_bo_wait - wait for buffer idle. 1044 + * 1045 + * @bo: The buffer object. 1046 + * @interruptible: Use interruptible wait. 1047 + * @no_wait: Return immediately if buffer is busy. 1048 + * 1049 + * This function must be called with the bo::mutex held, and makes 1050 + * sure any previous rendering to the buffer is completed. 1051 + * Note: It might be necessary to block validations before the 1052 + * wait by reserving the buffer. 1053 + * Returns -EBUSY if no_wait is true and the buffer is busy. 1054 + * Returns -ERESTARTSYS if interrupted by a signal. 1055 + */ 1089 1056 int ttm_bo_wait(struct ttm_buffer_object *bo, 1090 1057 bool interruptible, bool no_wait) 1091 1058 { ··· 1123 1062 return 0; 1124 1063 } 1125 1064 EXPORT_SYMBOL(ttm_bo_wait); 1065 + 1066 + int ttm_bo_wait_ctx(struct ttm_buffer_object *bo, struct ttm_operation_ctx *ctx) 1067 + { 1068 + return ttm_bo_wait(bo, ctx->interruptible, ctx->no_wait_gpu); 1069 + } 1070 + EXPORT_SYMBOL(ttm_bo_wait_ctx); 1126 1071 1127 1072 int ttm_bo_swapout(struct ttm_buffer_object *bo, struct ttm_operation_ctx *ctx, 1128 1073 gfp_t gfp_flags)
+100 -10
drivers/gpu/drm/ttm/ttm_bo_util.c
··· 29 29 * Authors: Thomas Hellstrom <thellstrom-at-vmware-dot-com> 30 30 */ 31 31 32 - #include <drm/ttm/ttm_bo_driver.h> 32 + #include <drm/ttm/ttm_bo.h> 33 33 #include <drm/ttm/ttm_placement.h> 34 + #include <drm/ttm/ttm_tt.h> 35 + 34 36 #include <drm/drm_cache.h> 35 - #include <drm/drm_vma_manager.h> 36 - #include <linux/iosys-map.h> 37 - #include <linux/io.h> 38 - #include <linux/highmem.h> 39 - #include <linux/wait.h> 40 - #include <linux/slab.h> 41 - #include <linux/vmalloc.h> 42 - #include <linux/module.h> 43 - #include <linux/dma-resv.h> 44 37 45 38 struct ttm_transfer_obj { 46 39 struct ttm_buffer_object base; ··· 121 128 } 122 129 EXPORT_SYMBOL(ttm_move_memcpy); 123 130 131 + /** 132 + * ttm_bo_move_memcpy 133 + * 134 + * @bo: A pointer to a struct ttm_buffer_object. 135 + * @interruptible: Sleep interruptible if waiting. 136 + * @no_wait_gpu: Return immediately if the GPU is busy. 137 + * @new_mem: struct ttm_resource indicating where to move. 138 + * 139 + * Fallback move function for a mappable buffer object in mappable memory. 140 + * The function will, if successful, 141 + * free any old aperture space, and set (@new_mem)->mm_node to NULL, 142 + * and update the (@bo)->mem placement flags. If unsuccessful, the old 143 + * data remains untouched, and it's up to the caller to free the 144 + * memory space indicated by @new_mem. 145 + * Returns: 146 + * !0: Failure. 147 + */ 124 148 int ttm_bo_move_memcpy(struct ttm_buffer_object *bo, 125 149 struct ttm_operation_ctx *ctx, 126 150 struct ttm_resource *dst_mem) ··· 276 266 return 0; 277 267 } 278 268 269 + /** 270 + * ttm_io_prot 271 + * 272 + * bo: ttm buffer object 273 + * res: ttm resource object 274 + * @tmp: Page protection flag for a normal, cached mapping. 275 + * 276 + * Utility function that returns the pgprot_t that should be used for 277 + * setting up a PTE with the caching model indicated by @c_state. 278 + */ 279 279 pgprot_t ttm_io_prot(struct ttm_buffer_object *bo, struct ttm_resource *res, 280 280 pgprot_t tmp) 281 281 { ··· 367 347 return (!map->virtual) ? -ENOMEM : 0; 368 348 } 369 349 350 + /** 351 + * ttm_bo_kmap 352 + * 353 + * @bo: The buffer object. 354 + * @start_page: The first page to map. 355 + * @num_pages: Number of pages to map. 356 + * @map: pointer to a struct ttm_bo_kmap_obj representing the map. 357 + * 358 + * Sets up a kernel virtual mapping, using ioremap, vmap or kmap to the 359 + * data in the buffer object. The ttm_kmap_obj_virtual function can then be 360 + * used to obtain a virtual address to the data. 361 + * 362 + * Returns 363 + * -ENOMEM: Out of memory. 364 + * -EINVAL: Invalid range. 365 + */ 370 366 int ttm_bo_kmap(struct ttm_buffer_object *bo, 371 367 unsigned long start_page, unsigned long num_pages, 372 368 struct ttm_bo_kmap_obj *map) ··· 410 374 } 411 375 EXPORT_SYMBOL(ttm_bo_kmap); 412 376 377 + /** 378 + * ttm_bo_kunmap 379 + * 380 + * @map: Object describing the map to unmap. 381 + * 382 + * Unmaps a kernel map set up by ttm_bo_kmap. 383 + */ 413 384 void ttm_bo_kunmap(struct ttm_bo_kmap_obj *map) 414 385 { 415 386 if (!map->virtual) ··· 442 399 } 443 400 EXPORT_SYMBOL(ttm_bo_kunmap); 444 401 402 + /** 403 + * ttm_bo_vmap 404 + * 405 + * @bo: The buffer object. 406 + * @map: pointer to a struct iosys_map representing the map. 407 + * 408 + * Sets up a kernel virtual mapping, using ioremap or vmap to the 409 + * data in the buffer object. The parameter @map returns the virtual 410 + * address as struct iosys_map. Unmap the buffer with ttm_bo_vunmap(). 411 + * 412 + * Returns 413 + * -ENOMEM: Out of memory. 414 + * -EINVAL: Invalid range. 415 + */ 445 416 int ttm_bo_vmap(struct ttm_buffer_object *bo, struct iosys_map *map) 446 417 { 447 418 struct ttm_resource *mem = bo->resource; ··· 517 460 } 518 461 EXPORT_SYMBOL(ttm_bo_vmap); 519 462 463 + /** 464 + * ttm_bo_vunmap 465 + * 466 + * @bo: The buffer object. 467 + * @map: Object describing the map to unmap. 468 + * 469 + * Unmaps a kernel map set up by ttm_bo_vmap(). 470 + */ 520 471 void ttm_bo_vunmap(struct ttm_buffer_object *bo, struct iosys_map *map) 521 472 { 522 473 struct ttm_resource *mem = bo->resource; ··· 618 553 ttm_resource_free(bo, &bo->resource); 619 554 } 620 555 556 + /** 557 + * ttm_bo_move_accel_cleanup. 558 + * 559 + * @bo: A pointer to a struct ttm_buffer_object. 560 + * @fence: A fence object that signals when moving is complete. 561 + * @evict: This is an evict move. Don't return until the buffer is idle. 562 + * @pipeline: evictions are to be pipelined. 563 + * @new_mem: struct ttm_resource indicating where to move. 564 + * 565 + * Accelerated move function to be called when an accelerated move 566 + * has been scheduled. The function will create a new temporary buffer object 567 + * representing the old placement, and put the sync object on both buffer 568 + * objects. After that the newly created buffer object is unref'd to be 569 + * destroyed when the move is complete. This will help pipeline 570 + * buffer moves. 571 + */ 621 572 int ttm_bo_move_accel_cleanup(struct ttm_buffer_object *bo, 622 573 struct dma_fence *fence, 623 574 bool evict, ··· 662 581 } 663 582 EXPORT_SYMBOL(ttm_bo_move_accel_cleanup); 664 583 584 + /** 585 + * ttm_bo_move_sync_cleanup. 586 + * 587 + * @bo: A pointer to a struct ttm_buffer_object. 588 + * @new_mem: struct ttm_resource indicating where to move. 589 + * 590 + * Special case of ttm_bo_move_accel_cleanup where the bo is guaranteed 591 + * by the caller to be idle. Typically used after memcpy buffer moves. 592 + */ 665 593 void ttm_bo_move_sync_cleanup(struct ttm_buffer_object *bo, 666 594 struct ttm_resource *new_mem) 667 595 {
+11 -8
drivers/gpu/drm/ttm/ttm_bo_vm.c
··· 31 31 32 32 #define pr_fmt(fmt) "[TTM] " fmt 33 33 34 - #include <drm/ttm/ttm_bo_driver.h> 34 + #include <drm/ttm/ttm_bo.h> 35 35 #include <drm/ttm/ttm_placement.h> 36 - #include <drm/drm_vma_manager.h> 36 + #include <drm/ttm/ttm_tt.h> 37 + 37 38 #include <drm/drm_drv.h> 38 39 #include <drm/drm_managed.h> 39 - #include <linux/mm.h> 40 - #include <linux/pfn_t.h> 41 - #include <linux/rbtree.h> 42 - #include <linux/module.h> 43 - #include <linux/uaccess.h> 44 - #include <linux/mem_encrypt.h> 45 40 46 41 static vm_fault_t ttm_bo_vm_fault_idle(struct ttm_buffer_object *bo, 47 42 struct vm_fault *vmf) ··· 441 446 .access = ttm_bo_vm_access, 442 447 }; 443 448 449 + /** 450 + * ttm_bo_mmap_obj - mmap memory backed by a ttm buffer object. 451 + * 452 + * @vma: vma as input from the fbdev mmap method. 453 + * @bo: The bo backing the address space. 454 + * 455 + * Maps a buffer object. 456 + */ 444 457 int ttm_bo_mmap_obj(struct vm_area_struct *vma, struct ttm_buffer_object *bo) 445 458 { 446 459 /* Enforce no COW since would have really strange behavior with it. */
+1 -1
drivers/gpu/drm/ttm/ttm_device.c
··· 29 29 30 30 #include <linux/mm.h> 31 31 32 + #include <drm/ttm/ttm_bo.h> 32 33 #include <drm/ttm/ttm_device.h> 33 34 #include <drm/ttm/ttm_tt.h> 34 35 #include <drm/ttm/ttm_placement.h> 35 - #include <drm/ttm/ttm_bo_api.h> 36 36 37 37 #include "ttm_module.h" 38 38
+1 -5
drivers/gpu/drm/ttm/ttm_execbuf_util.c
··· 27 27 **************************************************************************/ 28 28 29 29 #include <drm/ttm/ttm_execbuf_util.h> 30 - #include <drm/ttm/ttm_bo_driver.h> 31 - #include <drm/ttm/ttm_placement.h> 32 - #include <linux/wait.h> 33 - #include <linux/sched.h> 34 - #include <linux/module.h> 30 + #include <drm/ttm/ttm_bo.h> 35 31 36 32 static void ttm_eu_backoff_reservation_reverse(struct list_head *list, 37 33 struct ttm_validate_buffer *entry)
+2 -1
drivers/gpu/drm/ttm/ttm_pool.c
··· 33 33 34 34 #include <linux/module.h> 35 35 #include <linux/dma-mapping.h> 36 + #include <linux/debugfs.h> 36 37 #include <linux/highmem.h> 37 38 #include <linux/sched/mm.h> 38 39 ··· 42 41 #endif 43 42 44 43 #include <drm/ttm/ttm_pool.h> 45 - #include <drm/ttm/ttm_bo_driver.h> 46 44 #include <drm/ttm/ttm_tt.h> 45 + #include <drm/ttm/ttm_bo.h> 47 46 48 47 #include "ttm_module.h" 49 48
+1 -1
drivers/gpu/drm/ttm/ttm_range_manager.c
··· 32 32 #include <drm/ttm/ttm_device.h> 33 33 #include <drm/ttm/ttm_placement.h> 34 34 #include <drm/ttm/ttm_range_manager.h> 35 - #include <drm/ttm/ttm_bo_api.h> 35 + #include <drm/ttm/ttm_bo.h> 36 36 #include <drm/drm_mm.h> 37 37 #include <linux/slab.h> 38 38 #include <linux/spinlock.h>
+2 -1
drivers/gpu/drm/ttm/ttm_resource.c
··· 26 26 #include <linux/io-mapping.h> 27 27 #include <linux/scatterlist.h> 28 28 29 + #include <drm/ttm/ttm_bo.h> 30 + #include <drm/ttm/ttm_placement.h> 29 31 #include <drm/ttm/ttm_resource.h> 30 - #include <drm/ttm/ttm_bo_driver.h> 31 32 32 33 /** 33 34 * ttm_lru_bulk_move_init - initialize a bulk move structure
+2 -1
drivers/gpu/drm/ttm/ttm_tt.c
··· 36 36 #include <linux/file.h> 37 37 #include <linux/module.h> 38 38 #include <drm/drm_cache.h> 39 - #include <drm/ttm/ttm_bo_driver.h> 39 + #include <drm/ttm/ttm_bo.h> 40 + #include <drm/ttm/ttm_tt.h> 40 41 41 42 #include "ttm_module.h" 42 43
+1 -1
drivers/gpu/drm/vmwgfx/vmwgfx_cmdbuf.c
··· 28 28 #include <linux/dmapool.h> 29 29 #include <linux/pci.h> 30 30 31 - #include <drm/ttm/ttm_bo_api.h> 31 + #include <drm/ttm/ttm_bo.h> 32 32 33 33 #include "vmwgfx_drv.h" 34 34
-1
drivers/gpu/drm/vmwgfx/vmwgfx_drv.c
··· 40 40 #include <drm/drm_ioctl.h> 41 41 #include <drm/drm_module.h> 42 42 #include <drm/drm_sysfs.h> 43 - #include <drm/ttm/ttm_bo_driver.h> 44 43 #include <drm/ttm/ttm_range_manager.h> 45 44 #include <drm/ttm/ttm_placement.h> 46 45 #include <generated/utsrelease.h>
+3 -1
drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
··· 37 37 #include <drm/drm_file.h> 38 38 #include <drm/drm_rect.h> 39 39 40 - #include <drm/ttm/ttm_bo_driver.h> 41 40 #include <drm/ttm/ttm_execbuf_util.h> 41 + #include <drm/ttm/ttm_tt.h> 42 + #include <drm/ttm/ttm_placement.h> 43 + #include <drm/ttm/ttm_bo.h> 42 44 43 45 #include "ttm_object.h" 44 46
+1 -1
drivers/gpu/drm/vmwgfx/vmwgfx_execbuf.c
··· 29 29 30 30 #include "vmwgfx_drv.h" 31 31 #include "vmwgfx_reg.h" 32 - #include <drm/ttm/ttm_bo_api.h> 32 + #include <drm/ttm/ttm_bo.h> 33 33 #include <drm/ttm/ttm_placement.h> 34 34 #include "vmwgfx_so.h" 35 35 #include "vmwgfx_binding.h"
-1
drivers/gpu/drm/vmwgfx/vmwgfx_gmr.c
··· 25 25 * 26 26 **************************************************************************/ 27 27 28 - #include <drm/ttm/ttm_bo_driver.h> 29 28 30 29 #include "vmwgfx_drv.h" 31 30
-1
drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c
··· 29 29 */ 30 30 31 31 #include "vmwgfx_drv.h" 32 - #include <drm/ttm/ttm_bo_driver.h> 33 32 #include <drm/ttm/ttm_placement.h> 34 33 #include <linux/idr.h> 35 34 #include <linux/spinlock.h>
-1
drivers/gpu/drm/vmwgfx/vmwgfx_system_manager.c
··· 26 26 27 27 #include "vmwgfx_drv.h" 28 28 29 - #include <drm/ttm/ttm_bo_driver.h> 30 29 #include <drm/ttm/ttm_device.h> 31 30 #include <drm/ttm/ttm_placement.h> 32 31 #include <drm/ttm/ttm_resource.h>
-1
drivers/gpu/drm/vmwgfx/vmwgfx_ttm_buffer.c
··· 26 26 **************************************************************************/ 27 27 28 28 #include "vmwgfx_drv.h" 29 - #include <drm/ttm/ttm_bo_driver.h> 30 29 #include <drm/ttm/ttm_placement.h> 31 30 32 31 static const struct ttm_place vram_placement_flags = {
+1 -2
include/drm/drm_gem_ttm_helper.h
··· 7 7 8 8 #include <drm/drm_device.h> 9 9 #include <drm/drm_gem.h> 10 - #include <drm/ttm/ttm_bo_api.h> 11 - #include <drm/ttm/ttm_bo_driver.h> 10 + #include <drm/ttm/ttm_bo.h> 12 11 13 12 struct iosys_map; 14 13
+2 -2
include/drm/drm_gem_vram_helper.h
··· 8 8 #include <drm/drm_gem_ttm_helper.h> 9 9 #include <drm/drm_ioctl.h> 10 10 #include <drm/drm_modes.h> 11 - #include <drm/ttm/ttm_bo_api.h> 12 - #include <drm/ttm/ttm_bo_driver.h> 11 + #include <drm/ttm/ttm_bo.h> 12 + #include <drm/ttm/ttm_placement.h> 13 13 14 14 #include <linux/container_of.h> 15 15 #include <linux/iosys-map.h>
+164 -181
include/drm/ttm/ttm_bo_api.h include/drm/ttm/ttm_bo.h
··· 32 32 #define _TTM_BO_API_H_ 33 33 34 34 #include <drm/drm_gem.h> 35 - #include <drm/drm_vma_manager.h> 35 + 36 36 #include <linux/kref.h> 37 37 #include <linux/list.h> 38 - #include <linux/wait.h> 39 - #include <linux/mutex.h> 40 - #include <linux/mm.h> 41 - #include <linux/bitmap.h> 42 - #include <linux/dma-resv.h> 43 38 44 - #include "ttm_resource.h" 39 + #include "ttm_device.h" 45 40 46 - struct ttm_global; 47 - 48 - struct ttm_device; 41 + /* Default number of pre-faulted pages in the TTM fault handler */ 42 + #define TTM_BO_VM_NUM_PREFAULT 16 49 43 50 44 struct iosys_map; 51 45 52 - struct drm_mm_node; 53 - 46 + struct ttm_global; 47 + struct ttm_device; 54 48 struct ttm_placement; 55 - 56 49 struct ttm_place; 50 + struct ttm_resource; 51 + struct ttm_resource_manager; 52 + struct ttm_tt; 57 53 58 54 /** 59 55 * enum ttm_bo_type ··· 64 68 * @ttm_bo_type_sg: Buffer made from dmabuf sg table shared with another 65 69 * driver. 66 70 */ 67 - 68 71 enum ttm_bo_type { 69 72 ttm_bo_type_device, 70 73 ttm_bo_type_kernel, 71 74 ttm_bo_type_sg 72 75 }; 73 - 74 - struct ttm_tt; 75 76 76 77 /** 77 78 * struct ttm_buffer_object ··· 78 85 * @type: The bo type. 79 86 * @page_alignment: Page alignment. 80 87 * @destroy: Destruction function. If NULL, kfree is used. 81 - * @num_pages: Actual number of pages. 82 88 * @kref: Reference count of this buffer object. When this refcount reaches 83 89 * zero, the object is destroyed or put on the delayed delete list. 84 - * @mem: structure describing current placement. 90 + * @resource: structure describing current placement. 85 91 * @ttm: TTM structure holding system pages. 86 - * @evicted: Whether the object was evicted without user-space knowing. 87 92 * @deleted: True if the object is only a zombie and already deleted. 88 - * @swap: List head for swap LRU list. 89 - * @offset: The current GPU offset, which can have different meanings 90 - * depending on the memory type. For SYSTEM type memory, it should be 0. 91 - * @cur_placement: Hint of current placement. 92 93 * 93 94 * Base class for TTM buffer object, that deals with data placement and CPU 94 95 * mappings. GPU mappings are really up to the driver, but for simpler GPUs ··· 95 108 * The destroy member, the API visibility of this object makes it possible 96 109 * to derive driver specific types. 97 110 */ 98 - 99 111 struct ttm_buffer_object { 100 112 struct drm_gem_object base; 101 113 102 - /** 114 + /* 103 115 * Members constant at init. 104 116 */ 105 - 106 117 struct ttm_device *bdev; 107 118 enum ttm_bo_type type; 108 119 uint32_t page_alignment; 109 120 void (*destroy) (struct ttm_buffer_object *); 110 121 111 - /** 122 + /* 112 123 * Members not needing protection. 113 124 */ 114 125 struct kref kref; 115 126 116 - /** 127 + /* 117 128 * Members protected by the bo::resv::reserved lock. 118 129 */ 119 - 120 130 struct ttm_resource *resource; 121 131 struct ttm_tt *ttm; 122 132 bool deleted; ··· 132 148 * and the bo::lock when written to. Can be read with 133 149 * either of these locks held. 134 150 */ 135 - 136 151 struct sg_table *sg; 137 152 }; 138 153 ··· 147 164 * mapping can either be an ioremap, a vmap, a kmap or part of a 148 165 * premapped region. 149 166 */ 150 - 151 167 #define TTM_BO_MAP_IOMEM_MASK 0x80 152 168 struct ttm_bo_kmap_obj { 153 169 void *virtual; ··· 214 232 } 215 233 216 234 /** 217 - * ttm_bo_wait - wait for buffer idle. 235 + * ttm_bo_reserve: 218 236 * 219 - * @bo: The buffer object. 220 - * @interruptible: Use interruptible wait. 221 - * @no_wait: Return immediately if buffer is busy. 237 + * @bo: A pointer to a struct ttm_buffer_object. 238 + * @interruptible: Sleep interruptible if waiting. 239 + * @no_wait: Don't sleep while trying to reserve, rather return -EBUSY. 240 + * @ticket: ticket used to acquire the ww_mutex. 222 241 * 223 - * This function must be called with the bo::mutex held, and makes 224 - * sure any previous rendering to the buffer is completed. 225 - * Note: It might be necessary to block validations before the 226 - * wait by reserving the buffer. 227 - * Returns -EBUSY if no_wait is true and the buffer is busy. 228 - * Returns -ERESTARTSYS if interrupted by a signal. 242 + * Locks a buffer object for validation. (Or prevents other processes from 243 + * locking it for validation), while taking a number of measures to prevent 244 + * deadlocks. 245 + * 246 + * Returns: 247 + * -EDEADLK: The reservation may cause a deadlock. 248 + * Release all buffer reservations, wait for @bo to become unreserved and 249 + * try again. 250 + * -ERESTARTSYS: A wait for the buffer to become unreserved was interrupted by 251 + * a signal. Release all buffer reservations and return to user-space. 252 + * -EBUSY: The function needed to sleep, but @no_wait was true 253 + * -EALREADY: Bo already reserved using @ticket. This error code will only 254 + * be returned if @use_ticket is set to true. 229 255 */ 230 - int ttm_bo_wait(struct ttm_buffer_object *bo, bool interruptible, bool no_wait); 231 - 232 - static inline int ttm_bo_wait_ctx(struct ttm_buffer_object *bo, struct ttm_operation_ctx *ctx) 256 + static inline int ttm_bo_reserve(struct ttm_buffer_object *bo, 257 + bool interruptible, bool no_wait, 258 + struct ww_acquire_ctx *ticket) 233 259 { 234 - return ttm_bo_wait(bo, ctx->interruptible, ctx->no_wait_gpu); 260 + int ret = 0; 261 + 262 + if (no_wait) { 263 + bool success; 264 + 265 + if (WARN_ON(ticket)) 266 + return -EBUSY; 267 + 268 + success = dma_resv_trylock(bo->base.resv); 269 + return success ? 0 : -EBUSY; 270 + } 271 + 272 + if (interruptible) 273 + ret = dma_resv_lock_interruptible(bo->base.resv, ticket); 274 + else 275 + ret = dma_resv_lock(bo->base.resv, ticket); 276 + if (ret == -EINTR) 277 + return -ERESTARTSYS; 278 + return ret; 235 279 } 236 280 237 281 /** 238 - * ttm_bo_validate 282 + * ttm_bo_reserve_slowpath: 283 + * @bo: A pointer to a struct ttm_buffer_object. 284 + * @interruptible: Sleep interruptible if waiting. 285 + * @sequence: Set (@bo)->sequence to this value after lock 239 286 * 240 - * @bo: The buffer object. 241 - * @placement: Proposed placement for the buffer object. 242 - * @ctx: validation parameters. 243 - * 244 - * Changes placement and caching policy of the buffer object 245 - * according proposed placement. 246 - * Returns 247 - * -EINVAL on invalid proposed placement. 248 - * -ENOMEM on out-of-memory condition. 249 - * -EBUSY if no_wait is true and buffer busy. 250 - * -ERESTARTSYS if interrupted by a signal. 287 + * This is called after ttm_bo_reserve returns -EAGAIN and we backed off 288 + * from all our other reservations. Because there are no other reservations 289 + * held by us, this function cannot deadlock any more. 251 290 */ 252 - int ttm_bo_validate(struct ttm_buffer_object *bo, 253 - struct ttm_placement *placement, 254 - struct ttm_operation_ctx *ctx); 255 - 256 - /** 257 - * ttm_bo_put 258 - * 259 - * @bo: The buffer object. 260 - * 261 - * Unreference a buffer object. 262 - */ 263 - void ttm_bo_put(struct ttm_buffer_object *bo); 291 + static inline int ttm_bo_reserve_slowpath(struct ttm_buffer_object *bo, 292 + bool interruptible, 293 + struct ww_acquire_ctx *ticket) 294 + { 295 + if (interruptible) { 296 + int ret = dma_resv_lock_slow_interruptible(bo->base.resv, 297 + ticket); 298 + if (ret == -EINTR) 299 + ret = -ERESTARTSYS; 300 + return ret; 301 + } 302 + dma_resv_lock_slow(bo->base.resv, ticket); 303 + return 0; 304 + } 264 305 265 306 void ttm_bo_move_to_lru_tail(struct ttm_buffer_object *bo); 266 - void ttm_bo_set_bulk_move(struct ttm_buffer_object *bo, 267 - struct ttm_lru_bulk_move *bulk); 307 + 308 + static inline void 309 + ttm_bo_move_to_lru_tail_unlocked(struct ttm_buffer_object *bo) 310 + { 311 + spin_lock(&bo->bdev->lru_lock); 312 + ttm_bo_move_to_lru_tail(bo); 313 + spin_unlock(&bo->bdev->lru_lock); 314 + } 315 + 316 + static inline void ttm_bo_assign_mem(struct ttm_buffer_object *bo, 317 + struct ttm_resource *new_mem) 318 + { 319 + WARN_ON(bo->resource); 320 + bo->resource = new_mem; 321 + } 268 322 269 323 /** 270 - * ttm_bo_eviction_valuable 324 + * ttm_bo_move_null = assign memory for a buffer object. 325 + * @bo: The bo to assign the memory to 326 + * @new_mem: The memory to be assigned. 271 327 * 272 - * @bo: The buffer object to evict 273 - * @place: the placement we need to make room for 274 - * 275 - * Check if it is valuable to evict the BO to make room for the given placement. 328 + * Assign the memory from new_mem to the memory of the buffer object bo. 276 329 */ 277 - bool ttm_bo_eviction_valuable(struct ttm_buffer_object *bo, 278 - const struct ttm_place *place); 330 + static inline void ttm_bo_move_null(struct ttm_buffer_object *bo, 331 + struct ttm_resource *new_mem) 332 + { 333 + ttm_resource_free(bo, &bo->resource); 334 + ttm_bo_assign_mem(bo, new_mem); 335 + } 279 336 280 - int ttm_bo_init_reserved(struct ttm_device *bdev, struct ttm_buffer_object *bo, 281 - enum ttm_bo_type type, struct ttm_placement *placement, 282 - uint32_t alignment, struct ttm_operation_ctx *ctx, 283 - struct sg_table *sg, struct dma_resv *resv, 284 - void (*destroy) (struct ttm_buffer_object *)); 285 - int ttm_bo_init_validate(struct ttm_device *bdev, struct ttm_buffer_object *bo, 286 - enum ttm_bo_type type, struct ttm_placement *placement, 287 - uint32_t alignment, bool interruptible, 288 - struct sg_table *sg, struct dma_resv *resv, 289 - void (*destroy) (struct ttm_buffer_object *)); 337 + /** 338 + * ttm_bo_unreserve 339 + * 340 + * @bo: A pointer to a struct ttm_buffer_object. 341 + * 342 + * Unreserve a previous reservation of @bo. 343 + */ 344 + static inline void ttm_bo_unreserve(struct ttm_buffer_object *bo) 345 + { 346 + ttm_bo_move_to_lru_tail_unlocked(bo); 347 + dma_resv_unlock(bo->base.resv); 348 + } 290 349 291 350 /** 292 351 * ttm_kmap_obj_virtual ··· 347 324 return map->virtual; 348 325 } 349 326 350 - /** 351 - * ttm_bo_kmap 352 - * 353 - * @bo: The buffer object. 354 - * @start_page: The first page to map. 355 - * @num_pages: Number of pages to map. 356 - * @map: pointer to a struct ttm_bo_kmap_obj representing the map. 357 - * 358 - * Sets up a kernel virtual mapping, using ioremap, vmap or kmap to the 359 - * data in the buffer object. The ttm_kmap_obj_virtual function can then be 360 - * used to obtain a virtual address to the data. 361 - * 362 - * Returns 363 - * -ENOMEM: Out of memory. 364 - * -EINVAL: Invalid range. 365 - */ 327 + int ttm_bo_wait(struct ttm_buffer_object *bo, bool interruptible, bool no_wait); 328 + int ttm_bo_wait_ctx(struct ttm_buffer_object *bo, 329 + struct ttm_operation_ctx *ctx); 330 + int ttm_bo_validate(struct ttm_buffer_object *bo, 331 + struct ttm_placement *placement, 332 + struct ttm_operation_ctx *ctx); 333 + void ttm_bo_put(struct ttm_buffer_object *bo); 334 + void ttm_bo_set_bulk_move(struct ttm_buffer_object *bo, 335 + struct ttm_lru_bulk_move *bulk); 336 + int ttm_bo_lock_delayed_workqueue(struct ttm_device *bdev); 337 + void ttm_bo_unlock_delayed_workqueue(struct ttm_device *bdev, int resched); 338 + bool ttm_bo_eviction_valuable(struct ttm_buffer_object *bo, 339 + const struct ttm_place *place); 340 + int ttm_bo_init_reserved(struct ttm_device *bdev, struct ttm_buffer_object *bo, 341 + enum ttm_bo_type type, struct ttm_placement *placement, 342 + uint32_t alignment, struct ttm_operation_ctx *ctx, 343 + struct sg_table *sg, struct dma_resv *resv, 344 + void (*destroy)(struct ttm_buffer_object *)); 345 + int ttm_bo_init_validate(struct ttm_device *bdev, struct ttm_buffer_object *bo, 346 + enum ttm_bo_type type, struct ttm_placement *placement, 347 + uint32_t alignment, bool interruptible, 348 + struct sg_table *sg, struct dma_resv *resv, 349 + void (*destroy)(struct ttm_buffer_object *)); 366 350 int ttm_bo_kmap(struct ttm_buffer_object *bo, unsigned long start_page, 367 351 unsigned long num_pages, struct ttm_bo_kmap_obj *map); 368 - 369 - /** 370 - * ttm_bo_kunmap 371 - * 372 - * @map: Object describing the map to unmap. 373 - * 374 - * Unmaps a kernel map set up by ttm_bo_kmap. 375 - */ 376 352 void ttm_bo_kunmap(struct ttm_bo_kmap_obj *map); 377 - 378 - /** 379 - * ttm_bo_vmap 380 - * 381 - * @bo: The buffer object. 382 - * @map: pointer to a struct iosys_map representing the map. 383 - * 384 - * Sets up a kernel virtual mapping, using ioremap or vmap to the 385 - * data in the buffer object. The parameter @map returns the virtual 386 - * address as struct iosys_map. Unmap the buffer with ttm_bo_vunmap(). 387 - * 388 - * Returns 389 - * -ENOMEM: Out of memory. 390 - * -EINVAL: Invalid range. 391 - */ 392 353 int ttm_bo_vmap(struct ttm_buffer_object *bo, struct iosys_map *map); 393 - 394 - /** 395 - * ttm_bo_vunmap 396 - * 397 - * @bo: The buffer object. 398 - * @map: Object describing the map to unmap. 399 - * 400 - * Unmaps a kernel map set up by ttm_bo_vmap(). 401 - */ 402 354 void ttm_bo_vunmap(struct ttm_buffer_object *bo, struct iosys_map *map); 403 - 404 - /** 405 - * ttm_bo_mmap_obj - mmap memory backed by a ttm buffer object. 406 - * 407 - * @vma: vma as input from the fbdev mmap method. 408 - * @bo: The bo backing the address space. 409 - * 410 - * Maps a buffer object. 411 - */ 412 355 int ttm_bo_mmap_obj(struct vm_area_struct *vma, struct ttm_buffer_object *bo); 413 - 414 - /** 415 - * ttm_bo_io 416 - * 417 - * @bdev: Pointer to the struct ttm_device. 418 - * @filp: Pointer to the struct file attempting to read / write. 419 - * @wbuf: User-space pointer to address of buffer to write. NULL on read. 420 - * @rbuf: User-space pointer to address of buffer to read into. 421 - * Null on write. 422 - * @count: Number of bytes to read / write. 423 - * @f_pos: Pointer to current file position. 424 - * @write: 1 for read, 0 for write. 425 - * 426 - * This function implements read / write into ttm buffer objects, and is 427 - * intended to 428 - * be called from the fops::read and fops::write method. 429 - * Returns: 430 - * See man (2) write, man(2) read. In particular, 431 - * the function may return -ERESTARTSYS if 432 - * interrupted by a signal. 433 - */ 434 - ssize_t ttm_bo_io(struct ttm_device *bdev, struct file *filp, 435 - const char __user *wbuf, char __user *rbuf, 436 - size_t count, loff_t *f_pos, bool write); 437 - 438 356 int ttm_bo_swapout(struct ttm_buffer_object *bo, struct ttm_operation_ctx *ctx, 439 357 gfp_t gfp_flags); 440 - 441 358 void ttm_bo_pin(struct ttm_buffer_object *bo); 442 359 void ttm_bo_unpin(struct ttm_buffer_object *bo); 443 - 444 360 int ttm_mem_evict_first(struct ttm_device *bdev, 445 361 struct ttm_resource_manager *man, 446 362 const struct ttm_place *place, 447 363 struct ttm_operation_ctx *ctx, 448 364 struct ww_acquire_ctx *ticket); 449 - 450 - /* Default number of pre-faulted pages in the TTM fault handler */ 451 - #define TTM_BO_VM_NUM_PREFAULT 16 452 - 453 365 vm_fault_t ttm_bo_vm_reserve(struct ttm_buffer_object *bo, 454 366 struct vm_fault *vmf); 455 - 456 367 vm_fault_t ttm_bo_vm_fault_reserved(struct vm_fault *vmf, 457 368 pgprot_t prot, 458 369 pgoff_t num_prefault); 459 - 460 370 vm_fault_t ttm_bo_vm_fault(struct vm_fault *vmf); 461 - 462 371 void ttm_bo_vm_open(struct vm_area_struct *vma); 463 - 464 372 void ttm_bo_vm_close(struct vm_area_struct *vma); 465 - 466 373 int ttm_bo_vm_access(struct vm_area_struct *vma, unsigned long addr, 467 374 void *buf, int len, int write); 468 375 vm_fault_t ttm_bo_vm_dummy_page(struct vm_fault *vmf, pgprot_t prot); 376 + 377 + int ttm_bo_mem_space(struct ttm_buffer_object *bo, 378 + struct ttm_placement *placement, 379 + struct ttm_resource **mem, 380 + struct ttm_operation_ctx *ctx); 381 + 382 + void ttm_bo_unmap_virtual(struct ttm_buffer_object *bo); 383 + /* 384 + * ttm_bo_util.c 385 + */ 386 + int ttm_mem_io_reserve(struct ttm_device *bdev, 387 + struct ttm_resource *mem); 388 + void ttm_mem_io_free(struct ttm_device *bdev, 389 + struct ttm_resource *mem); 390 + void ttm_move_memcpy(bool clear, u32 num_pages, 391 + struct ttm_kmap_iter *dst_iter, 392 + struct ttm_kmap_iter *src_iter); 393 + int ttm_bo_move_memcpy(struct ttm_buffer_object *bo, 394 + struct ttm_operation_ctx *ctx, 395 + struct ttm_resource *new_mem); 396 + int ttm_bo_move_accel_cleanup(struct ttm_buffer_object *bo, 397 + struct dma_fence *fence, bool evict, 398 + bool pipeline, 399 + struct ttm_resource *new_mem); 400 + void ttm_bo_move_sync_cleanup(struct ttm_buffer_object *bo, 401 + struct ttm_resource *new_mem); 402 + int ttm_bo_pipeline_gutting(struct ttm_buffer_object *bo); 403 + pgprot_t ttm_io_prot(struct ttm_buffer_object *bo, struct ttm_resource *res, 404 + pgprot_t tmp); 405 + void ttm_bo_tt_destroy(struct ttm_buffer_object *bo); 469 406 470 407 #endif
-303
include/drm/ttm/ttm_bo_driver.h
··· 1 - /************************************************************************** 2 - * 3 - * Copyright (c) 2006-2009 Vmware, Inc., Palo Alto, CA., USA 4 - * All Rights Reserved. 5 - * 6 - * Permission is hereby granted, free of charge, to any person obtaining a 7 - * copy of this software and associated documentation files (the 8 - * "Software"), to deal in the Software without restriction, including 9 - * without limitation the rights to use, copy, modify, merge, publish, 10 - * distribute, sub license, and/or sell copies of the Software, and to 11 - * permit persons to whom the Software is furnished to do so, subject to 12 - * the following conditions: 13 - * 14 - * The above copyright notice and this permission notice (including the 15 - * next paragraph) shall be included in all copies or substantial portions 16 - * of the Software. 17 - * 18 - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 - * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL 21 - * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, 22 - * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 23 - * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE 24 - * USE OR OTHER DEALINGS IN THE SOFTWARE. 25 - * 26 - **************************************************************************/ 27 - /* 28 - * Authors: Thomas Hellstrom <thellstrom-at-vmware-dot-com> 29 - */ 30 - #ifndef _TTM_BO_DRIVER_H_ 31 - #define _TTM_BO_DRIVER_H_ 32 - 33 - #include <drm/drm_mm.h> 34 - #include <drm/drm_vma_manager.h> 35 - #include <linux/workqueue.h> 36 - #include <linux/fs.h> 37 - #include <linux/spinlock.h> 38 - #include <linux/dma-resv.h> 39 - 40 - #include <drm/ttm/ttm_device.h> 41 - 42 - #include "ttm_bo_api.h" 43 - #include "ttm_kmap_iter.h" 44 - #include "ttm_placement.h" 45 - #include "ttm_tt.h" 46 - #include "ttm_pool.h" 47 - 48 - /* 49 - * ttm_bo.c 50 - */ 51 - 52 - /** 53 - * ttm_bo_mem_space 54 - * 55 - * @bo: Pointer to a struct ttm_buffer_object. the data of which 56 - * we want to allocate space for. 57 - * @proposed_placement: Proposed new placement for the buffer object. 58 - * @mem: A struct ttm_resource. 59 - * @interruptible: Sleep interruptible when sliping. 60 - * @no_wait_gpu: Return immediately if the GPU is busy. 61 - * 62 - * Allocate memory space for the buffer object pointed to by @bo, using 63 - * the placement flags in @mem, potentially evicting other idle buffer objects. 64 - * This function may sleep while waiting for space to become available. 65 - * Returns: 66 - * -EBUSY: No space available (only if no_wait == 1). 67 - * -ENOMEM: Could not allocate memory for the buffer object, either due to 68 - * fragmentation or concurrent allocators. 69 - * -ERESTARTSYS: An interruptible sleep was interrupted by a signal. 70 - */ 71 - int ttm_bo_mem_space(struct ttm_buffer_object *bo, 72 - struct ttm_placement *placement, 73 - struct ttm_resource **mem, 74 - struct ttm_operation_ctx *ctx); 75 - 76 - /** 77 - * ttm_bo_unmap_virtual 78 - * 79 - * @bo: tear down the virtual mappings for this BO 80 - */ 81 - void ttm_bo_unmap_virtual(struct ttm_buffer_object *bo); 82 - 83 - /** 84 - * ttm_bo_reserve: 85 - * 86 - * @bo: A pointer to a struct ttm_buffer_object. 87 - * @interruptible: Sleep interruptible if waiting. 88 - * @no_wait: Don't sleep while trying to reserve, rather return -EBUSY. 89 - * @ticket: ticket used to acquire the ww_mutex. 90 - * 91 - * Locks a buffer object for validation. (Or prevents other processes from 92 - * locking it for validation), while taking a number of measures to prevent 93 - * deadlocks. 94 - * 95 - * Returns: 96 - * -EDEADLK: The reservation may cause a deadlock. 97 - * Release all buffer reservations, wait for @bo to become unreserved and 98 - * try again. 99 - * -ERESTARTSYS: A wait for the buffer to become unreserved was interrupted by 100 - * a signal. Release all buffer reservations and return to user-space. 101 - * -EBUSY: The function needed to sleep, but @no_wait was true 102 - * -EALREADY: Bo already reserved using @ticket. This error code will only 103 - * be returned if @use_ticket is set to true. 104 - */ 105 - static inline int ttm_bo_reserve(struct ttm_buffer_object *bo, 106 - bool interruptible, bool no_wait, 107 - struct ww_acquire_ctx *ticket) 108 - { 109 - int ret; 110 - 111 - if (no_wait) { 112 - bool success; 113 - if (WARN_ON(ticket)) 114 - return -EBUSY; 115 - 116 - success = dma_resv_trylock(bo->base.resv); 117 - return success ? 0 : -EBUSY; 118 - } 119 - 120 - if (interruptible) 121 - ret = dma_resv_lock_interruptible(bo->base.resv, ticket); 122 - else 123 - ret = dma_resv_lock(bo->base.resv, ticket); 124 - if (ret == -EINTR) 125 - return -ERESTARTSYS; 126 - return ret; 127 - } 128 - 129 - /** 130 - * ttm_bo_reserve_slowpath: 131 - * @bo: A pointer to a struct ttm_buffer_object. 132 - * @interruptible: Sleep interruptible if waiting. 133 - * @sequence: Set (@bo)->sequence to this value after lock 134 - * 135 - * This is called after ttm_bo_reserve returns -EAGAIN and we backed off 136 - * from all our other reservations. Because there are no other reservations 137 - * held by us, this function cannot deadlock any more. 138 - */ 139 - static inline int ttm_bo_reserve_slowpath(struct ttm_buffer_object *bo, 140 - bool interruptible, 141 - struct ww_acquire_ctx *ticket) 142 - { 143 - if (interruptible) { 144 - int ret = dma_resv_lock_slow_interruptible(bo->base.resv, 145 - ticket); 146 - if (ret == -EINTR) 147 - ret = -ERESTARTSYS; 148 - return ret; 149 - } 150 - dma_resv_lock_slow(bo->base.resv, ticket); 151 - return 0; 152 - } 153 - 154 - static inline void 155 - ttm_bo_move_to_lru_tail_unlocked(struct ttm_buffer_object *bo) 156 - { 157 - spin_lock(&bo->bdev->lru_lock); 158 - ttm_bo_move_to_lru_tail(bo); 159 - spin_unlock(&bo->bdev->lru_lock); 160 - } 161 - 162 - static inline void ttm_bo_assign_mem(struct ttm_buffer_object *bo, 163 - struct ttm_resource *new_mem) 164 - { 165 - WARN_ON(bo->resource); 166 - bo->resource = new_mem; 167 - } 168 - 169 - /** 170 - * ttm_bo_move_null = assign memory for a buffer object. 171 - * @bo: The bo to assign the memory to 172 - * @new_mem: The memory to be assigned. 173 - * 174 - * Assign the memory from new_mem to the memory of the buffer object bo. 175 - */ 176 - static inline void ttm_bo_move_null(struct ttm_buffer_object *bo, 177 - struct ttm_resource *new_mem) 178 - { 179 - ttm_resource_free(bo, &bo->resource); 180 - ttm_bo_assign_mem(bo, new_mem); 181 - } 182 - 183 - /** 184 - * ttm_bo_unreserve 185 - * 186 - * @bo: A pointer to a struct ttm_buffer_object. 187 - * 188 - * Unreserve a previous reservation of @bo. 189 - */ 190 - static inline void ttm_bo_unreserve(struct ttm_buffer_object *bo) 191 - { 192 - ttm_bo_move_to_lru_tail_unlocked(bo); 193 - dma_resv_unlock(bo->base.resv); 194 - } 195 - 196 - /* 197 - * ttm_bo_util.c 198 - */ 199 - int ttm_mem_io_reserve(struct ttm_device *bdev, 200 - struct ttm_resource *mem); 201 - void ttm_mem_io_free(struct ttm_device *bdev, 202 - struct ttm_resource *mem); 203 - 204 - /** 205 - * ttm_bo_move_memcpy 206 - * 207 - * @bo: A pointer to a struct ttm_buffer_object. 208 - * @interruptible: Sleep interruptible if waiting. 209 - * @no_wait_gpu: Return immediately if the GPU is busy. 210 - * @new_mem: struct ttm_resource indicating where to move. 211 - * 212 - * Fallback move function for a mappable buffer object in mappable memory. 213 - * The function will, if successful, 214 - * free any old aperture space, and set (@new_mem)->mm_node to NULL, 215 - * and update the (@bo)->mem placement flags. If unsuccessful, the old 216 - * data remains untouched, and it's up to the caller to free the 217 - * memory space indicated by @new_mem. 218 - * Returns: 219 - * !0: Failure. 220 - */ 221 - 222 - int ttm_bo_move_memcpy(struct ttm_buffer_object *bo, 223 - struct ttm_operation_ctx *ctx, 224 - struct ttm_resource *new_mem); 225 - 226 - /** 227 - * ttm_bo_move_accel_cleanup. 228 - * 229 - * @bo: A pointer to a struct ttm_buffer_object. 230 - * @fence: A fence object that signals when moving is complete. 231 - * @evict: This is an evict move. Don't return until the buffer is idle. 232 - * @pipeline: evictions are to be pipelined. 233 - * @new_mem: struct ttm_resource indicating where to move. 234 - * 235 - * Accelerated move function to be called when an accelerated move 236 - * has been scheduled. The function will create a new temporary buffer object 237 - * representing the old placement, and put the sync object on both buffer 238 - * objects. After that the newly created buffer object is unref'd to be 239 - * destroyed when the move is complete. This will help pipeline 240 - * buffer moves. 241 - */ 242 - int ttm_bo_move_accel_cleanup(struct ttm_buffer_object *bo, 243 - struct dma_fence *fence, bool evict, 244 - bool pipeline, 245 - struct ttm_resource *new_mem); 246 - 247 - /** 248 - * ttm_bo_move_sync_cleanup. 249 - * 250 - * @bo: A pointer to a struct ttm_buffer_object. 251 - * @new_mem: struct ttm_resource indicating where to move. 252 - * 253 - * Special case of ttm_bo_move_accel_cleanup where the bo is guaranteed 254 - * by the caller to be idle. Typically used after memcpy buffer moves. 255 - */ 256 - void ttm_bo_move_sync_cleanup(struct ttm_buffer_object *bo, 257 - struct ttm_resource *new_mem); 258 - 259 - /** 260 - * ttm_bo_pipeline_gutting. 261 - * 262 - * @bo: A pointer to a struct ttm_buffer_object. 263 - * 264 - * Pipelined gutting a BO of its backing store. 265 - */ 266 - int ttm_bo_pipeline_gutting(struct ttm_buffer_object *bo); 267 - 268 - /** 269 - * ttm_io_prot 270 - * 271 - * bo: ttm buffer object 272 - * res: ttm resource object 273 - * @tmp: Page protection flag for a normal, cached mapping. 274 - * 275 - * Utility function that returns the pgprot_t that should be used for 276 - * setting up a PTE with the caching model indicated by @c_state. 277 - */ 278 - pgprot_t ttm_io_prot(struct ttm_buffer_object *bo, struct ttm_resource *res, 279 - pgprot_t tmp); 280 - 281 - /** 282 - * ttm_bo_tt_bind 283 - * 284 - * Bind the object tt to a memory resource. 285 - */ 286 - int ttm_bo_tt_bind(struct ttm_buffer_object *bo, struct ttm_resource *mem); 287 - 288 - /** 289 - * ttm_bo_tt_destroy. 290 - */ 291 - void ttm_bo_tt_destroy(struct ttm_buffer_object *bo); 292 - 293 - void ttm_move_memcpy(bool clear, 294 - u32 num_pages, 295 - struct ttm_kmap_iter *dst_iter, 296 - struct ttm_kmap_iter *src_iter); 297 - 298 - struct ttm_kmap_iter * 299 - ttm_kmap_iter_iomap_init(struct ttm_kmap_iter_iomap *iter_io, 300 - struct io_mapping *iomap, 301 - struct sg_table *st, 302 - resource_size_t start); 303 - #endif
+3 -1
include/drm/ttm/ttm_execbuf_util.h
··· 33 33 34 34 #include <linux/list.h> 35 35 36 - #include "ttm_bo_api.h" 36 + struct ww_acquire_ctx; 37 + struct dma_fence; 38 + struct ttm_buffer_object; 37 39 38 40 /** 39 41 * struct ttm_validate_buffer