Commit 392a250b authored by Maarten Lankhorst's avatar Maarten Lankhorst Committed by Alex Deucher

drm/radeon: cope with foreign fences inside the reservation object

Not the whole world is a radeon! :-)
Reviewed-by: default avatarChristian König <christian.koenig@amd.com>
Signed-off-by: default avatarMaarten Lankhorst <maarten.lankhorst@canonical.com>
Signed-off-by: default avatarAlex Deucher <alexander.deucher@amd.com>
parent a0e84764
...@@ -3993,7 +3993,7 @@ struct radeon_fence *cik_copy_cpdma(struct radeon_device *rdev, ...@@ -3993,7 +3993,7 @@ struct radeon_fence *cik_copy_cpdma(struct radeon_device *rdev,
return ERR_PTR(r); 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_semaphore_sync_rings(rdev, sem, ring->idx);
for (i = 0; i < num_loops; i++) { for (i = 0; i < num_loops; i++) {
......
...@@ -571,7 +571,7 @@ struct radeon_fence *cik_copy_dma(struct radeon_device *rdev, ...@@ -571,7 +571,7 @@ struct radeon_fence *cik_copy_dma(struct radeon_device *rdev,
return ERR_PTR(r); 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_semaphore_sync_rings(rdev, sem, ring->idx);
for (i = 0; i < num_loops; i++) { for (i = 0; i < num_loops; i++) {
......
...@@ -133,7 +133,7 @@ struct radeon_fence *evergreen_copy_dma(struct radeon_device *rdev, ...@@ -133,7 +133,7 @@ struct radeon_fence *evergreen_copy_dma(struct radeon_device *rdev,
return ERR_PTR(r); 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_semaphore_sync_rings(rdev, sem, ring->idx);
for (i = 0; i < num_loops; i++) { for (i = 0; i < num_loops; i++) {
......
...@@ -2912,7 +2912,7 @@ struct radeon_fence *r600_copy_cpdma(struct radeon_device *rdev, ...@@ -2912,7 +2912,7 @@ struct radeon_fence *r600_copy_cpdma(struct radeon_device *rdev,
return ERR_PTR(r); 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_semaphore_sync_rings(rdev, sem, ring->idx);
radeon_ring_write(ring, PACKET3(PACKET3_SET_CONFIG_REG, 1)); radeon_ring_write(ring, PACKET3(PACKET3_SET_CONFIG_REG, 1));
......
...@@ -470,7 +470,7 @@ struct radeon_fence *r600_copy_dma(struct radeon_device *rdev, ...@@ -470,7 +470,7 @@ struct radeon_fence *r600_copy_dma(struct radeon_device *rdev,
return ERR_PTR(r); 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_semaphore_sync_rings(rdev, sem, ring->idx);
for (i = 0; i < num_loops; i++) { for (i = 0; i < num_loops; i++) {
......
...@@ -589,9 +589,10 @@ bool radeon_semaphore_emit_wait(struct radeon_device *rdev, int ring, ...@@ -589,9 +589,10 @@ bool radeon_semaphore_emit_wait(struct radeon_device *rdev, int ring,
struct radeon_semaphore *semaphore); struct radeon_semaphore *semaphore);
void radeon_semaphore_sync_fence(struct radeon_semaphore *semaphore, void radeon_semaphore_sync_fence(struct radeon_semaphore *semaphore,
struct radeon_fence *fence); struct radeon_fence *fence);
void radeon_semaphore_sync_resv(struct radeon_semaphore *semaphore, int radeon_semaphore_sync_resv(struct radeon_device *rdev,
struct reservation_object *resv, struct radeon_semaphore *semaphore,
bool shared); struct reservation_object *resv,
bool shared);
int radeon_semaphore_sync_rings(struct radeon_device *rdev, int radeon_semaphore_sync_rings(struct radeon_device *rdev,
struct radeon_semaphore *semaphore, struct radeon_semaphore *semaphore,
int waiting_ring); int waiting_ring);
......
...@@ -249,9 +249,9 @@ static int radeon_cs_get_ring(struct radeon_cs_parser *p, u32 ring, s32 priority ...@@ -249,9 +249,9 @@ static int radeon_cs_get_ring(struct radeon_cs_parser *p, u32 ring, s32 priority
return 0; 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++) { for (i = 0; i < p->nrelocs; i++) {
struct reservation_object *resv; struct reservation_object *resv;
...@@ -260,9 +260,13 @@ static void radeon_cs_sync_rings(struct radeon_cs_parser *p) ...@@ -260,9 +260,13 @@ static void radeon_cs_sync_rings(struct radeon_cs_parser *p)
continue; continue;
resv = p->relocs[i].robj->tbo.resv; resv = p->relocs[i].robj->tbo.resv;
radeon_semaphore_sync_resv(p->ib.semaphore, resv, r = radeon_semaphore_sync_resv(p->rdev, p->ib.semaphore, resv,
p->relocs[i].tv.shared); p->relocs[i].tv.shared);
if (r)
break;
} }
return r;
} }
/* XXX: note that this is called from the legacy UMS CS ioctl as well */ /* 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, ...@@ -472,13 +476,19 @@ static int radeon_cs_ib_chunk(struct radeon_device *rdev,
return r; 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) if (parser->ring == R600_RING_TYPE_UVD_INDEX)
radeon_uvd_note_usage(rdev); radeon_uvd_note_usage(rdev);
else if ((parser->ring == TN_RING_TYPE_VCE1_INDEX) || else if ((parser->ring == TN_RING_TYPE_VCE1_INDEX) ||
(parser->ring == TN_RING_TYPE_VCE2_INDEX)) (parser->ring == TN_RING_TYPE_VCE2_INDEX))
radeon_vce_note_usage(rdev); radeon_vce_note_usage(rdev);
radeon_cs_sync_rings(parser);
r = radeon_ib_schedule(rdev, &parser->ib, NULL, true); r = radeon_ib_schedule(rdev, &parser->ib, NULL, true);
if (r) { if (r) {
DRM_ERROR("Failed to schedule IB !\n"); DRM_ERROR("Failed to schedule IB !\n");
...@@ -565,7 +575,13 @@ static int radeon_cs_ib_vm_chunk(struct radeon_device *rdev, ...@@ -565,7 +575,13 @@ static int radeon_cs_ib_vm_chunk(struct radeon_device *rdev,
if (r) { if (r) {
goto out; 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); radeon_semaphore_sync_fence(parser->ib.semaphore, vm->fence);
if ((rdev->family >= CHIP_TAHITI) && if ((rdev->family >= CHIP_TAHITI) &&
......
...@@ -541,6 +541,15 @@ int radeon_fence_wait(struct radeon_fence *fence, bool intr) ...@@ -541,6 +541,15 @@ int radeon_fence_wait(struct radeon_fence *fence, bool intr)
uint64_t seq[RADEON_NUM_RINGS] = {}; uint64_t seq[RADEON_NUM_RINGS] = {};
long r; 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; seq[fence->ring] = fence->seq;
r = radeon_fence_wait_seq_timeout(fence->rdev, seq, intr, MAX_SCHEDULE_TIMEOUT); r = radeon_fence_wait_seq_timeout(fence->rdev, seq, intr, MAX_SCHEDULE_TIMEOUT);
if (r < 0) { if (r < 0) {
......
...@@ -124,27 +124,42 @@ void radeon_semaphore_sync_fence(struct radeon_semaphore *semaphore, ...@@ -124,27 +124,42 @@ void radeon_semaphore_sync_fence(struct radeon_semaphore *semaphore,
* *
* Sync to the fence using this semaphore object * Sync to the fence using this semaphore object
*/ */
void radeon_semaphore_sync_resv(struct radeon_semaphore *sema, int radeon_semaphore_sync_resv(struct radeon_device *rdev,
struct reservation_object *resv, struct radeon_semaphore *sema,
bool shared) struct reservation_object *resv,
bool shared)
{ {
struct reservation_object_list *flist; struct reservation_object_list *flist;
struct fence *f; struct fence *f;
struct radeon_fence *fence;
unsigned i; unsigned i;
int r = 0;
/* always sync to the exclusive fence */ /* always sync to the exclusive fence */
f = reservation_object_get_excl(resv); 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); flist = reservation_object_get_list(resv);
if (shared || !flist) if (shared || !flist || r)
return; return r;
for (i = 0; i < flist->shared_count; ++i) { for (i = 0; i < flist->shared_count; ++i) {
f = rcu_dereference_protected(flist->shared[i], f = rcu_dereference_protected(flist->shared[i],
reservation_object_held(resv)); 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;
} }
/** /**
......
...@@ -698,7 +698,7 @@ int radeon_vm_update_page_directory(struct radeon_device *rdev, ...@@ -698,7 +698,7 @@ int radeon_vm_update_page_directory(struct radeon_device *rdev,
if (ib.length_dw != 0) { if (ib.length_dw != 0) {
radeon_asic_vm_pad_ib(rdev, &ib); 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); radeon_semaphore_sync_fence(ib.semaphore, vm->last_id_use);
WARN_ON(ib.length_dw > ndw); WARN_ON(ib.length_dw > ndw);
r = radeon_ib_schedule(rdev, &ib, NULL, false); r = radeon_ib_schedule(rdev, &ib, NULL, false);
...@@ -825,7 +825,7 @@ static void radeon_vm_update_ptes(struct radeon_device *rdev, ...@@ -825,7 +825,7 @@ static void radeon_vm_update_ptes(struct radeon_device *rdev,
unsigned nptes; unsigned nptes;
uint64_t pte; 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)) if ((addr & ~mask) == (end & ~mask))
nptes = end - addr; nptes = end - addr;
......
...@@ -67,7 +67,7 @@ struct radeon_fence *rv770_copy_dma(struct radeon_device *rdev, ...@@ -67,7 +67,7 @@ struct radeon_fence *rv770_copy_dma(struct radeon_device *rdev,
return ERR_PTR(r); 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_semaphore_sync_rings(rdev, sem, ring->idx);
for (i = 0; i < num_loops; i++) { for (i = 0; i < num_loops; i++) {
......
...@@ -252,7 +252,7 @@ struct radeon_fence *si_copy_dma(struct radeon_device *rdev, ...@@ -252,7 +252,7 @@ struct radeon_fence *si_copy_dma(struct radeon_device *rdev,
return ERR_PTR(r); 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_semaphore_sync_rings(rdev, sem, ring->idx);
for (i = 0; i < num_loops; i++) { for (i = 0; i < num_loops; i++) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment