drm/radeon: cope with foreign fences inside the reservation object
authorMaarten Lankhorst <maarten.lankhorst@canonical.com>
Thu, 25 Sep 2014 10:39:38 +0000 (12:39 +0200)
committerAlex Deucher <alexander.deucher@amd.com>
Fri, 3 Oct 2014 13:19:16 +0000 (09:19 -0400)
Not the whole world is a radeon! :-)

Reviewed-by: Christian König <christian.koenig@amd.com>
Signed-off-by: Maarten Lankhorst <maarten.lankhorst@canonical.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
12 files changed:
drivers/gpu/drm/radeon/cik.c
drivers/gpu/drm/radeon/cik_sdma.c
drivers/gpu/drm/radeon/evergreen_dma.c
drivers/gpu/drm/radeon/r600.c
drivers/gpu/drm/radeon/r600_dma.c
drivers/gpu/drm/radeon/radeon.h
drivers/gpu/drm/radeon/radeon_cs.c
drivers/gpu/drm/radeon/radeon_fence.c
drivers/gpu/drm/radeon/radeon_semaphore.c
drivers/gpu/drm/radeon/radeon_vm.c
drivers/gpu/drm/radeon/rv770_dma.c
drivers/gpu/drm/radeon/si_dma.c

index 05c2f43421aaeda2946154dfc5b12ad016f19082..fc49a8d0fe00c930b0c9deb48ee49f0eaa16bfe8 100644 (file)
@@ -3993,7 +3993,7 @@ struct radeon_fence *cik_copy_cpdma(struct radeon_device *rdev,
                return ERR_PTR(r);
        }
 
-       radeon_semaphore_sync_resv(sem, resv, false);
+       radeon_semaphore_sync_resv(rdev, sem, resv, false);
        radeon_semaphore_sync_rings(rdev, sem, ring->idx);
 
        for (i = 0; i < num_loops; i++) {
index c01a6100c3189d7e897500d36928c1f66b9756d0..c473c9125295137002efa5fe72eaad254e165ecd 100644 (file)
@@ -571,7 +571,7 @@ struct radeon_fence *cik_copy_dma(struct radeon_device *rdev,
                return ERR_PTR(r);
        }
 
-       radeon_semaphore_sync_resv(sem, resv, false);
+       radeon_semaphore_sync_resv(rdev, sem, resv, false);
        radeon_semaphore_sync_rings(rdev, sem, ring->idx);
 
        for (i = 0; i < num_loops; i++) {
index 946f37d0b469b5f2ddccfe4a65ea23de72aa44d5..66bcfadeedd1a56265ea2f8121df864ecad4574e 100644 (file)
@@ -133,7 +133,7 @@ struct radeon_fence *evergreen_copy_dma(struct radeon_device *rdev,
                return ERR_PTR(r);
        }
 
-       radeon_semaphore_sync_resv(sem, resv, false);
+       radeon_semaphore_sync_resv(rdev, sem, resv, false);
        radeon_semaphore_sync_rings(rdev, sem, ring->idx);
 
        for (i = 0; i < num_loops; i++) {
index 25f367ac4637e5b5fcf27963c23532fdc003b9cd..f8eb519c32865a9510e2ba31cfcef5958c727a8f 100644 (file)
@@ -2912,7 +2912,7 @@ struct radeon_fence *r600_copy_cpdma(struct radeon_device *rdev,
                return ERR_PTR(r);
        }
 
-       radeon_semaphore_sync_resv(sem, resv, false);
+       radeon_semaphore_sync_resv(rdev, sem, resv, false);
        radeon_semaphore_sync_rings(rdev, sem, ring->idx);
 
        radeon_ring_write(ring, PACKET3(PACKET3_SET_CONFIG_REG, 1));
index fc54224ce87b1d2d439e7c5210160618659fb76f..a49db830a47fdb0ab968438f34db39e88673fdf8 100644 (file)
@@ -470,7 +470,7 @@ struct radeon_fence *r600_copy_dma(struct radeon_device *rdev,
                return ERR_PTR(r);
        }
 
-       radeon_semaphore_sync_resv(sem, resv, false);
+       radeon_semaphore_sync_resv(rdev, sem, resv, false);
        radeon_semaphore_sync_rings(rdev, sem, ring->idx);
 
        for (i = 0; i < num_loops; i++) {
index 06d24b85003e270c4f8cde9dbd46ca1532558aff..e01424fe284877a9b697dbc1b0234a42b62c385e 100644 (file)
@@ -589,9 +589,10 @@ bool radeon_semaphore_emit_wait(struct radeon_device *rdev, int ring,
                                struct radeon_semaphore *semaphore);
 void radeon_semaphore_sync_fence(struct radeon_semaphore *semaphore,
                                 struct radeon_fence *fence);
-void radeon_semaphore_sync_resv(struct radeon_semaphore *semaphore,
-                               struct reservation_object *resv,
-                               bool shared);
+int radeon_semaphore_sync_resv(struct radeon_device *rdev,
+                              struct radeon_semaphore *semaphore,
+                              struct reservation_object *resv,
+                              bool shared);
 int radeon_semaphore_sync_rings(struct radeon_device *rdev,
                                struct radeon_semaphore *semaphore,
                                int waiting_ring);
index f662de41ba49b232e7cad9d07f22f9649d312142..1c893447d7cd60fff05fa029dd9d3260d9495c11 100644 (file)
@@ -249,9 +249,9 @@ static int radeon_cs_get_ring(struct radeon_cs_parser *p, u32 ring, s32 priority
        return 0;
 }
 
-static void radeon_cs_sync_rings(struct radeon_cs_parser *p)
+static int radeon_cs_sync_rings(struct radeon_cs_parser *p)
 {
-       int i;
+       int i, r = 0;
 
        for (i = 0; i < p->nrelocs; i++) {
                struct reservation_object *resv;
@@ -260,9 +260,13 @@ static void radeon_cs_sync_rings(struct radeon_cs_parser *p)
                        continue;
 
                resv = p->relocs[i].robj->tbo.resv;
-               radeon_semaphore_sync_resv(p->ib.semaphore, resv,
-                                          p->relocs[i].tv.shared);
+               r = radeon_semaphore_sync_resv(p->rdev, p->ib.semaphore, resv,
+                                              p->relocs[i].tv.shared);
+
+               if (r)
+                       break;
        }
+       return r;
 }
 
 /* XXX: note that this is called from the legacy UMS CS ioctl as well */
@@ -472,13 +476,19 @@ static int radeon_cs_ib_chunk(struct radeon_device *rdev,
                return r;
        }
 
+       r = radeon_cs_sync_rings(parser);
+       if (r) {
+               if (r != -ERESTARTSYS)
+                       DRM_ERROR("Failed to sync rings: %i\n", r);
+               return r;
+       }
+
        if (parser->ring == R600_RING_TYPE_UVD_INDEX)
                radeon_uvd_note_usage(rdev);
        else if ((parser->ring == TN_RING_TYPE_VCE1_INDEX) ||
                 (parser->ring == TN_RING_TYPE_VCE2_INDEX))
                radeon_vce_note_usage(rdev);
 
-       radeon_cs_sync_rings(parser);
        r = radeon_ib_schedule(rdev, &parser->ib, NULL, true);
        if (r) {
                DRM_ERROR("Failed to schedule IB !\n");
@@ -565,7 +575,13 @@ static int radeon_cs_ib_vm_chunk(struct radeon_device *rdev,
        if (r) {
                goto out;
        }
-       radeon_cs_sync_rings(parser);
+
+       r = radeon_cs_sync_rings(parser);
+       if (r) {
+               if (r != -ERESTARTSYS)
+                       DRM_ERROR("Failed to sync rings: %i\n", r);
+               goto out;
+       }
        radeon_semaphore_sync_fence(parser->ib.semaphore, vm->fence);
 
        if ((rdev->family >= CHIP_TAHITI) &&
index af9f2d6bd7d03f8b54d814dc3cb0d6360275ecad..995167025282a13ff7fdbbe7a1555f0d228a751b 100644 (file)
@@ -541,6 +541,15 @@ int radeon_fence_wait(struct radeon_fence *fence, bool intr)
        uint64_t seq[RADEON_NUM_RINGS] = {};
        long r;
 
+       /*
+        * This function should not be called on !radeon fences.
+        * If this is the case, it would mean this function can
+        * also be called on radeon fences belonging to another card.
+        * exclusive_lock is not held in that case.
+        */
+       if (WARN_ON_ONCE(!to_radeon_fence(&fence->base)))
+               return fence_wait(&fence->base, intr);
+
        seq[fence->ring] = fence->seq;
        r = radeon_fence_wait_seq_timeout(fence->rdev, seq, intr, MAX_SCHEDULE_TIMEOUT);
        if (r < 0) {
index 4d4b0773638a53ca71e158489212e45ab87e6d50..6deb08f045b758a9cbaefec886177b86c950a567 100644 (file)
@@ -124,27 +124,42 @@ void radeon_semaphore_sync_fence(struct radeon_semaphore *semaphore,
  *
  * Sync to the fence using this semaphore object
  */
-void radeon_semaphore_sync_resv(struct radeon_semaphore *sema,
-                               struct reservation_object *resv,
-                               bool shared)
+int radeon_semaphore_sync_resv(struct radeon_device *rdev,
+                              struct radeon_semaphore *sema,
+                              struct reservation_object *resv,
+                              bool shared)
 {
        struct reservation_object_list *flist;
        struct fence *f;
+       struct radeon_fence *fence;
        unsigned i;
+       int r = 0;
 
        /* always sync to the exclusive fence */
        f = reservation_object_get_excl(resv);
-       radeon_semaphore_sync_fence(sema, (struct radeon_fence*)f);
+       fence = f ? to_radeon_fence(f) : NULL;
+       if (fence && fence->rdev == rdev)
+               radeon_semaphore_sync_fence(sema, fence);
+       else if (f)
+               r = fence_wait(f, true);
 
        flist = reservation_object_get_list(resv);
-       if (shared || !flist)
-               return;
+       if (shared || !flist || r)
+               return r;
 
        for (i = 0; i < flist->shared_count; ++i) {
                f = rcu_dereference_protected(flist->shared[i],
                                              reservation_object_held(resv));
-               radeon_semaphore_sync_fence(sema, (struct radeon_fence*)f);
+               fence = to_radeon_fence(f);
+               if (fence && fence->rdev == rdev)
+                       radeon_semaphore_sync_fence(sema, fence);
+               else
+                       r = fence_wait(f, true);
+
+               if (r)
+                       break;
        }
+       return r;
 }
 
 /**
index ce870959dff830b2a5f5615711588f1cb107bf89..8af1a94e7448234c35ae938f24353ee49c02d6f1 100644 (file)
@@ -698,7 +698,7 @@ int radeon_vm_update_page_directory(struct radeon_device *rdev,
        if (ib.length_dw != 0) {
                radeon_asic_vm_pad_ib(rdev, &ib);
 
-               radeon_semaphore_sync_resv(ib.semaphore, pd->tbo.resv, false);
+               radeon_semaphore_sync_resv(rdev, ib.semaphore, pd->tbo.resv, false);
                radeon_semaphore_sync_fence(ib.semaphore, vm->last_id_use);
                WARN_ON(ib.length_dw > ndw);
                r = radeon_ib_schedule(rdev, &ib, NULL, false);
@@ -825,7 +825,7 @@ static void radeon_vm_update_ptes(struct radeon_device *rdev,
                unsigned nptes;
                uint64_t pte;
 
-               radeon_semaphore_sync_resv(ib->semaphore, pt->tbo.resv, false);
+               radeon_semaphore_sync_resv(rdev, ib->semaphore, pt->tbo.resv, false);
 
                if ((addr & ~mask) == (end & ~mask))
                        nptes = end - addr;
index c112764adfdf20de5d2aa2885a571489078a89b8..7f34bad2e724d6e657203cfde55f85ddb48fa8da 100644 (file)
@@ -67,7 +67,7 @@ struct radeon_fence *rv770_copy_dma(struct radeon_device *rdev,
                return ERR_PTR(r);
        }
 
-       radeon_semaphore_sync_resv(sem, resv, false);
+       radeon_semaphore_sync_resv(rdev, sem, resv, false);
        radeon_semaphore_sync_rings(rdev, sem, ring->idx);
 
        for (i = 0; i < num_loops; i++) {
index 9b0dfbc913f3f60b621c535efca329d56d20b757..b58f12b762d797c3c4db418712987cf0da43718d 100644 (file)
@@ -252,7 +252,7 @@ struct radeon_fence *si_copy_dma(struct radeon_device *rdev,
                return ERR_PTR(r);
        }
 
-       radeon_semaphore_sync_resv(sem, resv, false);
+       radeon_semaphore_sync_resv(rdev, sem, resv, false);
        radeon_semaphore_sync_rings(rdev, sem, ring->idx);
 
        for (i = 0; i < num_loops; i++) {