drm/ttm: ttm_fault callback to allow driver to handle bo placement V3
Subsystems (3)
PATCH 1/1 drm/ttm: ttm_fault callback to allow driver to handle bo placement V3
On fault the driver is given the opportunity to perform any operation it sees fit in order to place the buffer into a CPU visible area of memory. This patch doesn't break TTM users, nouveau, vmwgfx and radeon should keep working properly. Future patch will take advantage of this infrastructure and remove the old path from TTM once driver are converted.
V2 return VM_FAULT_NOPAGE if callback return -EBUSY or -ERESTARTSYS V3 balance io_mem_reserve and io_mem_free call, fault_reserve_notify
is responsible to perform any necessary task for mapping to succeed
Signed-off-by Jerome Glisse <[email protected]>
--- drivers/gpu/drm/ttm/ttm_bo.c | 7 ++- drivers/gpu/drm/ttm/ttm_bo_util.c | 95 ++++++++++++++++++------------------- drivers/gpu/drm/ttm/ttm_bo_vm.c | 46 ++++++++---------- include/drm/ttm/ttm_bo_api.h | 21 ++++++++ include/drm/ttm/ttm_bo_driver.h | 16 ++++++- 5 files changed, 108 insertions(+), 77 deletions(-)
drivers/gpu/drm/ttm/ttm_bo.c +5 -2
@@ -632,6 +632,7 @@ static int ttm_bo_evict(struct ttm_buffer_object *bo, bool interruptible, evict_mem = bo->mem; evict_mem.mm_node =NULL ; +atomic_set (&evict_mem.bus.use_count,0 ); placement.fpfn =0 ; placement.lpfn =0 ;
@@ -1005,6 +1006,7 @@ int ttm_bo_move_buffer(struct ttm_buffer_object *bo, mem.num_pages = bo->num_pages; mem.size = mem.num_pages <<PAGE_SHIFT ; mem.page_alignment = bo->mem.page_alignment; +atomic_set (&mem.bus.use_count,0 );/* * Determine where to move the buffer. */
@@ -1147,6 +1149,7 @@ int ttm_bo_init(struct ttm_bo_device *bdev,kref_init (&bo->list_kref);atomic_set (&bo->cpu_writers,0 );atomic_set (&bo->reserved,1 ); +atomic_set (&bo->mem.bus.use_count,0 );init_waitqueue_head (&bo->event_queue);INIT_LIST_HEAD (&bo->lru);INIT_LIST_HEAD (&bo->ddestroy);
@@ -1574,7 +1577,7 @@ int ttm_bo_pci_offset(struct ttm_bo_device *bdev,if (ttm_mem_reg_is_pci (bdev, mem)) { *bus_offset = mem->mm_node->start <<PAGE_SHIFT ; *bus_size = mem->num_pages <<PAGE_SHIFT ; - *bus_base = man->io_offset; + *bus_base = man->io_offset + (uintptr_t )man->io_addr; }return 0 ;
@@ -1588,8 +1591,8 @@ void ttm_bo_unmap_virtual(struct ttm_buffer_object *bo)if (!bdev->dev_mapping)return ; -unmap_mapping_range (bdev->dev_mapping, offset, holelen,1 ); +ttm_mem_io_free (bdev, &bo->mem); }EXPORT_SYMBOL (ttm_bo_unmap_virtual);
drivers/gpu/drm/ttm/ttm_bo_util.c +46 -49
152 lines not on this page · raw message
drivers/gpu/drm/ttm/ttm_bo_vm.c +21 -25
114 lines not on this page · raw message
include/drm/ttm/ttm_bo_api.h +21 -0
@@ -66,6 +66,24 @@ struct ttm_placement {const uint32_t *busy_placement; }; +/** +* struct ttm_bus_placement +* +* @base: bus base address +* @is_iomem: is this io memory ? +* @size: size in byte +* @offset: offset from the base address +* +* Structure indicating the bus placement of an object. +*/ +struct ttm_bus_placement { +unsigned long base; +unsigned long size; +unsigned long offset; +bool is_iomem; +atomic_t use_count; +}; +/** * struct ttm_mem_reg
@@ -75,6 +93,7 @@ struct ttm_placement {* @num_pages: Actual size of memory region in pages. * @page_alignment: Page alignment. * @placement: Placement flags. +* @bus: Placement on io bus accessible to the CPU * * Structure indicating the placement and space resources used by a * buffer object.
@@ -87,6 +106,7 @@ struct ttm_mem_reg {uint32_t page_alignment;uint32_t mem_type;uint32_t placement; +struct ttm_bus_placement bus; };/**
@@ -274,6 +294,7 @@ struct ttm_bo_kmap_obj { ttm_bo_map_kmap =3 , ttm_bo_map_premapped =4 |TTM_BO_MAP_IOMEM_MASK , } bo_kmap_type; +struct ttm_buffer_object *bo; };/**
include/drm/ttm/ttm_bo_driver.h +15 -1
@@ -352,12 +352,21 @@ struct ttm_bo_driver { struct ttm_mem_reg *new_mem);/* notify the driver we are taking a fault on this BO * and have reserved it */ -void (*fault_reserve_notify)(struct ttm_buffer_object *bo); +int (*fault_reserve_notify)(struct ttm_buffer_object *bo);/** * notify the driver that we're about to swap out this bo */ void (*swap_notify) (struct ttm_buffer_object *bo); + +/** +* Driver callback on when mapping io memory (for bo_move_memcpy +* for instance). TTM will take care to call io_mem_free whenever +* the mapping is not use anymore. io_mem_reserve & io_mem_free +* are balanced. +*/ +int (*io_mem_reserve)(struct ttm_bo_device *bdev,struct ttm_mem_reg *mem); +void (*io_mem_free)(struct ttm_bo_device *bdev,struct ttm_mem_reg *mem); };/**
@@ -685,6 +694,11 @@ extern int ttm_bo_pci_offset(struct ttm_bo_device *bdev,unsigned long *bus_offset, unsigned long *bus_size); +extern int ttm_mem_io_reserve (struct ttm_bo_device *bdev, +struct ttm_mem_reg *mem); +extern void ttm_mem_io_free (struct ttm_bo_device *bdev, +struct ttm_mem_reg *mem); +extern void ttm_bo_global_release (struct ttm_global_reference *ref);extern int ttm_bo_global_init (struct ttm_global_reference *ref);
Signature · 10 lines
1.6.6.1 ------------------------------------------------------------------------------ Download Intel® Parallel Studio Eval Try the new software tools for yourself. Speed compiling, find bugs proactively, and fine-tune applications for parallel performance. See why Intel Parallel Studio got high marks during beta. http://p.sf.net/sfu/intel-sw-dev --