diff options
Diffstat (limited to 'drivers/gpu')
-rw-r--r-- | drivers/gpu/drm/radeon/radeon_drv.c | 2 | ||||
-rw-r--r-- | drivers/gpu/drm/radeon/radeon_object.c | 39 | ||||
-rw-r--r-- | drivers/gpu/drm/ttm/ttm_bo.c | 134 |
3 files changed, 71 insertions, 104 deletions
diff --git a/drivers/gpu/drm/radeon/radeon_drv.c b/drivers/gpu/drm/radeon/radeon_drv.c index 28077247f4f3..c5c45e626d74 100644 --- a/drivers/gpu/drm/radeon/radeon_drv.c +++ b/drivers/gpu/drm/radeon/radeon_drv.c | |||
@@ -121,7 +121,7 @@ module_param_named(connector_table, radeon_connector_table, int, 0444); | |||
121 | MODULE_PARM_DESC(tv, "TV enable (0 = disable)"); | 121 | MODULE_PARM_DESC(tv, "TV enable (0 = disable)"); |
122 | module_param_named(tv, radeon_tv, int, 0444); | 122 | module_param_named(tv, radeon_tv, int, 0444); |
123 | 123 | ||
124 | MODULE_PARM_DESC(r4xx_atom, "Select new PLL code for AVIVO chips"); | 124 | MODULE_PARM_DESC(new_pll, "Select new PLL code for AVIVO chips"); |
125 | module_param_named(new_pll, radeon_new_pll, int, 0444); | 125 | module_param_named(new_pll, radeon_new_pll, int, 0444); |
126 | 126 | ||
127 | static int radeon_suspend(struct drm_device *dev, pm_message_t state) | 127 | static int radeon_suspend(struct drm_device *dev, pm_message_t state) |
diff --git a/drivers/gpu/drm/radeon/radeon_object.c b/drivers/gpu/drm/radeon/radeon_object.c index 2040937682fd..544e18ffaf22 100644 --- a/drivers/gpu/drm/radeon/radeon_object.c +++ b/drivers/gpu/drm/radeon/radeon_object.c | |||
@@ -56,25 +56,6 @@ static void radeon_ttm_bo_destroy(struct ttm_buffer_object *tbo) | |||
56 | kfree(bo); | 56 | kfree(bo); |
57 | } | 57 | } |
58 | 58 | ||
59 | static inline u32 radeon_ttm_flags_from_domain(u32 domain) | ||
60 | { | ||
61 | u32 flags = 0; | ||
62 | |||
63 | if (domain & RADEON_GEM_DOMAIN_VRAM) { | ||
64 | flags |= TTM_PL_FLAG_VRAM | TTM_PL_FLAG_WC | TTM_PL_FLAG_UNCACHED; | ||
65 | } | ||
66 | if (domain & RADEON_GEM_DOMAIN_GTT) { | ||
67 | flags |= TTM_PL_FLAG_TT | TTM_PL_MASK_CACHING; | ||
68 | } | ||
69 | if (domain & RADEON_GEM_DOMAIN_CPU) { | ||
70 | flags |= TTM_PL_FLAG_SYSTEM | TTM_PL_MASK_CACHING; | ||
71 | } | ||
72 | if (!flags) { | ||
73 | flags |= TTM_PL_FLAG_SYSTEM | TTM_PL_MASK_CACHING; | ||
74 | } | ||
75 | return flags; | ||
76 | } | ||
77 | |||
78 | void radeon_ttm_placement_from_domain(struct radeon_bo *rbo, u32 domain) | 59 | void radeon_ttm_placement_from_domain(struct radeon_bo *rbo, u32 domain) |
79 | { | 60 | { |
80 | u32 c = 0; | 61 | u32 c = 0; |
@@ -100,7 +81,6 @@ int radeon_bo_create(struct radeon_device *rdev, struct drm_gem_object *gobj, | |||
100 | { | 81 | { |
101 | struct radeon_bo *bo; | 82 | struct radeon_bo *bo; |
102 | enum ttm_bo_type type; | 83 | enum ttm_bo_type type; |
103 | u32 flags; | ||
104 | int r; | 84 | int r; |
105 | 85 | ||
106 | if (unlikely(rdev->mman.bdev.dev_mapping == NULL)) { | 86 | if (unlikely(rdev->mman.bdev.dev_mapping == NULL)) { |
@@ -120,16 +100,16 @@ int radeon_bo_create(struct radeon_device *rdev, struct drm_gem_object *gobj, | |||
120 | bo->surface_reg = -1; | 100 | bo->surface_reg = -1; |
121 | INIT_LIST_HEAD(&bo->list); | 101 | INIT_LIST_HEAD(&bo->list); |
122 | 102 | ||
123 | flags = radeon_ttm_flags_from_domain(domain); | 103 | radeon_ttm_placement_from_domain(bo, domain); |
124 | /* Kernel allocation are uninterruptible */ | 104 | /* Kernel allocation are uninterruptible */ |
125 | r = ttm_buffer_object_init(&rdev->mman.bdev, &bo->tbo, size, type, | 105 | r = ttm_bo_init(&rdev->mman.bdev, &bo->tbo, size, type, |
126 | flags, 0, 0, !kernel, NULL, size, | 106 | &bo->placement, 0, 0, !kernel, NULL, size, |
127 | &radeon_ttm_bo_destroy); | 107 | &radeon_ttm_bo_destroy); |
128 | if (unlikely(r != 0)) { | 108 | if (unlikely(r != 0)) { |
129 | if (r != -ERESTARTSYS) | 109 | if (r != -ERESTARTSYS) |
130 | dev_err(rdev->dev, | 110 | dev_err(rdev->dev, |
131 | "object_init failed for (%ld, 0x%08X)\n", | 111 | "object_init failed for (%lu, 0x%08X)\n", |
132 | size, flags); | 112 | size, domain); |
133 | return r; | 113 | return r; |
134 | } | 114 | } |
135 | *bo_ptr = bo; | 115 | *bo_ptr = bo; |
@@ -199,7 +179,7 @@ int radeon_bo_pin(struct radeon_bo *bo, u32 domain, u64 *gpu_addr) | |||
199 | radeon_ttm_placement_from_domain(bo, domain); | 179 | radeon_ttm_placement_from_domain(bo, domain); |
200 | for (i = 0; i < bo->placement.num_placement; i++) | 180 | for (i = 0; i < bo->placement.num_placement; i++) |
201 | bo->placements[i] |= TTM_PL_FLAG_NO_EVICT; | 181 | bo->placements[i] |= TTM_PL_FLAG_NO_EVICT; |
202 | r = ttm_buffer_object_validate(&bo->tbo, &bo->placement, false, false); | 182 | r = ttm_bo_validate(&bo->tbo, &bo->placement, false, false); |
203 | if (likely(r == 0)) { | 183 | if (likely(r == 0)) { |
204 | bo->pin_count = 1; | 184 | bo->pin_count = 1; |
205 | if (gpu_addr != NULL) | 185 | if (gpu_addr != NULL) |
@@ -223,7 +203,7 @@ int radeon_bo_unpin(struct radeon_bo *bo) | |||
223 | return 0; | 203 | return 0; |
224 | for (i = 0; i < bo->placement.num_placement; i++) | 204 | for (i = 0; i < bo->placement.num_placement; i++) |
225 | bo->placements[i] &= ~TTM_PL_FLAG_NO_EVICT; | 205 | bo->placements[i] &= ~TTM_PL_FLAG_NO_EVICT; |
226 | r = ttm_buffer_object_validate(&bo->tbo, &bo->placement, false, false); | 206 | r = ttm_bo_validate(&bo->tbo, &bo->placement, false, false); |
227 | if (unlikely(r != 0)) | 207 | if (unlikely(r != 0)) |
228 | dev_err(bo->rdev->dev, "%p validate failed for unpin\n", bo); | 208 | dev_err(bo->rdev->dev, "%p validate failed for unpin\n", bo); |
229 | return r; | 209 | return r; |
@@ -336,8 +316,7 @@ int radeon_bo_list_validate(struct list_head *head, void *fence) | |||
336 | radeon_ttm_placement_from_domain(bo, | 316 | radeon_ttm_placement_from_domain(bo, |
337 | lobj->rdomain); | 317 | lobj->rdomain); |
338 | } | 318 | } |
339 | r = ttm_buffer_object_validate(&bo->tbo, | 319 | r = ttm_bo_validate(&bo->tbo, &bo->placement, |
340 | &bo->placement, | ||
341 | true, false); | 320 | true, false); |
342 | if (unlikely(r)) | 321 | if (unlikely(r)) |
343 | return r; | 322 | return r; |
diff --git a/drivers/gpu/drm/ttm/ttm_bo.c b/drivers/gpu/drm/ttm/ttm_bo.c index a835b6fe42a1..1fbb2eea5e88 100644 --- a/drivers/gpu/drm/ttm/ttm_bo.c +++ b/drivers/gpu/drm/ttm/ttm_bo.c | |||
@@ -185,6 +185,7 @@ int ttm_bo_wait_unreserved(struct ttm_buffer_object *bo, bool interruptible) | |||
185 | } | 185 | } |
186 | return 0; | 186 | return 0; |
187 | } | 187 | } |
188 | EXPORT_SYMBOL(ttm_bo_wait_unreserved); | ||
188 | 189 | ||
189 | static void ttm_bo_add_to_lru(struct ttm_buffer_object *bo) | 190 | static void ttm_bo_add_to_lru(struct ttm_buffer_object *bo) |
190 | { | 191 | { |
@@ -946,6 +947,7 @@ int ttm_bo_wait_cpu(struct ttm_buffer_object *bo, bool no_wait) | |||
946 | return wait_event_interruptible(bo->event_queue, | 947 | return wait_event_interruptible(bo->event_queue, |
947 | atomic_read(&bo->cpu_writers) == 0); | 948 | atomic_read(&bo->cpu_writers) == 0); |
948 | } | 949 | } |
950 | EXPORT_SYMBOL(ttm_bo_wait_cpu); | ||
949 | 951 | ||
950 | int ttm_bo_move_buffer(struct ttm_buffer_object *bo, | 952 | int ttm_bo_move_buffer(struct ttm_buffer_object *bo, |
951 | struct ttm_placement *placement, | 953 | struct ttm_placement *placement, |
@@ -1002,9 +1004,9 @@ static int ttm_bo_mem_compat(struct ttm_placement *placement, | |||
1002 | return -1; | 1004 | return -1; |
1003 | } | 1005 | } |
1004 | 1006 | ||
1005 | int ttm_buffer_object_validate(struct ttm_buffer_object *bo, | 1007 | int ttm_bo_validate(struct ttm_buffer_object *bo, |
1006 | struct ttm_placement *placement, | 1008 | struct ttm_placement *placement, |
1007 | bool interruptible, bool no_wait) | 1009 | bool interruptible, bool no_wait) |
1008 | { | 1010 | { |
1009 | int ret; | 1011 | int ret; |
1010 | 1012 | ||
@@ -1040,55 +1042,57 @@ int ttm_buffer_object_validate(struct ttm_buffer_object *bo, | |||
1040 | } | 1042 | } |
1041 | return 0; | 1043 | return 0; |
1042 | } | 1044 | } |
1043 | EXPORT_SYMBOL(ttm_buffer_object_validate); | 1045 | EXPORT_SYMBOL(ttm_bo_validate); |
1044 | 1046 | ||
1045 | int | 1047 | int ttm_bo_check_placement(struct ttm_buffer_object *bo, |
1046 | ttm_bo_check_placement(struct ttm_buffer_object *bo, | 1048 | struct ttm_placement *placement) |
1047 | uint32_t set_flags, uint32_t clr_flags) | ||
1048 | { | 1049 | { |
1049 | uint32_t new_mask = set_flags | clr_flags; | 1050 | int i; |
1050 | |||
1051 | if ((bo->type == ttm_bo_type_user) && | ||
1052 | (clr_flags & TTM_PL_FLAG_CACHED)) { | ||
1053 | printk(KERN_ERR TTM_PFX | ||
1054 | "User buffers require cache-coherent memory.\n"); | ||
1055 | return -EINVAL; | ||
1056 | } | ||
1057 | 1051 | ||
1058 | if (!capable(CAP_SYS_ADMIN)) { | 1052 | if (placement->fpfn || placement->lpfn) { |
1059 | if (new_mask & TTM_PL_FLAG_NO_EVICT) { | 1053 | if (bo->mem.num_pages > (placement->lpfn - placement->fpfn)) { |
1060 | printk(KERN_ERR TTM_PFX "Need to be root to modify" | 1054 | printk(KERN_ERR TTM_PFX "Page number range to small " |
1061 | " NO_EVICT status.\n"); | 1055 | "Need %lu pages, range is [%u, %u]\n", |
1056 | bo->mem.num_pages, placement->fpfn, | ||
1057 | placement->lpfn); | ||
1062 | return -EINVAL; | 1058 | return -EINVAL; |
1063 | } | 1059 | } |
1064 | 1060 | } | |
1065 | if ((clr_flags & bo->mem.placement & TTM_PL_MASK_MEMTYPE) && | 1061 | for (i = 0; i < placement->num_placement; i++) { |
1066 | (bo->mem.placement & TTM_PL_FLAG_NO_EVICT)) { | 1062 | if (!capable(CAP_SYS_ADMIN)) { |
1067 | printk(KERN_ERR TTM_PFX | 1063 | if (placement->placement[i] & TTM_PL_FLAG_NO_EVICT) { |
1068 | "Incompatible memory specification" | 1064 | printk(KERN_ERR TTM_PFX "Need to be root to " |
1069 | " for NO_EVICT buffer.\n"); | 1065 | "modify NO_EVICT status.\n"); |
1070 | return -EINVAL; | 1066 | return -EINVAL; |
1067 | } | ||
1068 | } | ||
1069 | } | ||
1070 | for (i = 0; i < placement->num_busy_placement; i++) { | ||
1071 | if (!capable(CAP_SYS_ADMIN)) { | ||
1072 | if (placement->busy_placement[i] & TTM_PL_FLAG_NO_EVICT) { | ||
1073 | printk(KERN_ERR TTM_PFX "Need to be root to " | ||
1074 | "modify NO_EVICT status.\n"); | ||
1075 | return -EINVAL; | ||
1076 | } | ||
1071 | } | 1077 | } |
1072 | } | 1078 | } |
1073 | return 0; | 1079 | return 0; |
1074 | } | 1080 | } |
1075 | 1081 | ||
1076 | int ttm_buffer_object_init(struct ttm_bo_device *bdev, | 1082 | int ttm_bo_init(struct ttm_bo_device *bdev, |
1077 | struct ttm_buffer_object *bo, | 1083 | struct ttm_buffer_object *bo, |
1078 | unsigned long size, | 1084 | unsigned long size, |
1079 | enum ttm_bo_type type, | 1085 | enum ttm_bo_type type, |
1080 | uint32_t flags, | 1086 | struct ttm_placement *placement, |
1081 | uint32_t page_alignment, | 1087 | uint32_t page_alignment, |
1082 | unsigned long buffer_start, | 1088 | unsigned long buffer_start, |
1083 | bool interruptible, | 1089 | bool interruptible, |
1084 | struct file *persistant_swap_storage, | 1090 | struct file *persistant_swap_storage, |
1085 | size_t acc_size, | 1091 | size_t acc_size, |
1086 | void (*destroy) (struct ttm_buffer_object *)) | 1092 | void (*destroy) (struct ttm_buffer_object *)) |
1087 | { | 1093 | { |
1088 | int i, c, ret = 0; | 1094 | int ret = 0; |
1089 | unsigned long num_pages; | 1095 | unsigned long num_pages; |
1090 | uint32_t placements[8]; | ||
1091 | struct ttm_placement placement; | ||
1092 | 1096 | ||
1093 | size += buffer_start & ~PAGE_MASK; | 1097 | size += buffer_start & ~PAGE_MASK; |
1094 | num_pages = (size + PAGE_SIZE - 1) >> PAGE_SHIFT; | 1098 | num_pages = (size + PAGE_SIZE - 1) >> PAGE_SHIFT; |
@@ -1123,38 +1127,21 @@ int ttm_buffer_object_init(struct ttm_bo_device *bdev, | |||
1123 | bo->acc_size = acc_size; | 1127 | bo->acc_size = acc_size; |
1124 | atomic_inc(&bo->glob->bo_count); | 1128 | atomic_inc(&bo->glob->bo_count); |
1125 | 1129 | ||
1126 | ret = ttm_bo_check_placement(bo, flags, 0ULL); | 1130 | ret = ttm_bo_check_placement(bo, placement); |
1127 | if (unlikely(ret != 0)) | 1131 | if (unlikely(ret != 0)) |
1128 | goto out_err; | 1132 | goto out_err; |
1129 | 1133 | ||
1130 | /* | 1134 | /* |
1131 | * If no caching attributes are set, accept any form of caching. | ||
1132 | */ | ||
1133 | |||
1134 | if ((flags & TTM_PL_MASK_CACHING) == 0) | ||
1135 | flags |= TTM_PL_MASK_CACHING; | ||
1136 | |||
1137 | /* | ||
1138 | * For ttm_bo_type_device buffers, allocate | 1135 | * For ttm_bo_type_device buffers, allocate |
1139 | * address space from the device. | 1136 | * address space from the device. |
1140 | */ | 1137 | */ |
1141 | |||
1142 | if (bo->type == ttm_bo_type_device) { | 1138 | if (bo->type == ttm_bo_type_device) { |
1143 | ret = ttm_bo_setup_vm(bo); | 1139 | ret = ttm_bo_setup_vm(bo); |
1144 | if (ret) | 1140 | if (ret) |
1145 | goto out_err; | 1141 | goto out_err; |
1146 | } | 1142 | } |
1147 | 1143 | ||
1148 | placement.fpfn = 0; | 1144 | ret = ttm_bo_validate(bo, placement, interruptible, false); |
1149 | placement.lpfn = 0; | ||
1150 | for (i = 0, c = 0; i <= TTM_PL_PRIV5; i++) | ||
1151 | if (flags & (1 << i)) | ||
1152 | placements[c++] = (flags & ~TTM_PL_MASK_MEM) | (1 << i); | ||
1153 | placement.placement = placements; | ||
1154 | placement.num_placement = c; | ||
1155 | placement.busy_placement = placements; | ||
1156 | placement.num_busy_placement = c; | ||
1157 | ret = ttm_buffer_object_validate(bo, &placement, interruptible, false); | ||
1158 | if (ret) | 1145 | if (ret) |
1159 | goto out_err; | 1146 | goto out_err; |
1160 | 1147 | ||
@@ -1167,7 +1154,7 @@ out_err: | |||
1167 | 1154 | ||
1168 | return ret; | 1155 | return ret; |
1169 | } | 1156 | } |
1170 | EXPORT_SYMBOL(ttm_buffer_object_init); | 1157 | EXPORT_SYMBOL(ttm_bo_init); |
1171 | 1158 | ||
1172 | static inline size_t ttm_bo_size(struct ttm_bo_global *glob, | 1159 | static inline size_t ttm_bo_size(struct ttm_bo_global *glob, |
1173 | unsigned long num_pages) | 1160 | unsigned long num_pages) |
@@ -1178,15 +1165,15 @@ static inline size_t ttm_bo_size(struct ttm_bo_global *glob, | |||
1178 | return glob->ttm_bo_size + 2 * page_array_size; | 1165 | return glob->ttm_bo_size + 2 * page_array_size; |
1179 | } | 1166 | } |
1180 | 1167 | ||
1181 | int ttm_buffer_object_create(struct ttm_bo_device *bdev, | 1168 | int ttm_bo_create(struct ttm_bo_device *bdev, |
1182 | unsigned long size, | 1169 | unsigned long size, |
1183 | enum ttm_bo_type type, | 1170 | enum ttm_bo_type type, |
1184 | uint32_t flags, | 1171 | struct ttm_placement *placement, |
1185 | uint32_t page_alignment, | 1172 | uint32_t page_alignment, |
1186 | unsigned long buffer_start, | 1173 | unsigned long buffer_start, |
1187 | bool interruptible, | 1174 | bool interruptible, |
1188 | struct file *persistant_swap_storage, | 1175 | struct file *persistant_swap_storage, |
1189 | struct ttm_buffer_object **p_bo) | 1176 | struct ttm_buffer_object **p_bo) |
1190 | { | 1177 | { |
1191 | struct ttm_buffer_object *bo; | 1178 | struct ttm_buffer_object *bo; |
1192 | struct ttm_mem_global *mem_glob = bdev->glob->mem_glob; | 1179 | struct ttm_mem_global *mem_glob = bdev->glob->mem_glob; |
@@ -1205,10 +1192,9 @@ int ttm_buffer_object_create(struct ttm_bo_device *bdev, | |||
1205 | return -ENOMEM; | 1192 | return -ENOMEM; |
1206 | } | 1193 | } |
1207 | 1194 | ||
1208 | ret = ttm_buffer_object_init(bdev, bo, size, type, flags, | 1195 | ret = ttm_bo_init(bdev, bo, size, type, placement, page_alignment, |
1209 | page_alignment, buffer_start, | 1196 | buffer_start, interruptible, |
1210 | interruptible, | 1197 | persistant_swap_storage, acc_size, NULL); |
1211 | persistant_swap_storage, acc_size, NULL); | ||
1212 | if (likely(ret == 0)) | 1198 | if (likely(ret == 0)) |
1213 | *p_bo = bo; | 1199 | *p_bo = bo; |
1214 | 1200 | ||
@@ -1743,12 +1729,14 @@ int ttm_bo_synccpu_write_grab(struct ttm_buffer_object *bo, bool no_wait) | |||
1743 | ttm_bo_unreserve(bo); | 1729 | ttm_bo_unreserve(bo); |
1744 | return ret; | 1730 | return ret; |
1745 | } | 1731 | } |
1732 | EXPORT_SYMBOL(ttm_bo_synccpu_write_grab); | ||
1746 | 1733 | ||
1747 | void ttm_bo_synccpu_write_release(struct ttm_buffer_object *bo) | 1734 | void ttm_bo_synccpu_write_release(struct ttm_buffer_object *bo) |
1748 | { | 1735 | { |
1749 | if (atomic_dec_and_test(&bo->cpu_writers)) | 1736 | if (atomic_dec_and_test(&bo->cpu_writers)) |
1750 | wake_up_all(&bo->event_queue); | 1737 | wake_up_all(&bo->event_queue); |
1751 | } | 1738 | } |
1739 | EXPORT_SYMBOL(ttm_bo_synccpu_write_release); | ||
1752 | 1740 | ||
1753 | /** | 1741 | /** |
1754 | * A buffer object shrink method that tries to swap out the first | 1742 | * A buffer object shrink method that tries to swap out the first |