diff options
| -rw-r--r-- | drivers/gpu/drm/radeon/radeon_ttm.c | 21 |
1 files changed, 14 insertions, 7 deletions
diff --git a/drivers/gpu/drm/radeon/radeon_ttm.c b/drivers/gpu/drm/radeon/radeon_ttm.c index eca2ce60d440..d73ea9c04227 100644 --- a/drivers/gpu/drm/radeon/radeon_ttm.c +++ b/drivers/gpu/drm/radeon/radeon_ttm.c | |||
| @@ -675,10 +675,17 @@ static struct ttm_tt *radeon_ttm_tt_create(struct ttm_bo_device *bdev, | |||
| 675 | return >t->ttm.ttm; | 675 | return >t->ttm.ttm; |
| 676 | } | 676 | } |
| 677 | 677 | ||
| 678 | static struct radeon_ttm_tt *radeon_ttm_tt_to_gtt(struct ttm_tt *ttm) | ||
| 679 | { | ||
| 680 | if (!ttm || ttm->func != &radeon_backend_func) | ||
| 681 | return NULL; | ||
| 682 | return (struct radeon_ttm_tt *)ttm; | ||
| 683 | } | ||
| 684 | |||
| 678 | static int radeon_ttm_tt_populate(struct ttm_tt *ttm) | 685 | static int radeon_ttm_tt_populate(struct ttm_tt *ttm) |
| 679 | { | 686 | { |
| 687 | struct radeon_ttm_tt *gtt = radeon_ttm_tt_to_gtt(ttm); | ||
| 680 | struct radeon_device *rdev; | 688 | struct radeon_device *rdev; |
| 681 | struct radeon_ttm_tt *gtt = (void *)ttm; | ||
| 682 | unsigned i; | 689 | unsigned i; |
| 683 | int r; | 690 | int r; |
| 684 | bool slave = !!(ttm->page_flags & TTM_PAGE_FLAG_SG); | 691 | bool slave = !!(ttm->page_flags & TTM_PAGE_FLAG_SG); |
| @@ -686,7 +693,7 @@ static int radeon_ttm_tt_populate(struct ttm_tt *ttm) | |||
| 686 | if (ttm->state != tt_unpopulated) | 693 | if (ttm->state != tt_unpopulated) |
| 687 | return 0; | 694 | return 0; |
| 688 | 695 | ||
| 689 | if (gtt->userptr) { | 696 | if (gtt && gtt->userptr) { |
| 690 | ttm->sg = kcalloc(1, sizeof(struct sg_table), GFP_KERNEL); | 697 | ttm->sg = kcalloc(1, sizeof(struct sg_table), GFP_KERNEL); |
| 691 | if (!ttm->sg) | 698 | if (!ttm->sg) |
| 692 | return -ENOMEM; | 699 | return -ENOMEM; |
| @@ -741,11 +748,11 @@ static int radeon_ttm_tt_populate(struct ttm_tt *ttm) | |||
| 741 | static void radeon_ttm_tt_unpopulate(struct ttm_tt *ttm) | 748 | static void radeon_ttm_tt_unpopulate(struct ttm_tt *ttm) |
| 742 | { | 749 | { |
| 743 | struct radeon_device *rdev; | 750 | struct radeon_device *rdev; |
| 744 | struct radeon_ttm_tt *gtt = (void *)ttm; | 751 | struct radeon_ttm_tt *gtt = radeon_ttm_tt_to_gtt(ttm); |
| 745 | unsigned i; | 752 | unsigned i; |
| 746 | bool slave = !!(ttm->page_flags & TTM_PAGE_FLAG_SG); | 753 | bool slave = !!(ttm->page_flags & TTM_PAGE_FLAG_SG); |
| 747 | 754 | ||
| 748 | if (gtt->userptr) { | 755 | if (gtt && gtt->userptr) { |
| 749 | kfree(ttm->sg); | 756 | kfree(ttm->sg); |
| 750 | ttm->page_flags &= ~TTM_PAGE_FLAG_SG; | 757 | ttm->page_flags &= ~TTM_PAGE_FLAG_SG; |
| 751 | return; | 758 | return; |
| @@ -782,7 +789,7 @@ static void radeon_ttm_tt_unpopulate(struct ttm_tt *ttm) | |||
| 782 | int radeon_ttm_tt_set_userptr(struct ttm_tt *ttm, uint64_t addr, | 789 | int radeon_ttm_tt_set_userptr(struct ttm_tt *ttm, uint64_t addr, |
| 783 | uint32_t flags) | 790 | uint32_t flags) |
| 784 | { | 791 | { |
| 785 | struct radeon_ttm_tt *gtt = (void *)ttm; | 792 | struct radeon_ttm_tt *gtt = radeon_ttm_tt_to_gtt(ttm); |
| 786 | 793 | ||
| 787 | if (gtt == NULL) | 794 | if (gtt == NULL) |
| 788 | return -EINVAL; | 795 | return -EINVAL; |
| @@ -795,7 +802,7 @@ int radeon_ttm_tt_set_userptr(struct ttm_tt *ttm, uint64_t addr, | |||
| 795 | 802 | ||
| 796 | bool radeon_ttm_tt_has_userptr(struct ttm_tt *ttm) | 803 | bool radeon_ttm_tt_has_userptr(struct ttm_tt *ttm) |
| 797 | { | 804 | { |
| 798 | struct radeon_ttm_tt *gtt = (void *)ttm; | 805 | struct radeon_ttm_tt *gtt = radeon_ttm_tt_to_gtt(ttm); |
| 799 | 806 | ||
| 800 | if (gtt == NULL) | 807 | if (gtt == NULL) |
| 801 | return false; | 808 | return false; |
| @@ -805,7 +812,7 @@ bool radeon_ttm_tt_has_userptr(struct ttm_tt *ttm) | |||
| 805 | 812 | ||
| 806 | bool radeon_ttm_tt_is_readonly(struct ttm_tt *ttm) | 813 | bool radeon_ttm_tt_is_readonly(struct ttm_tt *ttm) |
| 807 | { | 814 | { |
| 808 | struct radeon_ttm_tt *gtt = (void *)ttm; | 815 | struct radeon_ttm_tt *gtt = radeon_ttm_tt_to_gtt(ttm); |
| 809 | 816 | ||
| 810 | if (gtt == NULL) | 817 | if (gtt == NULL) |
| 811 | return false; | 818 | return false; |
