Commit a3185f91 authored by Christian König's avatar Christian König

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: default avatarChristian König <christian.koenig@amd.com>
Reviewed-by: default avatarArunpravin Paneer Selvam <Arunpravin.PaneerSelvam@amd.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20221125102137.1801-4-christian.koenig@amd.com
parent 9bff18d1
...@@ -52,8 +52,7 @@ ...@@ -52,8 +52,7 @@
#include <linux/pci.h> #include <linux/pci.h>
#include <linux/aer.h> #include <linux/aer.h>
#include <drm/ttm/ttm_bo_api.h> #include <drm/ttm/ttm_bo.h>
#include <drm/ttm/ttm_bo_driver.h>
#include <drm/ttm/ttm_placement.h> #include <drm/ttm/ttm_placement.h>
#include <drm/ttm/ttm_execbuf_util.h> #include <drm/ttm/ttm_execbuf_util.h>
......
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
#include <linux/pagemap.h> #include <linux/pagemap.h>
#include <linux/sched/mm.h> #include <linux/sched/mm.h>
#include <linux/sched/task.h> #include <linux/sched/task.h>
#include <drm/ttm/ttm_tt.h>
#include "amdgpu_object.h" #include "amdgpu_object.h"
#include "amdgpu_gem.h" #include "amdgpu_gem.h"
......
...@@ -28,6 +28,8 @@ ...@@ -28,6 +28,8 @@
struct hmm_range; struct hmm_range;
struct drm_file;
struct amdgpu_device; struct amdgpu_device;
struct amdgpu_bo; struct amdgpu_bo;
struct amdgpu_bo_va; struct amdgpu_bo_va;
......
...@@ -32,6 +32,8 @@ ...@@ -32,6 +32,8 @@
#include <drm/amdgpu_drm.h> #include <drm/amdgpu_drm.h>
#include <drm/drm_syncobj.h> #include <drm/drm_syncobj.h>
#include <drm/ttm/ttm_tt.h>
#include "amdgpu_cs.h" #include "amdgpu_cs.h"
#include "amdgpu.h" #include "amdgpu.h"
#include "amdgpu_trace.h" #include "amdgpu_trace.h"
......
...@@ -23,6 +23,8 @@ ...@@ -23,6 +23,8 @@
#ifndef __AMDGPU_CS_H__ #ifndef __AMDGPU_CS_H__
#define __AMDGPU_CS_H__ #define __AMDGPU_CS_H__
#include <linux/ww_mutex.h>
#include "amdgpu_job.h" #include "amdgpu_job.h"
#include "amdgpu_bo_list.h" #include "amdgpu_bo_list.h"
#include "amdgpu_ring.h" #include "amdgpu_ring.h"
......
...@@ -37,6 +37,7 @@ ...@@ -37,6 +37,7 @@
#include "amdgpu_dma_buf.h" #include "amdgpu_dma_buf.h"
#include "amdgpu_xgmi.h" #include "amdgpu_xgmi.h"
#include <drm/amdgpu_drm.h> #include <drm/amdgpu_drm.h>
#include <drm/ttm/ttm_tt.h>
#include <linux/dma-buf.h> #include <linux/dma-buf.h>
#include <linux/dma-fence-array.h> #include <linux/dma-fence-array.h>
#include <linux/pci-p2pdma.h> #include <linux/pci-p2pdma.h>
......
...@@ -30,7 +30,6 @@ ...@@ -30,7 +30,6 @@
#include <linux/rbtree.h> #include <linux/rbtree.h>
#include <drm/gpu_scheduler.h> #include <drm/gpu_scheduler.h>
#include <drm/drm_file.h> #include <drm/drm_file.h>
#include <drm/ttm/ttm_bo_driver.h>
#include <linux/sched/mm.h> #include <linux/sched/mm.h>
#include "amdgpu_sync.h" #include "amdgpu_sync.h"
......
...@@ -34,6 +34,7 @@ ...@@ -34,6 +34,7 @@
#include <drm/amdgpu_drm.h> #include <drm/amdgpu_drm.h>
#include <drm/drm_drv.h> #include <drm/drm_drv.h>
#include <drm/drm_gem_ttm_helper.h> #include <drm/drm_gem_ttm_helper.h>
#include <drm/ttm/ttm_tt.h>
#include "amdgpu.h" #include "amdgpu.h"
#include "amdgpu_display.h" #include "amdgpu_display.h"
......
...@@ -35,6 +35,7 @@ ...@@ -35,6 +35,7 @@
#include "amdgpu_xgmi.h" #include "amdgpu_xgmi.h"
#include <drm/drm_drv.h> #include <drm/drm_drv.h>
#include <drm/ttm/ttm_tt.h>
/** /**
* amdgpu_gmc_pdb0_alloc - allocate vram for pdb0 * amdgpu_gmc_pdb0_alloc - allocate vram for pdb0
......
...@@ -44,10 +44,10 @@ ...@@ -44,10 +44,10 @@
#include <linux/module.h> #include <linux/module.h>
#include <drm/drm_drv.h> #include <drm/drm_drv.h>
#include <drm/ttm/ttm_bo_api.h> #include <drm/ttm/ttm_bo.h>
#include <drm/ttm/ttm_bo_driver.h>
#include <drm/ttm/ttm_placement.h> #include <drm/ttm/ttm_placement.h>
#include <drm/ttm/ttm_range_manager.h> #include <drm/ttm/ttm_range_manager.h>
#include <drm/ttm/ttm_tt.h>
#include <drm/amdgpu_drm.h> #include <drm/amdgpu_drm.h>
#include <drm/drm_drv.h> #include <drm/drm_drv.h>
......
...@@ -33,6 +33,7 @@ ...@@ -33,6 +33,7 @@
#include <drm/amdgpu_drm.h> #include <drm/amdgpu_drm.h>
#include <drm/drm_drv.h> #include <drm/drm_drv.h>
#include <drm/ttm/ttm_tt.h>
#include "amdgpu.h" #include "amdgpu.h"
#include "amdgpu_trace.h" #include "amdgpu_trace.h"
#include "amdgpu_amdkfd.h" #include "amdgpu_amdkfd.h"
......
...@@ -29,7 +29,7 @@ ...@@ -29,7 +29,7 @@
#include <linux/rbtree.h> #include <linux/rbtree.h>
#include <drm/gpu_scheduler.h> #include <drm/gpu_scheduler.h>
#include <drm/drm_file.h> #include <drm/drm_file.h>
#include <drm/ttm/ttm_bo_driver.h> #include <drm/ttm/ttm_bo.h>
#include <linux/sched/mm.h> #include <linux/sched/mm.h>
#include "amdgpu_sync.h" #include "amdgpu_sync.h"
......
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
#include <linux/types.h> #include <linux/types.h>
#include <linux/sched/task.h> #include <linux/sched/task.h>
#include <drm/ttm/ttm_tt.h>
#include "amdgpu_sync.h" #include "amdgpu_sync.h"
#include "amdgpu_object.h" #include "amdgpu_object.h"
#include "amdgpu_vm.h" #include "amdgpu_vm.h"
......
...@@ -3,6 +3,8 @@ ...@@ -3,6 +3,8 @@
#include <linux/module.h> #include <linux/module.h>
#include <drm/drm_gem_ttm_helper.h> #include <drm/drm_gem_ttm_helper.h>
#include <drm/ttm/ttm_placement.h>
#include <drm/ttm/ttm_tt.h>
/** /**
* DOC: overview * DOC: overview
......
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
#include <drm/drm_simple_kms_helper.h> #include <drm/drm_simple_kms_helper.h>
#include <drm/ttm/ttm_range_manager.h> #include <drm/ttm/ttm_range_manager.h>
#include <drm/ttm/ttm_tt.h>
static const struct drm_gem_object_funcs drm_gem_vram_object_funcs; static const struct drm_gem_object_funcs drm_gem_vram_object_funcs;
......
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
#include <linux/mmu_notifier.h> #include <linux/mmu_notifier.h>
#include <drm/drm_gem.h> #include <drm/drm_gem.h>
#include <drm/ttm/ttm_bo_api.h> #include <drm/ttm/ttm_bo.h>
#include <uapi/drm/i915_drm.h> #include <uapi/drm/i915_drm.h>
#include "i915_active.h" #include "i915_active.h"
......
...@@ -5,8 +5,8 @@ ...@@ -5,8 +5,8 @@
#include <linux/shmem_fs.h> #include <linux/shmem_fs.h>
#include <drm/ttm/ttm_bo_driver.h>
#include <drm/ttm/ttm_placement.h> #include <drm/ttm/ttm_placement.h>
#include <drm/ttm/ttm_tt.h>
#include <drm/drm_buddy.h> #include <drm/drm_buddy.h>
#include "i915_drv.h" #include "i915_drv.h"
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
* Copyright © 2021 Intel Corporation * Copyright © 2021 Intel Corporation
*/ */
#include <drm/ttm/ttm_bo_driver.h> #include <drm/ttm/ttm_tt.h>
#include "i915_deps.h" #include "i915_deps.h"
#include "i915_drv.h" #include "i915_drv.h"
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
#include <linux/dma-fence.h> #include <linux/dma-fence.h>
#include <linux/slab.h> #include <linux/slab.h>
#include <drm/ttm/ttm_bo_api.h> #include <drm/ttm/ttm_bo.h>
#include "i915_deps.h" #include "i915_deps.h"
......
...@@ -5,8 +5,8 @@ ...@@ -5,8 +5,8 @@
#include <linux/slab.h> #include <linux/slab.h>
#include <drm/ttm/ttm_bo_driver.h>
#include <drm/ttm/ttm_placement.h> #include <drm/ttm/ttm_placement.h>
#include <drm/ttm/ttm_bo.h>
#include <drm/drm_buddy.h> #include <drm/drm_buddy.h>
......
...@@ -2,7 +2,6 @@ ...@@ -2,7 +2,6 @@
/* /*
* Copyright © 2021 Intel Corporation * Copyright © 2021 Intel Corporation
*/ */
#include <drm/ttm/ttm_bo_driver.h>
#include <drm/ttm/ttm_device.h> #include <drm/ttm/ttm_device.h>
#include <drm/ttm/ttm_range_manager.h> #include <drm/ttm/ttm_range_manager.h>
......
...@@ -28,6 +28,7 @@ ...@@ -28,6 +28,7 @@
*/ */
#include <linux/dma-mapping.h> #include <linux/dma-mapping.h>
#include <drm/ttm/ttm_tt.h>
#include "nouveau_drv.h" #include "nouveau_drv.h"
#include "nouveau_chan.h" #include "nouveau_chan.h"
......
/* SPDX-License-Identifier: MIT */ /* SPDX-License-Identifier: MIT */
#ifndef __NOUVEAU_BO_H__ #ifndef __NOUVEAU_BO_H__
#define __NOUVEAU_BO_H__ #define __NOUVEAU_BO_H__
#include <drm/ttm/ttm_bo_driver.h>
#include <drm/drm_gem.h> #include <drm/drm_gem.h>
#include <drm/ttm/ttm_bo.h>
#include <drm/ttm/ttm_placement.h>
struct nouveau_channel; struct nouveau_channel;
struct nouveau_cli; struct nouveau_cli;
......
...@@ -51,8 +51,7 @@ ...@@ -51,8 +51,7 @@
#include <drm/drm_drv.h> #include <drm/drm_drv.h>
#include <drm/drm_file.h> #include <drm/drm_file.h>
#include <drm/ttm/ttm_bo_api.h> #include <drm/ttm/ttm_bo.h>
#include <drm/ttm/ttm_bo_driver.h>
#include <drm/ttm/ttm_placement.h> #include <drm/ttm/ttm_placement.h>
#include <drm/drm_audio_component.h> #include <drm/drm_audio_component.h>
......
...@@ -19,11 +19,12 @@ ...@@ -19,11 +19,12 @@
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE. * OTHER DEALINGS IN THE SOFTWARE.
*/ */
#include <drm/ttm/ttm_tt.h>
#include "nouveau_mem.h" #include "nouveau_mem.h"
#include "nouveau_drv.h" #include "nouveau_drv.h"
#include "nouveau_bo.h" #include "nouveau_bo.h"
#include <drm/ttm/ttm_bo_driver.h>
#include <nvif/class.h> #include <nvif/class.h>
#include <nvif/if000a.h> #include <nvif/if000a.h>
......
#ifndef __NOUVEAU_MEM_H__ #ifndef __NOUVEAU_MEM_H__
#define __NOUVEAU_MEM_H__ #define __NOUVEAU_MEM_H__
#include <drm/ttm/ttm_bo_api.h> #include <drm/ttm/ttm_bo.h>
struct ttm_tt; struct ttm_tt;
#include <nvif/mem.h> #include <nvif/mem.h>
......
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
*/ */
#include <linux/dma-buf.h> #include <linux/dma-buf.h>
#include <drm/ttm/ttm_tt.h>
#include "nouveau_drv.h" #include "nouveau_drv.h"
#include "nouveau_gem.h" #include "nouveau_gem.h"
......
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
#include <linux/pagemap.h> #include <linux/pagemap.h>
#include <linux/slab.h> #include <linux/slab.h>
#include <drm/ttm/ttm_tt.h>
#include "nouveau_drv.h" #include "nouveau_drv.h"
#include "nouveau_mem.h" #include "nouveau_mem.h"
......
...@@ -42,8 +42,7 @@ ...@@ -42,8 +42,7 @@
#include <drm/drm_ioctl.h> #include <drm/drm_ioctl.h>
#include <drm/drm_gem.h> #include <drm/drm_gem.h>
#include <drm/qxl_drm.h> #include <drm/qxl_drm.h>
#include <drm/ttm/ttm_bo_api.h> #include <drm/ttm/ttm_bo.h>
#include <drm/ttm/ttm_bo_driver.h>
#include <drm/ttm/ttm_execbuf_util.h> #include <drm/ttm/ttm_execbuf_util.h>
#include <drm/ttm/ttm_placement.h> #include <drm/ttm/ttm_placement.h>
......
...@@ -29,10 +29,10 @@ ...@@ -29,10 +29,10 @@
#include <drm/drm_file.h> #include <drm/drm_file.h>
#include <drm/drm_debugfs.h> #include <drm/drm_debugfs.h>
#include <drm/qxl_drm.h> #include <drm/qxl_drm.h>
#include <drm/ttm/ttm_bo_api.h> #include <drm/ttm/ttm_bo.h>
#include <drm/ttm/ttm_bo_driver.h>
#include <drm/ttm/ttm_placement.h> #include <drm/ttm/ttm_placement.h>
#include <drm/ttm/ttm_range_manager.h> #include <drm/ttm/ttm_range_manager.h>
#include <drm/ttm/ttm_tt.h>
#include "qxl_drv.h" #include "qxl_drv.h"
#include "qxl_object.h" #include "qxl_object.h"
......
...@@ -73,8 +73,7 @@ ...@@ -73,8 +73,7 @@
#include <linux/mmu_notifier.h> #include <linux/mmu_notifier.h>
#endif #endif
#include <drm/ttm/ttm_bo_api.h> #include <drm/ttm/ttm_bo.h>
#include <drm/ttm/ttm_bo_driver.h>
#include <drm/ttm/ttm_placement.h> #include <drm/ttm/ttm_placement.h>
#include <drm/ttm/ttm_execbuf_util.h> #include <drm/ttm/ttm_execbuf_util.h>
......
...@@ -29,6 +29,8 @@ ...@@ -29,6 +29,8 @@
#include <drm/drm_prime.h> #include <drm/drm_prime.h>
#include <drm/radeon_drm.h> #include <drm/radeon_drm.h>
#include <drm/ttm/ttm_tt.h>
#include "radeon.h" #include "radeon.h"
#include "radeon_prime.h" #include "radeon_prime.h"
......
...@@ -42,10 +42,10 @@ ...@@ -42,10 +42,10 @@
#include <drm/drm_file.h> #include <drm/drm_file.h>
#include <drm/drm_prime.h> #include <drm/drm_prime.h>
#include <drm/radeon_drm.h> #include <drm/radeon_drm.h>
#include <drm/ttm/ttm_bo_api.h> #include <drm/ttm/ttm_bo.h>
#include <drm/ttm/ttm_bo_driver.h>
#include <drm/ttm/ttm_placement.h> #include <drm/ttm/ttm_placement.h>
#include <drm/ttm/ttm_range_manager.h> #include <drm/ttm/ttm_range_manager.h>
#include <drm/ttm/ttm_tt.h>
#include "radeon_reg.h" #include "radeon_reg.h"
#include "radeon.h" #include "radeon.h"
......
...@@ -31,8 +31,10 @@ ...@@ -31,8 +31,10 @@
#define pr_fmt(fmt) "[TTM] " fmt #define pr_fmt(fmt) "[TTM] " fmt
#include <drm/ttm/ttm_bo_driver.h> #include <drm/ttm/ttm_bo.h>
#include <drm/ttm/ttm_placement.h> #include <drm/ttm/ttm_placement.h>
#include <drm/ttm/ttm_tt.h>
#include <linux/jiffies.h> #include <linux/jiffies.h>
#include <linux/slab.h> #include <linux/slab.h>
#include <linux/sched.h> #include <linux/sched.h>
...@@ -381,6 +383,13 @@ static void ttm_bo_release(struct kref *kref) ...@@ -381,6 +383,13 @@ static void ttm_bo_release(struct kref *kref)
bo->destroy(bo); bo->destroy(bo);
} }
/**
* ttm_bo_put
*
* @bo: The buffer object.
*
* Unreference a buffer object.
*/
void ttm_bo_put(struct ttm_buffer_object *bo) void ttm_bo_put(struct ttm_buffer_object *bo)
{ {
kref_put(&bo->kref, ttm_bo_release); kref_put(&bo->kref, ttm_bo_release);
...@@ -467,6 +476,14 @@ static int ttm_bo_evict(struct ttm_buffer_object *bo, ...@@ -467,6 +476,14 @@ static int ttm_bo_evict(struct ttm_buffer_object *bo,
return ret; return ret;
} }
/**
* ttm_bo_eviction_valuable
*
* @bo: The buffer object to evict
* @place: the placement we need to make room for
*
* Check if it is valuable to evict the BO to make room for the given placement.
*/
bool ttm_bo_eviction_valuable(struct ttm_buffer_object *bo, bool ttm_bo_eviction_valuable(struct ttm_buffer_object *bo,
const struct ttm_place *place) const struct ttm_place *place)
{ {
...@@ -726,13 +743,23 @@ static int ttm_bo_mem_force_space(struct ttm_buffer_object *bo, ...@@ -726,13 +743,23 @@ static int ttm_bo_mem_force_space(struct ttm_buffer_object *bo,
return ttm_bo_add_move_fence(bo, man, *mem, ctx->no_wait_gpu); return ttm_bo_add_move_fence(bo, man, *mem, ctx->no_wait_gpu);
} }
/* /**
* Creates space for memory region @mem according to its type. * ttm_bo_mem_space
* *
* This function first searches for free space in compatible memory types in * @bo: Pointer to a struct ttm_buffer_object. the data of which
* the priority order defined by the driver. If free space isn't found, then * we want to allocate space for.
* ttm_bo_mem_force_space is attempted in priority order to evict and find * @proposed_placement: Proposed new placement for the buffer object.
* space. * @mem: A struct ttm_resource.
* @ctx: if and how to sleep, lock buffers and alloc memory
*
* Allocate memory space for the buffer object pointed to by @bo, using
* the placement flags in @placement, potentially evicting other idle buffer objects.
* This function may sleep while waiting for space to become available.
* Returns:
* -EBUSY: No space available (only if no_wait == 1).
* -ENOMEM: Could not allocate memory for the buffer object, either due to
* fragmentation or concurrent allocators.
* -ERESTARTSYS: An interruptible sleep was interrupted by a signal.
*/ */
int ttm_bo_mem_space(struct ttm_buffer_object *bo, int ttm_bo_mem_space(struct ttm_buffer_object *bo,
struct ttm_placement *placement, struct ttm_placement *placement,
...@@ -838,6 +865,21 @@ static int ttm_bo_move_buffer(struct ttm_buffer_object *bo, ...@@ -838,6 +865,21 @@ static int ttm_bo_move_buffer(struct ttm_buffer_object *bo,
return ret; return ret;
} }
/**
* ttm_bo_validate
*
* @bo: The buffer object.
* @placement: Proposed placement for the buffer object.
* @ctx: validation parameters.
*
* Changes placement and caching policy of the buffer object
* according proposed placement.
* Returns
* -EINVAL on invalid proposed placement.
* -ENOMEM on out-of-memory condition.
* -EBUSY if no_wait is true and buffer busy.
* -ERESTARTSYS if interrupted by a signal.
*/
int ttm_bo_validate(struct ttm_buffer_object *bo, int ttm_bo_validate(struct ttm_buffer_object *bo,
struct ttm_placement *placement, struct ttm_placement *placement,
struct ttm_operation_ctx *ctx) struct ttm_operation_ctx *ctx)
...@@ -1030,6 +1072,11 @@ EXPORT_SYMBOL(ttm_bo_init_validate); ...@@ -1030,6 +1072,11 @@ EXPORT_SYMBOL(ttm_bo_init_validate);
* buffer object vm functions. * buffer object vm functions.
*/ */
/**
* ttm_bo_unmap_virtual
*
* @bo: tear down the virtual mappings for this BO
*/
void ttm_bo_unmap_virtual(struct ttm_buffer_object *bo) void ttm_bo_unmap_virtual(struct ttm_buffer_object *bo)
{ {
struct ttm_device *bdev = bo->bdev; struct ttm_device *bdev = bo->bdev;
...@@ -1039,6 +1086,20 @@ void ttm_bo_unmap_virtual(struct ttm_buffer_object *bo) ...@@ -1039,6 +1086,20 @@ void ttm_bo_unmap_virtual(struct ttm_buffer_object *bo)
} }
EXPORT_SYMBOL(ttm_bo_unmap_virtual); EXPORT_SYMBOL(ttm_bo_unmap_virtual);
/**
* ttm_bo_wait - wait for buffer idle.
*
* @bo: The buffer object.
* @interruptible: Use interruptible wait.
* @no_wait: Return immediately if buffer is busy.
*
* This function must be called with the bo::mutex held, and makes
* sure any previous rendering to the buffer is completed.
* Note: It might be necessary to block validations before the
* wait by reserving the buffer.
* Returns -EBUSY if no_wait is true and the buffer is busy.
* Returns -ERESTARTSYS if interrupted by a signal.
*/
int ttm_bo_wait(struct ttm_buffer_object *bo, int ttm_bo_wait(struct ttm_buffer_object *bo,
bool interruptible, bool no_wait) bool interruptible, bool no_wait)
{ {
...@@ -1063,6 +1124,12 @@ int ttm_bo_wait(struct ttm_buffer_object *bo, ...@@ -1063,6 +1124,12 @@ int ttm_bo_wait(struct ttm_buffer_object *bo,
} }
EXPORT_SYMBOL(ttm_bo_wait); EXPORT_SYMBOL(ttm_bo_wait);
int ttm_bo_wait_ctx(struct ttm_buffer_object *bo, struct ttm_operation_ctx *ctx)
{
return ttm_bo_wait(bo, ctx->interruptible, ctx->no_wait_gpu);
}
EXPORT_SYMBOL(ttm_bo_wait_ctx);
int ttm_bo_swapout(struct ttm_buffer_object *bo, struct ttm_operation_ctx *ctx, int ttm_bo_swapout(struct ttm_buffer_object *bo, struct ttm_operation_ctx *ctx,
gfp_t gfp_flags) gfp_t gfp_flags)
{ {
......
...@@ -29,18 +29,11 @@ ...@@ -29,18 +29,11 @@
* Authors: Thomas Hellstrom <thellstrom-at-vmware-dot-com> * Authors: Thomas Hellstrom <thellstrom-at-vmware-dot-com>
*/ */
#include <drm/ttm/ttm_bo_driver.h> #include <drm/ttm/ttm_bo.h>
#include <drm/ttm/ttm_placement.h> #include <drm/ttm/ttm_placement.h>
#include <drm/ttm/ttm_tt.h>
#include <drm/drm_cache.h> #include <drm/drm_cache.h>
#include <drm/drm_vma_manager.h>
#include <linux/iosys-map.h>
#include <linux/io.h>
#include <linux/highmem.h>
#include <linux/wait.h>
#include <linux/slab.h>
#include <linux/vmalloc.h>
#include <linux/module.h>
#include <linux/dma-resv.h>
struct ttm_transfer_obj { struct ttm_transfer_obj {
struct ttm_buffer_object base; struct ttm_buffer_object base;
...@@ -128,6 +121,23 @@ void ttm_move_memcpy(bool clear, ...@@ -128,6 +121,23 @@ void ttm_move_memcpy(bool clear,
} }
EXPORT_SYMBOL(ttm_move_memcpy); EXPORT_SYMBOL(ttm_move_memcpy);
/**
* ttm_bo_move_memcpy
*
* @bo: A pointer to a struct ttm_buffer_object.
* @interruptible: Sleep interruptible if waiting.
* @no_wait_gpu: Return immediately if the GPU is busy.
* @new_mem: struct ttm_resource indicating where to move.
*
* Fallback move function for a mappable buffer object in mappable memory.
* The function will, if successful,
* free any old aperture space, and set (@new_mem)->mm_node to NULL,
* and update the (@bo)->mem placement flags. If unsuccessful, the old
* data remains untouched, and it's up to the caller to free the
* memory space indicated by @new_mem.
* Returns:
* !0: Failure.
*/
int ttm_bo_move_memcpy(struct ttm_buffer_object *bo, int ttm_bo_move_memcpy(struct ttm_buffer_object *bo,
struct ttm_operation_ctx *ctx, struct ttm_operation_ctx *ctx,
struct ttm_resource *dst_mem) struct ttm_resource *dst_mem)
...@@ -266,6 +276,16 @@ static int ttm_buffer_object_transfer(struct ttm_buffer_object *bo, ...@@ -266,6 +276,16 @@ static int ttm_buffer_object_transfer(struct ttm_buffer_object *bo,
return 0; return 0;
} }
/**
* ttm_io_prot
*
* bo: ttm buffer object
* res: ttm resource object
* @tmp: Page protection flag for a normal, cached mapping.
*
* Utility function that returns the pgprot_t that should be used for
* setting up a PTE with the caching model indicated by @c_state.
*/
pgprot_t ttm_io_prot(struct ttm_buffer_object *bo, struct ttm_resource *res, pgprot_t ttm_io_prot(struct ttm_buffer_object *bo, struct ttm_resource *res,
pgprot_t tmp) pgprot_t tmp)
{ {
...@@ -347,6 +367,22 @@ static int ttm_bo_kmap_ttm(struct ttm_buffer_object *bo, ...@@ -347,6 +367,22 @@ static int ttm_bo_kmap_ttm(struct ttm_buffer_object *bo,
return (!map->virtual) ? -ENOMEM : 0; return (!map->virtual) ? -ENOMEM : 0;
} }
/**
* ttm_bo_kmap
*
* @bo: The buffer object.
* @start_page: The first page to map.
* @num_pages: Number of pages to map.
* @map: pointer to a struct ttm_bo_kmap_obj representing the map.
*
* Sets up a kernel virtual mapping, using ioremap, vmap or kmap to the
* data in the buffer object. The ttm_kmap_obj_virtual function can then be
* used to obtain a virtual address to the data.
*
* Returns
* -ENOMEM: Out of memory.
* -EINVAL: Invalid range.
*/
int ttm_bo_kmap(struct ttm_buffer_object *bo, int ttm_bo_kmap(struct ttm_buffer_object *bo,
unsigned long start_page, unsigned long num_pages, unsigned long start_page, unsigned long num_pages,
struct ttm_bo_kmap_obj *map) struct ttm_bo_kmap_obj *map)
...@@ -374,6 +410,13 @@ int ttm_bo_kmap(struct ttm_buffer_object *bo, ...@@ -374,6 +410,13 @@ int ttm_bo_kmap(struct ttm_buffer_object *bo,
} }
EXPORT_SYMBOL(ttm_bo_kmap); EXPORT_SYMBOL(ttm_bo_kmap);
/**
* ttm_bo_kunmap
*
* @map: Object describing the map to unmap.
*
* Unmaps a kernel map set up by ttm_bo_kmap.
*/
void ttm_bo_kunmap(struct ttm_bo_kmap_obj *map) void ttm_bo_kunmap(struct ttm_bo_kmap_obj *map)
{ {
if (!map->virtual) if (!map->virtual)
...@@ -399,6 +442,20 @@ void ttm_bo_kunmap(struct ttm_bo_kmap_obj *map) ...@@ -399,6 +442,20 @@ void ttm_bo_kunmap(struct ttm_bo_kmap_obj *map)
} }
EXPORT_SYMBOL(ttm_bo_kunmap); EXPORT_SYMBOL(ttm_bo_kunmap);
/**
* ttm_bo_vmap
*
* @bo: The buffer object.
* @map: pointer to a struct iosys_map representing the map.
*
* Sets up a kernel virtual mapping, using ioremap or vmap to the
* data in the buffer object. The parameter @map returns the virtual
* address as struct iosys_map. Unmap the buffer with ttm_bo_vunmap().
*
* Returns
* -ENOMEM: Out of memory.
* -EINVAL: Invalid range.
*/
int ttm_bo_vmap(struct ttm_buffer_object *bo, struct iosys_map *map) int ttm_bo_vmap(struct ttm_buffer_object *bo, struct iosys_map *map)
{ {
struct ttm_resource *mem = bo->resource; struct ttm_resource *mem = bo->resource;
...@@ -460,6 +517,14 @@ int ttm_bo_vmap(struct ttm_buffer_object *bo, struct iosys_map *map) ...@@ -460,6 +517,14 @@ int ttm_bo_vmap(struct ttm_buffer_object *bo, struct iosys_map *map)
} }
EXPORT_SYMBOL(ttm_bo_vmap); EXPORT_SYMBOL(ttm_bo_vmap);
/**
* ttm_bo_vunmap
*
* @bo: The buffer object.
* @map: Object describing the map to unmap.
*
* Unmaps a kernel map set up by ttm_bo_vmap().
*/
void ttm_bo_vunmap(struct ttm_buffer_object *bo, struct iosys_map *map) void ttm_bo_vunmap(struct ttm_buffer_object *bo, struct iosys_map *map)
{ {
struct ttm_resource *mem = bo->resource; struct ttm_resource *mem = bo->resource;
...@@ -553,6 +618,22 @@ static void ttm_bo_move_pipeline_evict(struct ttm_buffer_object *bo, ...@@ -553,6 +618,22 @@ static void ttm_bo_move_pipeline_evict(struct ttm_buffer_object *bo,
ttm_resource_free(bo, &bo->resource); ttm_resource_free(bo, &bo->resource);
} }
/**
* ttm_bo_move_accel_cleanup.
*
* @bo: A pointer to a struct ttm_buffer_object.
* @fence: A fence object that signals when moving is complete.
* @evict: This is an evict move. Don't return until the buffer is idle.
* @pipeline: evictions are to be pipelined.
* @new_mem: struct ttm_resource indicating where to move.
*
* Accelerated move function to be called when an accelerated move
* has been scheduled. The function will create a new temporary buffer object
* representing the old placement, and put the sync object on both buffer
* objects. After that the newly created buffer object is unref'd to be
* destroyed when the move is complete. This will help pipeline
* buffer moves.
*/
int ttm_bo_move_accel_cleanup(struct ttm_buffer_object *bo, int ttm_bo_move_accel_cleanup(struct ttm_buffer_object *bo,
struct dma_fence *fence, struct dma_fence *fence,
bool evict, bool evict,
...@@ -581,6 +662,15 @@ int ttm_bo_move_accel_cleanup(struct ttm_buffer_object *bo, ...@@ -581,6 +662,15 @@ int ttm_bo_move_accel_cleanup(struct ttm_buffer_object *bo,
} }
EXPORT_SYMBOL(ttm_bo_move_accel_cleanup); EXPORT_SYMBOL(ttm_bo_move_accel_cleanup);
/**
* ttm_bo_move_sync_cleanup.
*
* @bo: A pointer to a struct ttm_buffer_object.
* @new_mem: struct ttm_resource indicating where to move.
*
* Special case of ttm_bo_move_accel_cleanup where the bo is guaranteed
* by the caller to be idle. Typically used after memcpy buffer moves.
*/
void ttm_bo_move_sync_cleanup(struct ttm_buffer_object *bo, void ttm_bo_move_sync_cleanup(struct ttm_buffer_object *bo,
struct ttm_resource *new_mem) struct ttm_resource *new_mem)
{ {
......
...@@ -31,17 +31,12 @@ ...@@ -31,17 +31,12 @@
#define pr_fmt(fmt) "[TTM] " fmt #define pr_fmt(fmt) "[TTM] " fmt
#include <drm/ttm/ttm_bo_driver.h> #include <drm/ttm/ttm_bo.h>
#include <drm/ttm/ttm_placement.h> #include <drm/ttm/ttm_placement.h>
#include <drm/drm_vma_manager.h> #include <drm/ttm/ttm_tt.h>
#include <drm/drm_drv.h> #include <drm/drm_drv.h>
#include <drm/drm_managed.h> #include <drm/drm_managed.h>
#include <linux/mm.h>
#include <linux/pfn_t.h>
#include <linux/rbtree.h>
#include <linux/module.h>
#include <linux/uaccess.h>
#include <linux/mem_encrypt.h>
static vm_fault_t ttm_bo_vm_fault_idle(struct ttm_buffer_object *bo, static vm_fault_t ttm_bo_vm_fault_idle(struct ttm_buffer_object *bo,
struct vm_fault *vmf) struct vm_fault *vmf)
...@@ -446,6 +441,14 @@ static const struct vm_operations_struct ttm_bo_vm_ops = { ...@@ -446,6 +441,14 @@ static const struct vm_operations_struct ttm_bo_vm_ops = {
.access = ttm_bo_vm_access, .access = ttm_bo_vm_access,
}; };
/**
* ttm_bo_mmap_obj - mmap memory backed by a ttm buffer object.
*
* @vma: vma as input from the fbdev mmap method.
* @bo: The bo backing the address space.
*
* Maps a buffer object.
*/
int ttm_bo_mmap_obj(struct vm_area_struct *vma, struct ttm_buffer_object *bo) int ttm_bo_mmap_obj(struct vm_area_struct *vma, struct ttm_buffer_object *bo)
{ {
/* Enforce no COW since would have really strange behavior with it. */ /* Enforce no COW since would have really strange behavior with it. */
......
...@@ -29,10 +29,10 @@ ...@@ -29,10 +29,10 @@
#include <linux/mm.h> #include <linux/mm.h>
#include <drm/ttm/ttm_bo.h>
#include <drm/ttm/ttm_device.h> #include <drm/ttm/ttm_device.h>
#include <drm/ttm/ttm_tt.h> #include <drm/ttm/ttm_tt.h>
#include <drm/ttm/ttm_placement.h> #include <drm/ttm/ttm_placement.h>
#include <drm/ttm/ttm_bo_api.h>
#include "ttm_module.h" #include "ttm_module.h"
......
...@@ -27,11 +27,7 @@ ...@@ -27,11 +27,7 @@
**************************************************************************/ **************************************************************************/
#include <drm/ttm/ttm_execbuf_util.h> #include <drm/ttm/ttm_execbuf_util.h>
#include <drm/ttm/ttm_bo_driver.h> #include <drm/ttm/ttm_bo.h>
#include <drm/ttm/ttm_placement.h>
#include <linux/wait.h>
#include <linux/sched.h>
#include <linux/module.h>
static void ttm_eu_backoff_reservation_reverse(struct list_head *list, static void ttm_eu_backoff_reservation_reverse(struct list_head *list,
struct ttm_validate_buffer *entry) struct ttm_validate_buffer *entry)
......
...@@ -33,6 +33,7 @@ ...@@ -33,6 +33,7 @@
#include <linux/module.h> #include <linux/module.h>
#include <linux/dma-mapping.h> #include <linux/dma-mapping.h>
#include <linux/debugfs.h>
#include <linux/highmem.h> #include <linux/highmem.h>
#include <linux/sched/mm.h> #include <linux/sched/mm.h>
...@@ -41,8 +42,8 @@ ...@@ -41,8 +42,8 @@
#endif #endif
#include <drm/ttm/ttm_pool.h> #include <drm/ttm/ttm_pool.h>
#include <drm/ttm/ttm_bo_driver.h>
#include <drm/ttm/ttm_tt.h> #include <drm/ttm/ttm_tt.h>
#include <drm/ttm/ttm_bo.h>
#include "ttm_module.h" #include "ttm_module.h"
......
...@@ -32,7 +32,7 @@ ...@@ -32,7 +32,7 @@
#include <drm/ttm/ttm_device.h> #include <drm/ttm/ttm_device.h>
#include <drm/ttm/ttm_placement.h> #include <drm/ttm/ttm_placement.h>
#include <drm/ttm/ttm_range_manager.h> #include <drm/ttm/ttm_range_manager.h>
#include <drm/ttm/ttm_bo_api.h> #include <drm/ttm/ttm_bo.h>
#include <drm/drm_mm.h> #include <drm/drm_mm.h>
#include <linux/slab.h> #include <linux/slab.h>
#include <linux/spinlock.h> #include <linux/spinlock.h>
......
...@@ -26,8 +26,9 @@ ...@@ -26,8 +26,9 @@
#include <linux/io-mapping.h> #include <linux/io-mapping.h>
#include <linux/scatterlist.h> #include <linux/scatterlist.h>
#include <drm/ttm/ttm_bo.h>
#include <drm/ttm/ttm_placement.h>
#include <drm/ttm/ttm_resource.h> #include <drm/ttm/ttm_resource.h>
#include <drm/ttm/ttm_bo_driver.h>
/** /**
* ttm_lru_bulk_move_init - initialize a bulk move structure * ttm_lru_bulk_move_init - initialize a bulk move structure
......
...@@ -36,7 +36,8 @@ ...@@ -36,7 +36,8 @@
#include <linux/file.h> #include <linux/file.h>
#include <linux/module.h> #include <linux/module.h>
#include <drm/drm_cache.h> #include <drm/drm_cache.h>
#include <drm/ttm/ttm_bo_driver.h> #include <drm/ttm/ttm_bo.h>
#include <drm/ttm/ttm_tt.h>
#include "ttm_module.h" #include "ttm_module.h"
......
...@@ -28,7 +28,7 @@ ...@@ -28,7 +28,7 @@
#include <linux/dmapool.h> #include <linux/dmapool.h>
#include <linux/pci.h> #include <linux/pci.h>
#include <drm/ttm/ttm_bo_api.h> #include <drm/ttm/ttm_bo.h>
#include "vmwgfx_drv.h" #include "vmwgfx_drv.h"
......
...@@ -40,7 +40,6 @@ ...@@ -40,7 +40,6 @@
#include <drm/drm_ioctl.h> #include <drm/drm_ioctl.h>
#include <drm/drm_module.h> #include <drm/drm_module.h>
#include <drm/drm_sysfs.h> #include <drm/drm_sysfs.h>
#include <drm/ttm/ttm_bo_driver.h>
#include <drm/ttm/ttm_range_manager.h> #include <drm/ttm/ttm_range_manager.h>
#include <drm/ttm/ttm_placement.h> #include <drm/ttm/ttm_placement.h>
#include <generated/utsrelease.h> #include <generated/utsrelease.h>
......
...@@ -37,8 +37,10 @@ ...@@ -37,8 +37,10 @@
#include <drm/drm_file.h> #include <drm/drm_file.h>
#include <drm/drm_rect.h> #include <drm/drm_rect.h>
#include <drm/ttm/ttm_bo_driver.h>
#include <drm/ttm/ttm_execbuf_util.h> #include <drm/ttm/ttm_execbuf_util.h>
#include <drm/ttm/ttm_tt.h>
#include <drm/ttm/ttm_placement.h>
#include <drm/ttm/ttm_bo.h>
#include "ttm_object.h" #include "ttm_object.h"
......
...@@ -29,7 +29,7 @@ ...@@ -29,7 +29,7 @@
#include "vmwgfx_drv.h" #include "vmwgfx_drv.h"
#include "vmwgfx_reg.h" #include "vmwgfx_reg.h"
#include <drm/ttm/ttm_bo_api.h> #include <drm/ttm/ttm_bo.h>
#include <drm/ttm/ttm_placement.h> #include <drm/ttm/ttm_placement.h>
#include "vmwgfx_so.h" #include "vmwgfx_so.h"
#include "vmwgfx_binding.h" #include "vmwgfx_binding.h"
......
...@@ -25,7 +25,6 @@ ...@@ -25,7 +25,6 @@
* *
**************************************************************************/ **************************************************************************/
#include <drm/ttm/ttm_bo_driver.h>
#include "vmwgfx_drv.h" #include "vmwgfx_drv.h"
......
...@@ -29,7 +29,6 @@ ...@@ -29,7 +29,6 @@
*/ */
#include "vmwgfx_drv.h" #include "vmwgfx_drv.h"
#include <drm/ttm/ttm_bo_driver.h>
#include <drm/ttm/ttm_placement.h> #include <drm/ttm/ttm_placement.h>
#include <linux/idr.h> #include <linux/idr.h>
#include <linux/spinlock.h> #include <linux/spinlock.h>
......
...@@ -26,7 +26,6 @@ ...@@ -26,7 +26,6 @@
#include "vmwgfx_drv.h" #include "vmwgfx_drv.h"
#include <drm/ttm/ttm_bo_driver.h>
#include <drm/ttm/ttm_device.h> #include <drm/ttm/ttm_device.h>
#include <drm/ttm/ttm_placement.h> #include <drm/ttm/ttm_placement.h>
#include <drm/ttm/ttm_resource.h> #include <drm/ttm/ttm_resource.h>
......
...@@ -26,7 +26,6 @@ ...@@ -26,7 +26,6 @@
**************************************************************************/ **************************************************************************/
#include "vmwgfx_drv.h" #include "vmwgfx_drv.h"
#include <drm/ttm/ttm_bo_driver.h>
#include <drm/ttm/ttm_placement.h> #include <drm/ttm/ttm_placement.h>
static const struct ttm_place vram_placement_flags = { static const struct ttm_place vram_placement_flags = {
......
...@@ -7,8 +7,7 @@ ...@@ -7,8 +7,7 @@
#include <drm/drm_device.h> #include <drm/drm_device.h>
#include <drm/drm_gem.h> #include <drm/drm_gem.h>
#include <drm/ttm/ttm_bo_api.h> #include <drm/ttm/ttm_bo.h>
#include <drm/ttm/ttm_bo_driver.h>
struct iosys_map; struct iosys_map;
......
...@@ -8,8 +8,8 @@ ...@@ -8,8 +8,8 @@
#include <drm/drm_gem_ttm_helper.h> #include <drm/drm_gem_ttm_helper.h>
#include <drm/drm_ioctl.h> #include <drm/drm_ioctl.h>
#include <drm/drm_modes.h> #include <drm/drm_modes.h>
#include <drm/ttm/ttm_bo_api.h> #include <drm/ttm/ttm_bo.h>
#include <drm/ttm/ttm_bo_driver.h> #include <drm/ttm/ttm_placement.h>
#include <linux/container_of.h> #include <linux/container_of.h>
#include <linux/iosys-map.h> #include <linux/iosys-map.h>
......
/**************************************************************************
*
* Copyright (c) 2006-2009 Vmware, Inc., Palo Alto, CA., USA
* All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sub license, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice (including the
* next paragraph) shall be included in all copies or substantial portions
* of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
* THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
* USE OR OTHER DEALINGS IN THE SOFTWARE.
*
**************************************************************************/
/*
* Authors: Thomas Hellstrom <thellstrom-at-vmware-dot-com>
*/
#ifndef _TTM_BO_DRIVER_H_
#define _TTM_BO_DRIVER_H_
#include <drm/drm_mm.h>
#include <drm/drm_vma_manager.h>
#include <linux/workqueue.h>
#include <linux/fs.h>
#include <linux/spinlock.h>
#include <linux/dma-resv.h>
#include <drm/ttm/ttm_device.h>
#include "ttm_bo_api.h"
#include "ttm_kmap_iter.h"
#include "ttm_placement.h"
#include "ttm_tt.h"
#include "ttm_pool.h"
/*
* ttm_bo.c
*/
/**
* ttm_bo_mem_space
*
* @bo: Pointer to a struct ttm_buffer_object. the data of which
* we want to allocate space for.
* @proposed_placement: Proposed new placement for the buffer object.
* @mem: A struct ttm_resource.
* @interruptible: Sleep interruptible when sliping.
* @no_wait_gpu: Return immediately if the GPU is busy.
*
* Allocate memory space for the buffer object pointed to by @bo, using
* the placement flags in @mem, potentially evicting other idle buffer objects.
* This function may sleep while waiting for space to become available.
* Returns:
* -EBUSY: No space available (only if no_wait == 1).
* -ENOMEM: Could not allocate memory for the buffer object, either due to
* fragmentation or concurrent allocators.
* -ERESTARTSYS: An interruptible sleep was interrupted by a signal.
*/
int ttm_bo_mem_space(struct ttm_buffer_object *bo,
struct ttm_placement *placement,
struct ttm_resource **mem,
struct ttm_operation_ctx *ctx);
/**
* ttm_bo_unmap_virtual
*
* @bo: tear down the virtual mappings for this BO
*/
void ttm_bo_unmap_virtual(struct ttm_buffer_object *bo);
/**
* ttm_bo_reserve:
*
* @bo: A pointer to a struct ttm_buffer_object.
* @interruptible: Sleep interruptible if waiting.
* @no_wait: Don't sleep while trying to reserve, rather return -EBUSY.
* @ticket: ticket used to acquire the ww_mutex.
*
* Locks a buffer object for validation. (Or prevents other processes from
* locking it for validation), while taking a number of measures to prevent
* deadlocks.
*
* Returns:
* -EDEADLK: The reservation may cause a deadlock.
* Release all buffer reservations, wait for @bo to become unreserved and
* try again.
* -ERESTARTSYS: A wait for the buffer to become unreserved was interrupted by
* a signal. Release all buffer reservations and return to user-space.
* -EBUSY: The function needed to sleep, but @no_wait was true
* -EALREADY: Bo already reserved using @ticket. This error code will only
* be returned if @use_ticket is set to true.
*/
static inline int ttm_bo_reserve(struct ttm_buffer_object *bo,
bool interruptible, bool no_wait,
struct ww_acquire_ctx *ticket)
{
int ret;
if (no_wait) {
bool success;
if (WARN_ON(ticket))
return -EBUSY;
success = dma_resv_trylock(bo->base.resv);
return success ? 0 : -EBUSY;
}
if (interruptible)
ret = dma_resv_lock_interruptible(bo->base.resv, ticket);
else
ret = dma_resv_lock(bo->base.resv, ticket);
if (ret == -EINTR)
return -ERESTARTSYS;
return ret;
}
/**
* ttm_bo_reserve_slowpath:
* @bo: A pointer to a struct ttm_buffer_object.
* @interruptible: Sleep interruptible if waiting.
* @sequence: Set (@bo)->sequence to this value after lock
*
* This is called after ttm_bo_reserve returns -EAGAIN and we backed off
* from all our other reservations. Because there are no other reservations
* held by us, this function cannot deadlock any more.
*/
static inline int ttm_bo_reserve_slowpath(struct ttm_buffer_object *bo,
bool interruptible,
struct ww_acquire_ctx *ticket)
{
if (interruptible) {
int ret = dma_resv_lock_slow_interruptible(bo->base.resv,
ticket);
if (ret == -EINTR)
ret = -ERESTARTSYS;
return ret;
}
dma_resv_lock_slow(bo->base.resv, ticket);
return 0;
}
static inline void
ttm_bo_move_to_lru_tail_unlocked(struct ttm_buffer_object *bo)
{
spin_lock(&bo->bdev->lru_lock);
ttm_bo_move_to_lru_tail(bo);
spin_unlock(&bo->bdev->lru_lock);
}
static inline void ttm_bo_assign_mem(struct ttm_buffer_object *bo,
struct ttm_resource *new_mem)
{
WARN_ON(bo->resource);
bo->resource = new_mem;
}
/**
* ttm_bo_move_null = assign memory for a buffer object.
* @bo: The bo to assign the memory to
* @new_mem: The memory to be assigned.
*
* Assign the memory from new_mem to the memory of the buffer object bo.
*/
static inline void ttm_bo_move_null(struct ttm_buffer_object *bo,
struct ttm_resource *new_mem)
{
ttm_resource_free(bo, &bo->resource);
ttm_bo_assign_mem(bo, new_mem);
}
/**
* ttm_bo_unreserve
*
* @bo: A pointer to a struct ttm_buffer_object.
*
* Unreserve a previous reservation of @bo.
*/
static inline void ttm_bo_unreserve(struct ttm_buffer_object *bo)
{
ttm_bo_move_to_lru_tail_unlocked(bo);
dma_resv_unlock(bo->base.resv);
}
/*
* ttm_bo_util.c
*/
int ttm_mem_io_reserve(struct ttm_device *bdev,
struct ttm_resource *mem);
void ttm_mem_io_free(struct ttm_device *bdev,
struct ttm_resource *mem);
/**
* ttm_bo_move_memcpy
*
* @bo: A pointer to a struct ttm_buffer_object.
* @interruptible: Sleep interruptible if waiting.
* @no_wait_gpu: Return immediately if the GPU is busy.
* @new_mem: struct ttm_resource indicating where to move.
*
* Fallback move function for a mappable buffer object in mappable memory.
* The function will, if successful,
* free any old aperture space, and set (@new_mem)->mm_node to NULL,
* and update the (@bo)->mem placement flags. If unsuccessful, the old
* data remains untouched, and it's up to the caller to free the
* memory space indicated by @new_mem.
* Returns:
* !0: Failure.
*/
int ttm_bo_move_memcpy(struct ttm_buffer_object *bo,
struct ttm_operation_ctx *ctx,
struct ttm_resource *new_mem);
/**
* ttm_bo_move_accel_cleanup.
*
* @bo: A pointer to a struct ttm_buffer_object.
* @fence: A fence object that signals when moving is complete.
* @evict: This is an evict move. Don't return until the buffer is idle.
* @pipeline: evictions are to be pipelined.
* @new_mem: struct ttm_resource indicating where to move.
*
* Accelerated move function to be called when an accelerated move
* has been scheduled. The function will create a new temporary buffer object
* representing the old placement, and put the sync object on both buffer
* objects. After that the newly created buffer object is unref'd to be
* destroyed when the move is complete. This will help pipeline
* buffer moves.
*/
int ttm_bo_move_accel_cleanup(struct ttm_buffer_object *bo,
struct dma_fence *fence, bool evict,
bool pipeline,
struct ttm_resource *new_mem);
/**
* ttm_bo_move_sync_cleanup.
*
* @bo: A pointer to a struct ttm_buffer_object.
* @new_mem: struct ttm_resource indicating where to move.
*
* Special case of ttm_bo_move_accel_cleanup where the bo is guaranteed
* by the caller to be idle. Typically used after memcpy buffer moves.
*/
void ttm_bo_move_sync_cleanup(struct ttm_buffer_object *bo,
struct ttm_resource *new_mem);
/**
* ttm_bo_pipeline_gutting.
*
* @bo: A pointer to a struct ttm_buffer_object.
*
* Pipelined gutting a BO of its backing store.
*/
int ttm_bo_pipeline_gutting(struct ttm_buffer_object *bo);
/**
* ttm_io_prot
*
* bo: ttm buffer object
* res: ttm resource object
* @tmp: Page protection flag for a normal, cached mapping.
*
* Utility function that returns the pgprot_t that should be used for
* setting up a PTE with the caching model indicated by @c_state.
*/
pgprot_t ttm_io_prot(struct ttm_buffer_object *bo, struct ttm_resource *res,
pgprot_t tmp);
/**
* ttm_bo_tt_bind
*
* Bind the object tt to a memory resource.
*/
int ttm_bo_tt_bind(struct ttm_buffer_object *bo, struct ttm_resource *mem);
/**
* ttm_bo_tt_destroy.
*/
void ttm_bo_tt_destroy(struct ttm_buffer_object *bo);
void ttm_move_memcpy(bool clear,
u32 num_pages,
struct ttm_kmap_iter *dst_iter,
struct ttm_kmap_iter *src_iter);
struct ttm_kmap_iter *
ttm_kmap_iter_iomap_init(struct ttm_kmap_iter_iomap *iter_io,
struct io_mapping *iomap,
struct sg_table *st,
resource_size_t start);
#endif
...@@ -33,7 +33,9 @@ ...@@ -33,7 +33,9 @@
#include <linux/list.h> #include <linux/list.h>
#include "ttm_bo_api.h" struct ww_acquire_ctx;
struct dma_fence;
struct ttm_buffer_object;
/** /**
* struct ttm_validate_buffer * struct ttm_validate_buffer
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment