drm/radeon: fix AGP userptr handling
Subsystems (2)
PATCH 1/1 drm/radeon: fix AGP userptr handling
From: Christian König <[email protected]>
AGP mappings are not cache coherent, so userptr support won't work. Additional to that the AGP implementation uses a different ttm_tt container structure so we run into problems if we cast the pointer without checking if it's the right type.
--- drivers/gpu/drm/radeon/radeon_ttm.c | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-)
drivers/gpu/drm/radeon/radeon_ttm.c +14 -7
@@ -675,10 +675,17 @@ static struct ttm_tt *radeon_ttm_tt_create(struct ttm_bo_device *bdev,return >t->ttm.ttm; } +static struct radeon_ttm_tt *radeon_ttm_tt_to_gtt (struct ttm_tt *ttm) +{ +if (!ttm || ttm->func != &radeon_backend_func) +return NULL ; +return (struct radeon_ttm_tt *)ttm; +} +static int radeon_ttm_tt_populate (struct ttm_tt *ttm) { +struct radeon_ttm_tt *gtt =radeon_ttm_tt_to_gtt (ttm);struct radeon_device *rdev; -struct radeon_ttm_tt *gtt = (void *)ttm;unsigned i;int r;bool slave = !!(ttm->page_flags &TTM_PAGE_FLAG_SG );
@@ -686,7 +693,7 @@ static int radeon_ttm_tt_populate(struct ttm_tt *ttm)if (ttm->state != tt_unpopulated)return 0 ; -if (gtt->userptr) { +if (gtt && gtt->userptr) { ttm->sg =kcalloc (1 ,sizeof (struct sg_table ),GFP_KERNEL );if (!ttm->sg)return -ENOMEM ;
@@ -741,11 +748,11 @@ static int radeon_ttm_tt_populate(struct ttm_tt *ttm)static void radeon_ttm_tt_unpopulate (struct ttm_tt *ttm) {struct radeon_device *rdev; -struct radeon_ttm_tt *gtt = (void *)ttm; +struct radeon_ttm_tt *gtt =radeon_ttm_tt_to_gtt (ttm);unsigned i;bool slave = !!(ttm->page_flags &TTM_PAGE_FLAG_SG ); -if (gtt->userptr) { +if (gtt && gtt->userptr) {kfree (ttm->sg); ttm->page_flags &= ~TTM_PAGE_FLAG_SG ;return ;
@@ -782,7 +789,7 @@ static void radeon_ttm_tt_unpopulate(struct ttm_tt *ttm)int radeon_ttm_tt_set_userptr (struct ttm_tt *ttm,uint64_t addr,uint32_t flags) { -struct radeon_ttm_tt *gtt = (void *)ttm; +struct radeon_ttm_tt *gtt =radeon_ttm_tt_to_gtt (ttm);if (gtt ==NULL )return -EINVAL ;
@@ -795,7 +802,7 @@ int radeon_ttm_tt_set_userptr(struct ttm_tt *ttm, uint64_t addr,bool radeon_ttm_tt_has_userptr (struct ttm_tt *ttm) { -struct radeon_ttm_tt *gtt = (void *)ttm; +struct radeon_ttm_tt *gtt =radeon_ttm_tt_to_gtt (ttm);if (gtt ==NULL )return false;
@@ -805,7 +812,7 @@ bool radeon_ttm_tt_has_userptr(struct ttm_tt *ttm)bool radeon_ttm_tt_is_readonly (struct ttm_tt *ttm) { -struct radeon_ttm_tt *gtt = (void *)ttm; +struct radeon_ttm_tt *gtt =radeon_ttm_tt_to_gtt (ttm);if (gtt ==NULL )return false;
Signature · 6 lines
1.8.3.2 _______________________________________________ dri-devel mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/dri-devel
Alex Deucher
AppliedQuoted 9 lines · Christian König
From: Christian König <[email protected]>
AGP mappings are not cache coherent, so userptr support won't work. Additional to that the AGP implementation uses a different
ttm_ttcontainer structure so we run into problems if we cast the pointer without checking if it's the right type.Signed-off-by Christian König <[email protected]>
Applied to my 3.18 tree. thanks!
Alex
Quoted 78 lines
--- drivers/gpu/drm/radeon/radeon_ttm.c | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-)drivers/gpu/drm/radeon/radeon_ttm.c +14
-8@@ -675,10 +675,17 @@ static struct ttm_tt *radeon_ttm_tt_create(struct ttm_bo_device *bdev,return >t->ttm.ttm; } +static struct radeon_ttm_tt *radeon_ttm_tt_to_gtt (struct ttm_tt *ttm) +{ +if (!ttm || ttm->func != &radeon_backend_func) +return NULL ; +return (struct radeon_ttm_tt *)ttm; +} +static int radeon_ttm_tt_populate (struct ttm_tt *ttm) { +struct radeon_ttm_tt *gtt =radeon_ttm_tt_to_gtt (ttm);struct radeon_device *rdev; -struct radeon_ttm_tt *gtt = (void *)ttm;unsigned i;int r;bool slave = !!(ttm->page_flags &TTM_PAGE_FLAG_SG );@@ -686,7 +693,7 @@ static int radeon_ttm_tt_populate(struct ttm_tt *ttm)if (ttm->state != tt_unpopulated)return 0 ; -if (gtt->userptr) { +if (gtt && gtt->userptr) { ttm->sg =kcalloc (1 ,sizeof (struct sg_table ),GFP_KERNEL );if (!ttm->sg)return -ENOMEM ;@@ -741,11 +748,11 @@ static int radeon_ttm_tt_populate(struct ttm_tt *ttm)static void radeon_ttm_tt_unpopulate (struct ttm_tt *ttm) {struct radeon_device *rdev; -struct radeon_ttm_tt *gtt = (void *)ttm; +struct radeon_ttm_tt *gtt =radeon_ttm_tt_to_gtt (ttm);unsigned i;bool slave = !!(ttm->page_flags &TTM_PAGE_FLAG_SG ); -if (gtt->userptr) { +if (gtt && gtt->userptr) {kfree (ttm->sg); ttm->page_flags &= ~TTM_PAGE_FLAG_SG ;return ;@@ -782,7 +789,7 @@ static void radeon_ttm_tt_unpopulate(struct ttm_tt *ttm)int radeon_ttm_tt_set_userptr (struct ttm_tt *ttm,uint64_t addr,uint32_t flags) { -struct radeon_ttm_tt *gtt = (void *)ttm; +struct radeon_ttm_tt *gtt =radeon_ttm_tt_to_gtt (ttm);if (gtt ==NULL )return -EINVAL ;@@ -795,7 +802,7 @@ int radeon_ttm_tt_set_userptr(struct ttm_tt *ttm, uint64_t addr,bool radeon_ttm_tt_has_userptr (struct ttm_tt *ttm) { -struct radeon_ttm_tt *gtt = (void *)ttm; +struct radeon_ttm_tt *gtt =radeon_ttm_tt_to_gtt (ttm);if (gtt ==NULL )return false;@@ -805,7 +812,7 @@ bool radeon_ttm_tt_has_userptr(struct ttm_tt *ttm)bool radeon_ttm_tt_is_readonly (struct ttm_tt *ttm) { -struct radeon_ttm_tt *gtt = (void *)ttm; +struct radeon_ttm_tt *gtt =radeon_ttm_tt_to_gtt (ttm);if (gtt ==NULL )return false; --
Quoted 2 lines
1.8.3.2
_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel