@@ -284,6 +284,34 @@ set_placement_range(struct nouveau_bo *nvbo, uint32_t type)
}
}
+static void
+nouveau_bo_sync_for_cpu(struct nouveau_bo *nvbo)
+{
+ struct nouveau_device *device;
+ struct ttm_tt *ttm = nvbo->bo.ttm;
+
+ device = nouveau_dev(nouveau_bdev(ttm->bdev)->dev);
+
+ if (nvbo->bo.ttm && nvbo->bo.ttm->caching_state == tt_cached)
+ ttm_dma_tt_cache_sync_for_cpu((struct ttm_dma_tt *)nvbo->bo.ttm,
+ nv_device_base(device));
+}
+
+static void
+nouveau_bo_sync_for_device(struct nouveau_bo *nvbo)
+{
+ struct ttm_tt *ttm = nvbo->bo.ttm;
+
+ if (ttm && ttm->caching_state == tt_cached) {
+ struct nouveau_device *device;
+
+ device = nouveau_dev(nouveau_bdev(ttm->bdev)->dev);
+
+ ttm_dma_tt_cache_sync_for_device((struct ttm_dma_tt *)ttm,
+ nv_device_base(device));
+ }
+}
+
void
nouveau_bo_placement_set(struct nouveau_bo *nvbo, uint32_t type, uint32_t busy)
{
@@ -407,6 +435,8 @@ nouveau_bo_validate(struct nouveau_bo *nvbo, bool interruptible,
{
int ret;
+ nouveau_bo_sync_for_device(nvbo);
+
ret = ttm_bo_validate(&nvbo->bo, &nvbo->placement,
interruptible, no_wait_gpu);
if (ret)
@@ -415,6 +445,23 @@ nouveau_bo_validate(struct nouveau_bo *nvbo, bool interruptible,
return 0;
}
+int
+nouveau_bo_wait(struct nouveau_bo *nvbo, bool no_wait)
+{
+ int ret;
+
+ spin_lock(&nvbo->bo.bdev->fence_lock);
+ ret = ttm_bo_wait(&nvbo->bo, true, true, no_wait);
+ spin_unlock(&nvbo->bo.bdev->fence_lock);
+
+ if (ret)
+ return ret;
+
+ nouveau_bo_sync_for_cpu(nvbo);
+
+ return 0;
+}
+
u16
nouveau_bo_rd16(struct nouveau_bo *nvbo, unsigned index)
{
@@ -81,6 +81,7 @@ void nouveau_bo_wr32(struct nouveau_bo *, unsigned index, u32 val);
void nouveau_bo_fence(struct nouveau_bo *, struct nouveau_fence *);
int nouveau_bo_validate(struct nouveau_bo *, bool interruptible,
bool no_wait_gpu);
+int nouveau_bo_wait(struct nouveau_bo *, bool no_wait);
struct nouveau_vma *
nouveau_bo_vma_find(struct nouveau_bo *, struct nouveau_vm *);
@@ -884,19 +884,15 @@ nouveau_gem_ioctl_cpu_prep(struct drm_device *dev, void *data,
{
struct drm_nouveau_gem_cpu_prep *req = data;
struct drm_gem_object *gem;
- struct nouveau_bo *nvbo;
bool no_wait = !!(req->flags & NOUVEAU_GEM_CPU_PREP_NOWAIT);
- int ret = -EINVAL;
+ int ret;
gem = drm_gem_object_lookup(dev, file_priv, req->handle);
if (!gem)
return -ENOENT;
- nvbo = nouveau_gem_object(gem);
-
- spin_lock(&nvbo->bo.bdev->fence_lock);
- ret = ttm_bo_wait(&nvbo->bo, true, true, no_wait);
- spin_unlock(&nvbo->bo.bdev->fence_lock);
+ ret = nouveau_bo_wait(nouveau_gem_object(gem), no_wait);
drm_gem_object_unreference_unlocked(gem);
+
return ret;
}