diff options
author | Ben Skeggs <bskeggs@redhat.com> | 2012-04-29 22:51:48 -0400 |
---|---|---|
committer | Ben Skeggs <bskeggs@redhat.com> | 2012-05-24 02:55:44 -0400 |
commit | 875ac34aad49bb875833aed2b4f2deb7a28df9f0 (patch) | |
tree | 254aedbbc3c838471090154a9d14d29ad86211de | |
parent | 35bcf5d55540e47091a67e5962f12b88d51d7131 (diff) |
drm/nouveau/fence: make ttm interfaces wrap ours, not the other way around
Signed-off-by: Ben Skeggs <bskeggs@redhat.com>
-rw-r--r-- | drivers/gpu/drm/nouveau/nouveau_bo.c | 72 | ||||
-rw-r--r-- | drivers/gpu/drm/nouveau/nouveau_drv.h | 31 | ||||
-rw-r--r-- | drivers/gpu/drm/nouveau/nouveau_fence.c | 36 |
3 files changed, 68 insertions, 71 deletions
diff --git a/drivers/gpu/drm/nouveau/nouveau_bo.c b/drivers/gpu/drm/nouveau/nouveau_bo.c index c45c7bce9ebd..1aa03a83bae0 100644 --- a/drivers/gpu/drm/nouveau/nouveau_bo.c +++ b/drivers/gpu/drm/nouveau/nouveau_bo.c | |||
@@ -1068,22 +1068,6 @@ nouveau_ttm_fault_reserve_notify(struct ttm_buffer_object *bo) | |||
1068 | return nouveau_bo_validate(nvbo, false, true, false); | 1068 | return nouveau_bo_validate(nvbo, false, true, false); |
1069 | } | 1069 | } |
1070 | 1070 | ||
1071 | void | ||
1072 | nouveau_bo_fence(struct nouveau_bo *nvbo, struct nouveau_fence *fence) | ||
1073 | { | ||
1074 | struct nouveau_fence *old_fence; | ||
1075 | |||
1076 | if (likely(fence)) | ||
1077 | nouveau_fence_ref(fence); | ||
1078 | |||
1079 | spin_lock(&nvbo->bo.bdev->fence_lock); | ||
1080 | old_fence = nvbo->bo.sync_obj; | ||
1081 | nvbo->bo.sync_obj = fence; | ||
1082 | spin_unlock(&nvbo->bo.bdev->fence_lock); | ||
1083 | |||
1084 | nouveau_fence_unref(&old_fence); | ||
1085 | } | ||
1086 | |||
1087 | static int | 1071 | static int |
1088 | nouveau_ttm_tt_populate(struct ttm_tt *ttm) | 1072 | nouveau_ttm_tt_populate(struct ttm_tt *ttm) |
1089 | { | 1073 | { |
@@ -1181,6 +1165,52 @@ nouveau_ttm_tt_unpopulate(struct ttm_tt *ttm) | |||
1181 | ttm_pool_unpopulate(ttm); | 1165 | ttm_pool_unpopulate(ttm); |
1182 | } | 1166 | } |
1183 | 1167 | ||
1168 | void | ||
1169 | nouveau_bo_fence(struct nouveau_bo *nvbo, struct nouveau_fence *fence) | ||
1170 | { | ||
1171 | struct nouveau_fence *old_fence = NULL; | ||
1172 | |||
1173 | if (likely(fence)) | ||
1174 | nouveau_fence_ref(fence); | ||
1175 | |||
1176 | spin_lock(&nvbo->bo.bdev->fence_lock); | ||
1177 | old_fence = nvbo->bo.sync_obj; | ||
1178 | nvbo->bo.sync_obj = fence; | ||
1179 | spin_unlock(&nvbo->bo.bdev->fence_lock); | ||
1180 | |||
1181 | nouveau_fence_unref(&old_fence); | ||
1182 | } | ||
1183 | |||
1184 | static void | ||
1185 | nouveau_bo_fence_unref(void **sync_obj) | ||
1186 | { | ||
1187 | nouveau_fence_unref((struct nouveau_fence **)sync_obj); | ||
1188 | } | ||
1189 | |||
1190 | static void * | ||
1191 | nouveau_bo_fence_ref(void *sync_obj) | ||
1192 | { | ||
1193 | return nouveau_fence_ref(sync_obj); | ||
1194 | } | ||
1195 | |||
1196 | static bool | ||
1197 | nouveau_bo_fence_signalled(void *sync_obj, void *sync_arg) | ||
1198 | { | ||
1199 | return nouveau_fence_signalled(sync_obj); | ||
1200 | } | ||
1201 | |||
1202 | static int | ||
1203 | nouveau_bo_fence_wait(void *sync_obj, void *sync_arg, bool lazy, bool intr) | ||
1204 | { | ||
1205 | return nouveau_fence_wait(sync_obj, lazy, intr); | ||
1206 | } | ||
1207 | |||
1208 | static int | ||
1209 | nouveau_bo_fence_flush(void *sync_obj, void *sync_arg) | ||
1210 | { | ||
1211 | return 0; | ||
1212 | } | ||
1213 | |||
1184 | struct ttm_bo_driver nouveau_bo_driver = { | 1214 | struct ttm_bo_driver nouveau_bo_driver = { |
1185 | .ttm_tt_create = &nouveau_ttm_tt_create, | 1215 | .ttm_tt_create = &nouveau_ttm_tt_create, |
1186 | .ttm_tt_populate = &nouveau_ttm_tt_populate, | 1216 | .ttm_tt_populate = &nouveau_ttm_tt_populate, |
@@ -1191,11 +1221,11 @@ struct ttm_bo_driver nouveau_bo_driver = { | |||
1191 | .move_notify = nouveau_bo_move_ntfy, | 1221 | .move_notify = nouveau_bo_move_ntfy, |
1192 | .move = nouveau_bo_move, | 1222 | .move = nouveau_bo_move, |
1193 | .verify_access = nouveau_bo_verify_access, | 1223 | .verify_access = nouveau_bo_verify_access, |
1194 | .sync_obj_signaled = __nouveau_fence_signalled, | 1224 | .sync_obj_signaled = nouveau_bo_fence_signalled, |
1195 | .sync_obj_wait = __nouveau_fence_wait, | 1225 | .sync_obj_wait = nouveau_bo_fence_wait, |
1196 | .sync_obj_flush = __nouveau_fence_flush, | 1226 | .sync_obj_flush = nouveau_bo_fence_flush, |
1197 | .sync_obj_unref = __nouveau_fence_unref, | 1227 | .sync_obj_unref = nouveau_bo_fence_unref, |
1198 | .sync_obj_ref = __nouveau_fence_ref, | 1228 | .sync_obj_ref = nouveau_bo_fence_ref, |
1199 | .fault_reserve_notify = &nouveau_ttm_fault_reserve_notify, | 1229 | .fault_reserve_notify = &nouveau_ttm_fault_reserve_notify, |
1200 | .io_mem_reserve = &nouveau_ttm_io_mem_reserve, | 1230 | .io_mem_reserve = &nouveau_ttm_io_mem_reserve, |
1201 | .io_mem_free = &nouveau_ttm_io_mem_free, | 1231 | .io_mem_free = &nouveau_ttm_io_mem_free, |
diff --git a/drivers/gpu/drm/nouveau/nouveau_drv.h b/drivers/gpu/drm/nouveau/nouveau_drv.h index dce621555433..b17444ae05c8 100644 --- a/drivers/gpu/drm/nouveau/nouveau_drv.h +++ b/drivers/gpu/drm/nouveau/nouveau_drv.h | |||
@@ -1458,34 +1458,11 @@ extern void nouveau_fence_work(struct nouveau_fence *fence, | |||
1458 | void *priv); | 1458 | void *priv); |
1459 | struct nouveau_channel *nouveau_fence_channel(struct nouveau_fence *); | 1459 | struct nouveau_channel *nouveau_fence_channel(struct nouveau_fence *); |
1460 | 1460 | ||
1461 | extern bool __nouveau_fence_signalled(void *obj, void *arg); | 1461 | extern bool nouveau_fence_signalled(struct nouveau_fence *); |
1462 | extern int __nouveau_fence_wait(void *obj, void *arg, bool lazy, bool intr); | 1462 | extern int nouveau_fence_wait(struct nouveau_fence *, bool lazy, bool intr); |
1463 | extern int __nouveau_fence_flush(void *obj, void *arg); | 1463 | extern void nouveau_fence_unref(struct nouveau_fence **); |
1464 | extern void __nouveau_fence_unref(void **obj); | 1464 | extern struct nouveau_fence *nouveau_fence_ref(struct nouveau_fence *); |
1465 | extern void *__nouveau_fence_ref(void *obj); | ||
1466 | |||
1467 | static inline bool nouveau_fence_signalled(struct nouveau_fence *obj) | ||
1468 | { | ||
1469 | return __nouveau_fence_signalled(obj, NULL); | ||
1470 | } | ||
1471 | static inline int | ||
1472 | nouveau_fence_wait(struct nouveau_fence *obj, bool lazy, bool intr) | ||
1473 | { | ||
1474 | return __nouveau_fence_wait(obj, NULL, lazy, intr); | ||
1475 | } | ||
1476 | extern int nouveau_fence_sync(struct nouveau_fence *, struct nouveau_channel *); | 1465 | extern int nouveau_fence_sync(struct nouveau_fence *, struct nouveau_channel *); |
1477 | static inline int nouveau_fence_flush(struct nouveau_fence *obj) | ||
1478 | { | ||
1479 | return __nouveau_fence_flush(obj, NULL); | ||
1480 | } | ||
1481 | static inline void nouveau_fence_unref(struct nouveau_fence **obj) | ||
1482 | { | ||
1483 | __nouveau_fence_unref((void **)obj); | ||
1484 | } | ||
1485 | static inline struct nouveau_fence *nouveau_fence_ref(struct nouveau_fence *obj) | ||
1486 | { | ||
1487 | return __nouveau_fence_ref(obj); | ||
1488 | } | ||
1489 | 1466 | ||
1490 | /* nouveau_gem.c */ | 1467 | /* nouveau_gem.c */ |
1491 | extern int nouveau_gem_new(struct drm_device *, int size, int align, | 1468 | extern int nouveau_gem_new(struct drm_device *, int size, int align, |
diff --git a/drivers/gpu/drm/nouveau/nouveau_fence.c b/drivers/gpu/drm/nouveau/nouveau_fence.c index aca4719c287f..f26177ac27e7 100644 --- a/drivers/gpu/drm/nouveau/nouveau_fence.c +++ b/drivers/gpu/drm/nouveau/nouveau_fence.c | |||
@@ -199,28 +199,23 @@ nouveau_fence_work(struct nouveau_fence *fence, | |||
199 | } | 199 | } |
200 | 200 | ||
201 | void | 201 | void |
202 | __nouveau_fence_unref(void **sync_obj) | 202 | nouveau_fence_unref(struct nouveau_fence **pfence) |
203 | { | 203 | { |
204 | struct nouveau_fence *fence = nouveau_fence(*sync_obj); | 204 | if (*pfence) |
205 | 205 | kref_put(&(*pfence)->refcount, nouveau_fence_del); | |
206 | if (fence) | 206 | *pfence = NULL; |
207 | kref_put(&fence->refcount, nouveau_fence_del); | ||
208 | *sync_obj = NULL; | ||
209 | } | 207 | } |
210 | 208 | ||
211 | void * | 209 | struct nouveau_fence * |
212 | __nouveau_fence_ref(void *sync_obj) | 210 | nouveau_fence_ref(struct nouveau_fence *fence) |
213 | { | 211 | { |
214 | struct nouveau_fence *fence = nouveau_fence(sync_obj); | ||
215 | |||
216 | kref_get(&fence->refcount); | 212 | kref_get(&fence->refcount); |
217 | return sync_obj; | 213 | return fence; |
218 | } | 214 | } |
219 | 215 | ||
220 | bool | 216 | bool |
221 | __nouveau_fence_signalled(void *sync_obj, void *sync_arg) | 217 | nouveau_fence_signalled(struct nouveau_fence *fence) |
222 | { | 218 | { |
223 | struct nouveau_fence *fence = nouveau_fence(sync_obj); | ||
224 | struct nouveau_channel *chan = fence->channel; | 219 | struct nouveau_channel *chan = fence->channel; |
225 | 220 | ||
226 | if (fence->signalled) | 221 | if (fence->signalled) |
@@ -231,25 +226,20 @@ __nouveau_fence_signalled(void *sync_obj, void *sync_arg) | |||
231 | } | 226 | } |
232 | 227 | ||
233 | int | 228 | int |
234 | __nouveau_fence_wait(void *sync_obj, void *sync_arg, bool lazy, bool intr) | 229 | nouveau_fence_wait(struct nouveau_fence *fence, bool lazy, bool intr) |
235 | { | 230 | { |
236 | struct nouveau_fence *fence = nouveau_fence(sync_obj); | ||
237 | unsigned long timeout = fence->timeout; | ||
238 | unsigned long sleep_time = NSEC_PER_MSEC / 1000; | 231 | unsigned long sleep_time = NSEC_PER_MSEC / 1000; |
239 | ktime_t t; | 232 | ktime_t t; |
240 | int ret = 0; | 233 | int ret = 0; |
241 | 234 | ||
242 | while (1) { | 235 | while (!nouveau_fence_signalled(fence)) { |
243 | if (__nouveau_fence_signalled(sync_obj, sync_arg)) | 236 | if (time_after_eq(jiffies, fence->timeout)) { |
244 | break; | ||
245 | |||
246 | if (time_after_eq(jiffies, timeout)) { | ||
247 | ret = -EBUSY; | 237 | ret = -EBUSY; |
248 | break; | 238 | break; |
249 | } | 239 | } |
250 | 240 | ||
251 | __set_current_state(intr ? TASK_INTERRUPTIBLE | 241 | __set_current_state(intr ? TASK_INTERRUPTIBLE : |
252 | : TASK_UNINTERRUPTIBLE); | 242 | TASK_UNINTERRUPTIBLE); |
253 | if (lazy) { | 243 | if (lazy) { |
254 | t = ktime_set(0, sleep_time); | 244 | t = ktime_set(0, sleep_time); |
255 | schedule_hrtimeout(&t, HRTIMER_MODE_REL); | 245 | schedule_hrtimeout(&t, HRTIMER_MODE_REL); |