Commit a68bb193 authored by Dave Airlie's avatar Dave Airlie

drm/radeon/ttm: move to driver binding/destroy functions. (v2)

Do agp decision in the driver, instead of special binding funcs

v2: use container_of, drop some {}.
Reviewed-by: default avatarChristian König <christian.koenig@amd.com>
Signed-off-by: default avatarDave Airlie <airlied@redhat.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20200907204630.1406528-6-airlied@gmail.com
parent 738edc0a
...@@ -2815,10 +2815,11 @@ extern void radeon_legacy_set_clock_gating(struct radeon_device *rdev, int enabl ...@@ -2815,10 +2815,11 @@ extern void radeon_legacy_set_clock_gating(struct radeon_device *rdev, int enabl
extern void radeon_atom_set_clock_gating(struct radeon_device *rdev, int enable); extern void radeon_atom_set_clock_gating(struct radeon_device *rdev, int enable);
extern void radeon_ttm_placement_from_domain(struct radeon_bo *rbo, u32 domain); extern void radeon_ttm_placement_from_domain(struct radeon_bo *rbo, u32 domain);
extern bool radeon_ttm_bo_is_radeon_bo(struct ttm_buffer_object *bo); extern bool radeon_ttm_bo_is_radeon_bo(struct ttm_buffer_object *bo);
extern int radeon_ttm_tt_set_userptr(struct ttm_tt *ttm, uint64_t addr, extern int radeon_ttm_tt_set_userptr(struct radeon_device *rdev,
struct ttm_tt *ttm, uint64_t addr,
uint32_t flags); uint32_t flags);
extern bool radeon_ttm_tt_has_userptr(struct ttm_tt *ttm); extern bool radeon_ttm_tt_has_userptr(struct radeon_device *rdev, struct ttm_tt *ttm);
extern bool radeon_ttm_tt_is_readonly(struct ttm_tt *ttm); extern bool radeon_ttm_tt_is_readonly(struct radeon_device *rdev, struct ttm_tt *ttm);
extern void radeon_vram_location(struct radeon_device *rdev, struct radeon_mc *mc, u64 base); extern void radeon_vram_location(struct radeon_device *rdev, struct radeon_mc *mc, u64 base);
extern void radeon_gtt_location(struct radeon_device *rdev, struct radeon_mc *mc); extern void radeon_gtt_location(struct radeon_device *rdev, struct radeon_mc *mc);
extern int radeon_resume_kms(struct drm_device *dev, bool resume, bool fbcon); extern int radeon_resume_kms(struct drm_device *dev, bool resume, bool fbcon);
......
...@@ -160,7 +160,7 @@ static int radeon_cs_parser_relocs(struct radeon_cs_parser *p) ...@@ -160,7 +160,7 @@ static int radeon_cs_parser_relocs(struct radeon_cs_parser *p)
p->relocs[i].allowed_domains = domain; p->relocs[i].allowed_domains = domain;
} }
if (radeon_ttm_tt_has_userptr(p->relocs[i].robj->tbo.ttm)) { if (radeon_ttm_tt_has_userptr(p->rdev, p->relocs[i].robj->tbo.ttm)) {
uint32_t domain = p->relocs[i].preferred_domains; uint32_t domain = p->relocs[i].preferred_domains;
if (!(domain & RADEON_GEM_DOMAIN_GTT)) { if (!(domain & RADEON_GEM_DOMAIN_GTT)) {
DRM_ERROR("Only RADEON_GEM_DOMAIN_GTT is " DRM_ERROR("Only RADEON_GEM_DOMAIN_GTT is "
......
...@@ -331,7 +331,7 @@ int radeon_gem_userptr_ioctl(struct drm_device *dev, void *data, ...@@ -331,7 +331,7 @@ int radeon_gem_userptr_ioctl(struct drm_device *dev, void *data,
goto handle_lockup; goto handle_lockup;
bo = gem_to_radeon_bo(gobj); bo = gem_to_radeon_bo(gobj);
r = radeon_ttm_tt_set_userptr(bo->tbo.ttm, args->addr, args->flags); r = radeon_ttm_tt_set_userptr(rdev, bo->tbo.ttm, args->addr, args->flags);
if (r) if (r)
goto release_object; goto release_object;
...@@ -420,7 +420,7 @@ int radeon_mode_dumb_mmap(struct drm_file *filp, ...@@ -420,7 +420,7 @@ int radeon_mode_dumb_mmap(struct drm_file *filp,
return -ENOENT; return -ENOENT;
} }
robj = gem_to_radeon_bo(gobj); robj = gem_to_radeon_bo(gobj);
if (radeon_ttm_tt_has_userptr(robj->tbo.ttm)) { if (radeon_ttm_tt_has_userptr(robj->rdev, robj->tbo.ttm)) {
drm_gem_object_put(gobj); drm_gem_object_put(gobj);
return -EPERM; return -EPERM;
} }
...@@ -721,7 +721,7 @@ int radeon_gem_op_ioctl(struct drm_device *dev, void *data, ...@@ -721,7 +721,7 @@ int radeon_gem_op_ioctl(struct drm_device *dev, void *data,
robj = gem_to_radeon_bo(gobj); robj = gem_to_radeon_bo(gobj);
r = -EPERM; r = -EPERM;
if (radeon_ttm_tt_has_userptr(robj->tbo.ttm)) if (radeon_ttm_tt_has_userptr(robj->rdev, robj->tbo.ttm))
goto out; goto out;
r = radeon_bo_reserve(robj, false); r = radeon_bo_reserve(robj, false);
......
...@@ -331,7 +331,7 @@ int radeon_bo_pin_restricted(struct radeon_bo *bo, u32 domain, u64 max_offset, ...@@ -331,7 +331,7 @@ int radeon_bo_pin_restricted(struct radeon_bo *bo, u32 domain, u64 max_offset,
struct ttm_operation_ctx ctx = { false, false }; struct ttm_operation_ctx ctx = { false, false };
int r, i; int r, i;
if (radeon_ttm_tt_has_userptr(bo->tbo.ttm)) if (radeon_ttm_tt_has_userptr(bo->rdev, bo->tbo.ttm))
return -EPERM; return -EPERM;
if (bo->pin_count) { if (bo->pin_count) {
......
...@@ -121,7 +121,7 @@ struct dma_buf *radeon_gem_prime_export(struct drm_gem_object *gobj, ...@@ -121,7 +121,7 @@ struct dma_buf *radeon_gem_prime_export(struct drm_gem_object *gobj,
int flags) int flags)
{ {
struct radeon_bo *bo = gem_to_radeon_bo(gobj); struct radeon_bo *bo = gem_to_radeon_bo(gobj);
if (radeon_ttm_tt_has_userptr(bo->tbo.ttm)) if (radeon_ttm_tt_has_userptr(bo->rdev, bo->tbo.ttm))
return ERR_PTR(-EPERM); return ERR_PTR(-EPERM);
return drm_gem_prime_export(gobj, flags); return drm_gem_prime_export(gobj, flags);
} }
...@@ -141,8 +141,9 @@ static void radeon_evict_flags(struct ttm_buffer_object *bo, ...@@ -141,8 +141,9 @@ static void radeon_evict_flags(struct ttm_buffer_object *bo,
static int radeon_verify_access(struct ttm_buffer_object *bo, struct file *filp) static int radeon_verify_access(struct ttm_buffer_object *bo, struct file *filp)
{ {
struct radeon_bo *rbo = container_of(bo, struct radeon_bo, tbo); struct radeon_bo *rbo = container_of(bo, struct radeon_bo, tbo);
struct radeon_device *rdev = radeon_get_rdev(bo->bdev);
if (radeon_ttm_tt_has_userptr(bo->ttm)) if (radeon_ttm_tt_has_userptr(rdev, bo->ttm))
return -EPERM; return -EPERM;
return drm_vma_node_verify_access(&rbo->tbo.base.vma_node, return drm_vma_node_verify_access(&rbo->tbo.base.vma_node,
filp->private_data); filp->private_data);
...@@ -559,12 +560,6 @@ static void radeon_ttm_backend_destroy(struct ttm_bo_device *bdev, struct ttm_tt ...@@ -559,12 +560,6 @@ static void radeon_ttm_backend_destroy(struct ttm_bo_device *bdev, struct ttm_tt
kfree(gtt); kfree(gtt);
} }
static struct ttm_backend_func radeon_backend_func = {
.bind = &radeon_ttm_backend_bind,
.unbind = &radeon_ttm_backend_unbind,
.destroy = &radeon_ttm_backend_destroy,
};
static struct ttm_tt *radeon_ttm_tt_create(struct ttm_buffer_object *bo, static struct ttm_tt *radeon_ttm_tt_create(struct ttm_buffer_object *bo,
uint32_t page_flags) uint32_t page_flags)
{ {
...@@ -583,7 +578,6 @@ static struct ttm_tt *radeon_ttm_tt_create(struct ttm_buffer_object *bo, ...@@ -583,7 +578,6 @@ static struct ttm_tt *radeon_ttm_tt_create(struct ttm_buffer_object *bo,
if (gtt == NULL) { if (gtt == NULL) {
return NULL; return NULL;
} }
gtt->ttm.ttm.func = &radeon_backend_func;
if (ttm_dma_tt_init(&gtt->ttm, bo, page_flags)) { if (ttm_dma_tt_init(&gtt->ttm, bo, page_flags)) {
kfree(gtt); kfree(gtt);
return NULL; return NULL;
...@@ -591,19 +585,25 @@ static struct ttm_tt *radeon_ttm_tt_create(struct ttm_buffer_object *bo, ...@@ -591,19 +585,25 @@ static struct ttm_tt *radeon_ttm_tt_create(struct ttm_buffer_object *bo,
return &gtt->ttm.ttm; return &gtt->ttm.ttm;
} }
static struct radeon_ttm_tt *radeon_ttm_tt_to_gtt(struct ttm_tt *ttm) static struct radeon_ttm_tt *radeon_ttm_tt_to_gtt(struct radeon_device *rdev,
struct ttm_tt *ttm)
{ {
if (!ttm || ttm->func != &radeon_backend_func) #if IS_ENABLED(CONFIG_AGP)
if (rdev->flags & RADEON_IS_AGP)
return NULL;
#endif
if (!ttm)
return NULL; return NULL;
return (struct radeon_ttm_tt *)ttm; return container_of(ttm, struct radeon_ttm_tt, ttm.ttm);
} }
static int radeon_ttm_tt_populate(struct ttm_bo_device *bdev, static int radeon_ttm_tt_populate(struct ttm_bo_device *bdev,
struct ttm_tt *ttm, struct ttm_tt *ttm,
struct ttm_operation_ctx *ctx) struct ttm_operation_ctx *ctx)
{ {
struct radeon_ttm_tt *gtt = radeon_ttm_tt_to_gtt(ttm); struct radeon_device *rdev = radeon_get_rdev(bdev);
struct radeon_device *rdev; struct radeon_ttm_tt *gtt = radeon_ttm_tt_to_gtt(rdev, ttm);
bool slave = !!(ttm->page_flags & TTM_PAGE_FLAG_SG); bool slave = !!(ttm->page_flags & TTM_PAGE_FLAG_SG);
if (gtt && gtt->userptr) { if (gtt && gtt->userptr) {
...@@ -623,7 +623,6 @@ static int radeon_ttm_tt_populate(struct ttm_bo_device *bdev, ...@@ -623,7 +623,6 @@ static int radeon_ttm_tt_populate(struct ttm_bo_device *bdev,
return 0; return 0;
} }
rdev = radeon_get_rdev(bdev);
#if IS_ENABLED(CONFIG_AGP) #if IS_ENABLED(CONFIG_AGP)
if (rdev->flags & RADEON_IS_AGP) { if (rdev->flags & RADEON_IS_AGP) {
return ttm_agp_tt_populate(bdev, ttm, ctx); return ttm_agp_tt_populate(bdev, ttm, ctx);
...@@ -641,8 +640,8 @@ static int radeon_ttm_tt_populate(struct ttm_bo_device *bdev, ...@@ -641,8 +640,8 @@ static int radeon_ttm_tt_populate(struct ttm_bo_device *bdev,
static void radeon_ttm_tt_unpopulate(struct ttm_bo_device *bdev, struct ttm_tt *ttm) static void radeon_ttm_tt_unpopulate(struct ttm_bo_device *bdev, struct ttm_tt *ttm)
{ {
struct radeon_device *rdev; struct radeon_device *rdev = radeon_get_rdev(bdev);
struct radeon_ttm_tt *gtt = radeon_ttm_tt_to_gtt(ttm); struct radeon_ttm_tt *gtt = radeon_ttm_tt_to_gtt(rdev, ttm);
bool slave = !!(ttm->page_flags & TTM_PAGE_FLAG_SG); bool slave = !!(ttm->page_flags & TTM_PAGE_FLAG_SG);
if (gtt && gtt->userptr) { if (gtt && gtt->userptr) {
...@@ -654,7 +653,6 @@ static void radeon_ttm_tt_unpopulate(struct ttm_bo_device *bdev, struct ttm_tt * ...@@ -654,7 +653,6 @@ static void radeon_ttm_tt_unpopulate(struct ttm_bo_device *bdev, struct ttm_tt *
if (slave) if (slave)
return; return;
rdev = radeon_get_rdev(bdev);
#if IS_ENABLED(CONFIG_AGP) #if IS_ENABLED(CONFIG_AGP)
if (rdev->flags & RADEON_IS_AGP) { if (rdev->flags & RADEON_IS_AGP) {
ttm_agp_tt_unpopulate(bdev, ttm); ttm_agp_tt_unpopulate(bdev, ttm);
...@@ -672,10 +670,11 @@ static void radeon_ttm_tt_unpopulate(struct ttm_bo_device *bdev, struct ttm_tt * ...@@ -672,10 +670,11 @@ static void radeon_ttm_tt_unpopulate(struct ttm_bo_device *bdev, struct ttm_tt *
ttm_unmap_and_unpopulate_pages(rdev->dev, &gtt->ttm); ttm_unmap_and_unpopulate_pages(rdev->dev, &gtt->ttm);
} }
int radeon_ttm_tt_set_userptr(struct ttm_tt *ttm, uint64_t addr, int radeon_ttm_tt_set_userptr(struct radeon_device *rdev,
struct ttm_tt *ttm, uint64_t addr,
uint32_t flags) uint32_t flags)
{ {
struct radeon_ttm_tt *gtt = radeon_ttm_tt_to_gtt(ttm); struct radeon_ttm_tt *gtt = radeon_ttm_tt_to_gtt(rdev, ttm);
if (gtt == NULL) if (gtt == NULL)
return -EINVAL; return -EINVAL;
...@@ -686,9 +685,52 @@ int radeon_ttm_tt_set_userptr(struct ttm_tt *ttm, uint64_t addr, ...@@ -686,9 +685,52 @@ int radeon_ttm_tt_set_userptr(struct ttm_tt *ttm, uint64_t addr,
return 0; return 0;
} }
bool radeon_ttm_tt_has_userptr(struct ttm_tt *ttm) static int radeon_ttm_tt_bind(struct ttm_bo_device *bdev,
struct ttm_tt *ttm,
struct ttm_resource *bo_mem)
{
struct radeon_device *rdev = radeon_get_rdev(bdev);
#if IS_ENABLED(CONFIG_AGP)
if (rdev->flags & RADEON_IS_AGP)
return ttm_agp_bind(bdev, ttm, bo_mem);
#endif
return radeon_ttm_backend_bind(bdev, ttm, bo_mem);
}
static void radeon_ttm_tt_unbind(struct ttm_bo_device *bdev,
struct ttm_tt *ttm)
{
#if IS_ENABLED(CONFIG_AGP)
struct radeon_device *rdev = radeon_get_rdev(bdev);
if (rdev->flags & RADEON_IS_AGP) {
ttm_agp_unbind(bdev, ttm);
return;
}
#endif
radeon_ttm_backend_unbind(bdev, ttm);
}
static void radeon_ttm_tt_destroy(struct ttm_bo_device *bdev,
struct ttm_tt *ttm)
{
#if IS_ENABLED(CONFIG_AGP)
struct radeon_device *rdev = radeon_get_rdev(bdev);
if (rdev->flags & RADEON_IS_AGP) {
ttm_agp_destroy(bdev, ttm);
return;
}
#endif
radeon_ttm_backend_destroy(bdev, ttm);
}
bool radeon_ttm_tt_has_userptr(struct radeon_device *rdev,
struct ttm_tt *ttm)
{ {
struct radeon_ttm_tt *gtt = radeon_ttm_tt_to_gtt(ttm); struct radeon_ttm_tt *gtt = radeon_ttm_tt_to_gtt(rdev, ttm);
if (gtt == NULL) if (gtt == NULL)
return false; return false;
...@@ -696,9 +738,10 @@ bool radeon_ttm_tt_has_userptr(struct ttm_tt *ttm) ...@@ -696,9 +738,10 @@ bool radeon_ttm_tt_has_userptr(struct ttm_tt *ttm)
return !!gtt->userptr; return !!gtt->userptr;
} }
bool radeon_ttm_tt_is_readonly(struct ttm_tt *ttm) bool radeon_ttm_tt_is_readonly(struct radeon_device *rdev,
struct ttm_tt *ttm)
{ {
struct radeon_ttm_tt *gtt = radeon_ttm_tt_to_gtt(ttm); struct radeon_ttm_tt *gtt = radeon_ttm_tt_to_gtt(rdev, ttm);
if (gtt == NULL) if (gtt == NULL)
return false; return false;
...@@ -710,6 +753,9 @@ static struct ttm_bo_driver radeon_bo_driver = { ...@@ -710,6 +753,9 @@ static struct ttm_bo_driver radeon_bo_driver = {
.ttm_tt_create = &radeon_ttm_tt_create, .ttm_tt_create = &radeon_ttm_tt_create,
.ttm_tt_populate = &radeon_ttm_tt_populate, .ttm_tt_populate = &radeon_ttm_tt_populate,
.ttm_tt_unpopulate = &radeon_ttm_tt_unpopulate, .ttm_tt_unpopulate = &radeon_ttm_tt_unpopulate,
.ttm_tt_bind = &radeon_ttm_tt_bind,
.ttm_tt_unbind = &radeon_ttm_tt_unbind,
.ttm_tt_destroy = &radeon_ttm_tt_destroy,
.eviction_valuable = ttm_bo_eviction_valuable, .eviction_valuable = ttm_bo_eviction_valuable,
.evict_flags = &radeon_evict_flags, .evict_flags = &radeon_evict_flags,
.move = &radeon_bo_move, .move = &radeon_bo_move,
......
...@@ -942,7 +942,7 @@ int radeon_vm_bo_update(struct radeon_device *rdev, ...@@ -942,7 +942,7 @@ int radeon_vm_bo_update(struct radeon_device *rdev,
bo_va->flags &= ~RADEON_VM_PAGE_VALID; bo_va->flags &= ~RADEON_VM_PAGE_VALID;
bo_va->flags &= ~RADEON_VM_PAGE_SYSTEM; bo_va->flags &= ~RADEON_VM_PAGE_SYSTEM;
bo_va->flags &= ~RADEON_VM_PAGE_SNOOPED; bo_va->flags &= ~RADEON_VM_PAGE_SNOOPED;
if (bo_va->bo && radeon_ttm_tt_is_readonly(bo_va->bo->tbo.ttm)) if (bo_va->bo && radeon_ttm_tt_is_readonly(rdev, bo_va->bo->tbo.ttm))
bo_va->flags &= ~RADEON_VM_PAGE_WRITEABLE; bo_va->flags &= ~RADEON_VM_PAGE_WRITEABLE;
if (mem) { if (mem) {
......
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