Skip to contentSkip to conversation

drm/nv50: align size of buffer object to the right boundaries.

PATCH In review Maarten Maathuis 1 participant 10 messages Feb 2, 2010 – Feb 4, 2010 8 messages not in the archive

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/6 drm/nv50: align size of buffer object to the right boundaries.

- In the current situation the padding that is added is dangerous to write to, userspace could potentially overwrite parts of another bo.
- Depth and stencil buffers are supposed to be large enough in general so the waste of memory should be acceptable.
- Alternatives are hiding the padding from users or splitting vram into 2 zones.

---
 drivers/gpu/drm/nouveau/nouveau_bo.c |   10 +++++-----
 1 files changed, 5 insertions(+), 5 deletions(-)
drivers/gpu/drm/nouveau/nouveau_bo.c +5 -5
index db0ed4c..028719f 100644
@@ -65,8 +65,10 @@ nouveau_bo_fixup_align(struct drm_device *dev,
 
 	/*
 	 * Some of the tile_flags have a periodic structure of N*4096 bytes,
-	 * align to to that as well as the page size. Overallocate memory to
-	 * avoid corruption of other buffer objects.
+	 * align to to that as well as the page size. Align the size to the
+	 * appropriate boundaries. This does imply that sizes are rounded up
+	 * 3-7 pages, so be aware of this and do not waste memory by allocating
+	 * many small buffers.
 	 */
 	if (dev_priv->card_type == NV_50) {
 		uint32_t block_size = nouveau_mem_fb_amount(dev) >> 15;
@@ -77,22 +79,20 @@ nouveau_bo_fixup_align(struct drm_device *dev,
 		case 0x2800:
 		case 0x4800:
 		case 0x7a00:
-			*size = roundup(*size, block_size);
 			if (is_power_of_2(block_size)) {
-				*size += 3 * block_size;
 				for (i = 1; i < 10; i++) {
 					*align = 12 * i * block_size;
 					if (!(*align % 65536))
 						break;
 				}
 			} else {
-				*size += 6 * block_size;
 				for (i = 1; i < 10; i++) {
 					*align = 8 * i * block_size;
 					if (!(*align % 65536))
 						break;
 				}
 			}
+			*size = roundup(*size, *align);
 			break;
 		default:
 			break;
Signature · 1 line
1.6.6.1

A message that is not in the archive (sent off-list or not yet received): 1265146565-6048-1-git-send-email-madman2003-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org

#2 lore raw

PATCH 2/6 drm/nv50: avoid unloading pgraph context when ctxprog is running

- We need to disable pgraph fifo access before checking the current channel, otherwise we could still hit a running ctxprog.
- The writes to 0x400500 are already handled by pgraph->fifo_access and are therefore redundant, moreover pgraph fifo access should not be reenabled before current context is set as invalid. So remove them altogether.

---
 drivers/gpu/drm/nouveau/nouveau_channel.c |    7 +++----
 drivers/gpu/drm/nouveau/nv50_graph.c      |   10 +++++++---
 2 files changed, 10 insertions(+), 7 deletions(-)
drivers/gpu/drm/nouveau/nouveau_channel.c +3 -4
index 343d718..2281f99 100644
@@ -278,12 +278,11 @@ nouveau_channel_free(struct nouveau_channel *chan)
 	/* Ensure the channel is no longer active on the GPU */
 	pfifo->reassign(dev, false);
 
-	if (pgraph->channel(dev) == chan) {
-		pgraph->fifo_access(dev, false);
+	pgraph->fifo_access(dev, false);
+	if (pgraph->channel(dev) == chan)
 		pgraph->unload_context(dev);
-		pgraph->fifo_access(dev, true);
-	}
 	pgraph->destroy_context(chan);
+	pgraph->fifo_access(dev, true);
 
 	if (pfifo->channel_id(dev) == chan->id) {
 		pfifo->disable(dev);
drivers/gpu/drm/nouveau/nv50_graph.c +7 -3
index 20319e5..6d50480 100644
@@ -165,6 +165,12 @@ nv50_graph_channel(struct drm_device *dev)
 	uint32_t inst;
 	int i;
 
+	/* Be sure we're not in the middle of a context switch or bad things
+	 * will happen, such as unloading the wrong pgraph context.
+	 */
+	if (!nv_wait(0x400300, 0x00000001, 0x00000000))
+		NV_ERROR(dev, "Ctxprog is still running\n");
+
 	inst = nv_rd32(dev, NV50_PGRAPH_CTXCTL_CUR);
 	if (!(inst & NV50_PGRAPH_CTXCTL_CUR_LOADED))
 		return NULL;
@@ -275,7 +281,7 @@ nv50_graph_load_context(struct nouveau_channel *chan)
 int
 nv50_graph_unload_context(struct drm_device *dev)
 {
-	uint32_t inst, fifo = nv_rd32(dev, 0x400500);
+	uint32_t inst;
 
 	inst  = nv_rd32(dev, NV50_PGRAPH_CTXCTL_CUR);
 	if (!(inst & NV50_PGRAPH_CTXCTL_CUR_LOADED))
@@ -283,12 +289,10 @@ nv50_graph_unload_context(struct drm_device *dev)
 	inst &= NV50_PGRAPH_CTXCTL_CUR_INSTANCE;
 
 	nouveau_wait_for_idle(dev);
-	nv_wr32(dev, 0x400500, fifo & ~1);
 	nv_wr32(dev, 0x400784, inst);
 	nv_wr32(dev, 0x400824, nv_rd32(dev, 0x400824) | 0x20);
 	nv_wr32(dev, 0x400304, nv_rd32(dev, 0x400304) | 0x01);
 	nouveau_wait_for_idle(dev);
-	nv_wr32(dev, 0x400500, fifo);
 
 	nv_wr32(dev, NV50_PGRAPH_CTXCTL_CUR, inst);
 	return 0;
Signature · 1 line
1.6.6.1

A message that is not in the archive (sent off-list or not yet received): 1265146565-6048-2-git-send-email-madman2003-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org

#4 lore raw

PATCH 3/6 drm/nv50: delete ramfc object after disabling fifo, not before

- ramfc is zero'ed upon destruction, so it's safer to do things in the right order.

---
 drivers/gpu/drm/nouveau/nv50_fifo.c |    9 ++++++---
 1 files changed, 6 insertions(+), 3 deletions(-)
drivers/gpu/drm/nouveau/nv50_fifo.c +6 -3
index 32b244b..204a79f 100644
@@ -317,17 +317,20 @@ void
 nv50_fifo_destroy_context(struct nouveau_channel *chan)
 {
 	struct drm_device *dev = chan->dev;
+	struct nouveau_gpuobj_ref *ramfc = chan->ramfc;
 
 	NV_DEBUG(dev, "ch%d\n", chan->id);
 
-	nouveau_gpuobj_ref_del(dev, &chan->ramfc);
-	nouveau_gpuobj_ref_del(dev, &chan->cache);
-
+	/* This will ensure the channel is seen as disabled. */
+	chan->ramfc = NULL;
 	nv50_fifo_channel_disable(dev, chan->id, false);
 
 	/* Dummy channel, also used on ch 127 */
 	if (chan->id == 0)
 		nv50_fifo_channel_disable(dev, 127, false);
+
+	nouveau_gpuobj_ref_del(dev, &ramfc);
+	nouveau_gpuobj_ref_del(dev, &chan->cache);
 }
 
 int
Signature · 1 line
1.6.6.1

A message that is not in the archive (sent off-list or not yet received): 1265146565-6048-3-git-send-email-madman2003-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org

#6 lore raw

PATCH 4/6 drm/nouveau: protect channel create/destroy and irq handler with a spin lock

- The nv50 pgraph handler (for example) could reenable pgraph fifo access and that would be bad when pgraph context is being unloaded (we need the garuantee a ctxprog isn't running).

---
 drivers/gpu/drm/nouveau/nouveau_channel.c |    9 +++++++++
 drivers/gpu/drm/nouveau/nouveau_drv.h     |    1 +
 drivers/gpu/drm/nouveau/nouveau_irq.c     |    5 +++++
 drivers/gpu/drm/nouveau/nouveau_state.c   |    1 +
 4 files changed, 16 insertions(+), 0 deletions(-)
drivers/gpu/drm/nouveau/nouveau_channel.c +9 -0
index 2281f99..86399f6 100644
@@ -113,6 +113,7 @@ nouveau_channel_alloc(struct drm_device *dev, struct nouveau_channel **chan_ret,
 	struct nouveau_pgraph_engine *pgraph = &dev_priv->engine.graph;
 	struct nouveau_fifo_engine *pfifo = &dev_priv->engine.fifo;
 	struct nouveau_channel *chan;
+	unsigned long flags;
 	int channel, user;
 	int ret;
 
@@ -203,6 +204,8 @@ nouveau_channel_alloc(struct drm_device *dev, struct nouveau_channel **chan_ret,
 		return ret;
 	}
 
+	spin_lock_irqsave(&dev_priv->engine.lock, flags);
+
 	/* disable the fifo caches */
 	pfifo->reassign(dev, false);
 
@@ -222,6 +225,8 @@ nouveau_channel_alloc(struct drm_device *dev, struct nouveau_channel **chan_ret,
 
 	pfifo->reassign(dev, true);
 
+	spin_unlock_irqrestore(&dev_priv->engine.lock, flags);
+
 	ret = nouveau_dma_init(chan);
 	if (!ret)
 		ret = nouveau_fence_init(chan);
@@ -275,6 +280,8 @@ nouveau_channel_free(struct nouveau_channel *chan)
 	 */
 	nouveau_fence_fini(chan);
 
+	spin_lock_irqsave(&dev_priv->engine.lock, flags);
+
 	/* Ensure the channel is no longer active on the GPU */
 	pfifo->reassign(dev, false);
 
@@ -293,6 +300,8 @@ nouveau_channel_free(struct nouveau_channel *chan)
 
 	pfifo->reassign(dev, true);
 
+	spin_unlock_irqrestore(&dev_priv->engine.lock, flags);
+
 	/* Release the channel's resources */
 	nouveau_gpuobj_ref_del(dev, &chan->pushbuf);
 	if (chan->pushbuf_bo) {
drivers/gpu/drm/nouveau/nouveau_drv.h +1 -0
index 5445cef..64987a9 100644
@@ -358,6 +358,7 @@ struct nouveau_engine {
 	struct nouveau_fb_engine      fb;
 	struct nouveau_pgraph_engine  graph;
 	struct nouveau_fifo_engine    fifo;
+	spinlock_t lock;
 };
 
 struct nouveau_pll_vals {
drivers/gpu/drm/nouveau/nouveau_irq.c +5 -0
index baa9b3e..3e46b85 100644
@@ -678,11 +678,14 @@ nouveau_irq_handler(DRM_IRQ_ARGS)
 	struct drm_device *dev = (struct drm_device *)arg;
 	struct drm_nouveau_private *dev_priv = dev->dev_private;
 	uint32_t status, fbdev_flags = 0;
+	unsigned long flags;
 
 	status = nv_rd32(dev, NV03_PMC_INTR_0);
 	if (!status)
 		return IRQ_NONE;
 
+	spin_lock_irqsave(&dev_priv->engine.lock, flags);
+
 	if (dev_priv->fbdev_info) {
 		fbdev_flags = dev_priv->fbdev_info->flags;
 		dev_priv->fbdev_info->flags |= FBINFO_HWACCEL_DISABLED;
@@ -720,5 +723,7 @@ nouveau_irq_handler(DRM_IRQ_ARGS)
 	if (dev_priv->fbdev_info)
 		dev_priv->fbdev_info->flags = fbdev_flags;
 
+	spin_unlock_irqrestore(&dev_priv->engine.lock, flags);
+
 	return IRQ_HANDLED;
 }
drivers/gpu/drm/nouveau/nouveau_state.c +1 -0
index fcd7610..3586667 100644
@@ -383,6 +383,7 @@ nouveau_card_init(struct drm_device *dev)
 		goto out;
 	engine = &dev_priv->engine;
 	dev_priv->init_state = NOUVEAU_CARD_INIT_FAILED;
+	spin_lock_init(&dev_priv->engine.lock);
 
 	/* Parse BIOS tables / Run init tables if card not POSTed */
 	if (drm_core_check_feature(dev, DRIVER_MODESET)) {
Signature · 1 line
1.6.6.1

A message that is not in the archive (sent off-list or not yet received): 1265146565-6048-4-git-send-email-madman2003-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org

#8 lore raw

PATCH 5/6 drm/nv50: make the pgraph irq handler loop like the pre-nv50 version

- Unset the bit that indicates that a ctxprog can continue at the end.

---
 drivers/gpu/drm/nouveau/nouveau_irq.c |  139 ++++++++++++++++++---------------
 1 files changed, 75 insertions(+), 64 deletions(-)
drivers/gpu/drm/nouveau/nouveau_irq.c +75 -64
index 3e46b85..e21bec3 100644
@@ -580,86 +580,97 @@ nouveau_pgraph_irq_handler(struct drm_device *dev)
 static void
 nv50_pgraph_irq_handler(struct drm_device *dev)
 {
-	uint32_t status, nsource;
+	uint32_t status;
 
-	status = nv_rd32(dev, NV03_PGRAPH_INTR);
-	nsource = nv_rd32(dev, NV03_PGRAPH_NSOURCE);
+	while ((status = nv_rd32(dev, NV03_PGRAPH_INTR))) {
+		uint32_t nsource = nv_rd32(dev, NV03_PGRAPH_NSOURCE);
 
-	if (status & 0x00000001) {
-		nouveau_pgraph_intr_notify(dev, nsource);
-		status &= ~0x00000001;
-		nv_wr32(dev, NV03_PGRAPH_INTR, 0x00000001);
-	}
+		if (status & 0x00000001) {
+			nouveau_pgraph_intr_notify(dev, nsource);
+			status &= ~0x00000001;
+			nv_wr32(dev, NV03_PGRAPH_INTR, 0x00000001);
+		}
 
-	if (status & 0x00000010) {
-		nouveau_pgraph_intr_error(dev, nsource |
-					  NV03_PGRAPH_NSOURCE_ILLEGAL_MTHD);
+		if (status & 0x00000010) {
+			nouveau_pgraph_intr_error(dev, nsource |
+						  NV03_PGRAPH_NSOURCE_ILLEGAL_MTHD);
 
-		status &= ~0x00000010;
-		nv_wr32(dev, NV03_PGRAPH_INTR, 0x00000010);
-	}
+			status &= ~0x00000010;
+			nv_wr32(dev, NV03_PGRAPH_INTR, 0x00000010);
+		}
 
-	if (status & 0x00001000) {
-		nv_wr32(dev, 0x400500, 0x00000000);
-		nv_wr32(dev, NV03_PGRAPH_INTR, NV_PGRAPH_INTR_CONTEXT_SWITCH);
-		nv_wr32(dev, NV40_PGRAPH_INTR_EN, nv_rd32(dev,
-			NV40_PGRAPH_INTR_EN) & ~NV_PGRAPH_INTR_CONTEXT_SWITCH);
-		nv_wr32(dev, 0x400500, 0x00010001);
+		if (status & 0x00001000) {
+			nv_wr32(dev, 0x400500, 0x00000000);
+			nv_wr32(dev, NV03_PGRAPH_INTR, NV_PGRAPH_INTR_CONTEXT_SWITCH);
+			nv_wr32(dev, NV40_PGRAPH_INTR_EN, nv_rd32(dev,
+				NV40_PGRAPH_INTR_EN) & ~NV_PGRAPH_INTR_CONTEXT_SWITCH);
+			nv_wr32(dev, 0x400500, 0x00010001);
 
-		nv50_graph_context_switch(dev);
+			nv50_graph_context_switch(dev);
 
-		status &= ~NV_PGRAPH_INTR_CONTEXT_SWITCH;
-	}
+			status &= ~NV_PGRAPH_INTR_CONTEXT_SWITCH;
+		}
 
-	if (status & 0x00100000) {
-		nouveau_pgraph_intr_error(dev, nsource |
-					  NV03_PGRAPH_NSOURCE_DATA_ERROR);
+		if (status & 0x00100000) {
+			nouveau_pgraph_intr_error(dev, nsource |
+						  NV03_PGRAPH_NSOURCE_DATA_ERROR);
 
-		status &= ~0x00100000;
-		nv_wr32(dev, NV03_PGRAPH_INTR, 0x00100000);
-	}
+			status &= ~0x00100000;
+			nv_wr32(dev, NV03_PGRAPH_INTR, 0x00100000);
+		}
 
-	if (status & 0x00200000) {
-		int r;
-
-		nouveau_pgraph_intr_error(dev, nsource |
-					  NV03_PGRAPH_NSOURCE_PROTECTION_ERROR);
-
-		NV_ERROR(dev, "magic set 1:\n");
-		for (r = 0x408900; r <= 0x408910; r += 4)
-			NV_ERROR(dev, "\t0x%08x: 0x%08x\n", r, nv_rd32(dev, r));
-		nv_wr32(dev, 0x408900, nv_rd32(dev, 0x408904) | 0xc0000000);
-		for (r = 0x408e08; r <= 0x408e24; r += 4)
-			NV_ERROR(dev, "\t0x%08x: 0x%08x\n", r, nv_rd32(dev, r));
-		nv_wr32(dev, 0x408e08, nv_rd32(dev, 0x408e08) | 0xc0000000);
-
-		NV_ERROR(dev, "magic set 2:\n");
-		for (r = 0x409900; r <= 0x409910; r += 4)
-			NV_ERROR(dev, "\t0x%08x: 0x%08x\n", r, nv_rd32(dev, r));
-		nv_wr32(dev, 0x409900, nv_rd32(dev, 0x409904) | 0xc0000000);
-		for (r = 0x409e08; r <= 0x409e24; r += 4)
-			NV_ERROR(dev, "\t0x%08x: 0x%08x\n", r, nv_rd32(dev, r));
-		nv_wr32(dev, 0x409e08, nv_rd32(dev, 0x409e08) | 0xc0000000);
-
-		status &= ~0x00200000;
-		nv_wr32(dev, NV03_PGRAPH_NSOURCE, nsource);
-		nv_wr32(dev, NV03_PGRAPH_INTR, 0x00200000);
-	}
+		if (status & 0x00200000) {
+			int r;
+
+			nouveau_pgraph_intr_error(dev, nsource |
+					NV03_PGRAPH_NSOURCE_PROTECTION_ERROR);
+
+			NV_ERROR(dev, "magic set 1:\n");
+			for (r = 0x408900; r <= 0x408910; r += 4)
+				NV_ERROR(dev, "\t0x%08x: 0x%08x\n", r,
+					nv_rd32(dev, r));
+			nv_wr32(dev, 0x408900,
+				nv_rd32(dev, 0x408904) | 0xc0000000);
+			for (r = 0x408e08; r <= 0x408e24; r += 4)
+				NV_ERROR(dev, "\t0x%08x: 0x%08x\n", r,
+							nv_rd32(dev, r));
+			nv_wr32(dev, 0x408e08,
+				nv_rd32(dev, 0x408e08) | 0xc0000000);
+
+			NV_ERROR(dev, "magic set 2:\n");
+			for (r = 0x409900; r <= 0x409910; r += 4)
+				NV_ERROR(dev, "\t0x%08x: 0x%08x\n", r,
+					nv_rd32(dev, r));
+			nv_wr32(dev, 0x409900,
+				nv_rd32(dev, 0x409904) | 0xc0000000);
+			for (r = 0x409e08; r <= 0x409e24; r += 4)
+				NV_ERROR(dev, "\t0x%08x: 0x%08x\n", r,
+					nv_rd32(dev, r));
+			nv_wr32(dev, 0x409e08,
+				nv_rd32(dev, 0x409e08) | 0xc0000000);
+
+			status &= ~0x00200000;
+			nv_wr32(dev, NV03_PGRAPH_NSOURCE, nsource);
+			nv_wr32(dev, NV03_PGRAPH_INTR, 0x00200000);
+		}
 
-	if (status) {
-		NV_INFO(dev, "Unhandled PGRAPH_INTR - 0x%08x\n", status);
-		nv_wr32(dev, NV03_PGRAPH_INTR, status);
-	}
+		if (status) {
+			NV_INFO(dev, "Unhandled PGRAPH_INTR - 0x%08x\n",
+				status);
+			nv_wr32(dev, NV03_PGRAPH_INTR, status);
+		}
 
-	{
-		const int isb = (1 << 16) | (1 << 0);
+		{
+			const int isb = (1 << 16) | (1 << 0);
 
-		if ((nv_rd32(dev, 0x400500) & isb) != isb)
-			nv_wr32(dev, 0x400500, nv_rd32(dev, 0x400500) | isb);
-		nv_wr32(dev, 0x400824, nv_rd32(dev, 0x400824) & ~(1 << 31));
+			if ((nv_rd32(dev, 0x400500) & isb) != isb)
+				nv_wr32(dev, 0x400500,
+					nv_rd32(dev, 0x400500) | isb);
+		}
 	}
 
 	nv_wr32(dev, NV03_PMC_INTR_0, NV_PMC_INTR_0_PGRAPH_PENDING);
+	nv_wr32(dev, 0x400824, nv_rd32(dev, 0x400824) & ~(1 << 31));
 }
 
 static void
Signature · 1 line
1.6.6.1

A message that is not in the archive (sent off-list or not yet received): 1265146565-6048-5-git-send-email-madman2003-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org

#10 lore raw

PATCH 6/6 drm/nouveau: give pgraph a chance to idle before spinlock

- Under some rare conditions i've managed to get pgraph errors after the channel is closed, which has very undesirable effects.
- This is the only reason i can think off.

---
 drivers/gpu/drm/nouveau/nouveau_channel.c |   13 ++++++++++---
 1 files changed, 10 insertions(+), 3 deletions(-)
drivers/gpu/drm/nouveau/nouveau_channel.c +10 -3
index 86399f6..d25ed61 100644
@@ -280,11 +280,18 @@ nouveau_channel_free(struct nouveau_channel *chan)
 	 */
 	nouveau_fence_fini(chan);
 
-	spin_lock_irqsave(&dev_priv->engine.lock, flags);
-
-	/* Ensure the channel is no longer active on the GPU */
+	/* This will prevent pfifo from switching channels. */
 	pfifo->reassign(dev, false);
 
+	/* We want to give pgraph a chance to idle and get rid of all potential
+	 * errors. We need to do this before the lock, otherwise the irq handler
+	 * is unable to process them.
+	 */
+	if (pgraph->channel(dev) == chan)
+		nouveau_wait_for_idle(dev);
+
+	spin_lock_irqsave(&dev_priv->engine.lock, flags);
+
 	pgraph->fifo_access(dev, false);
 	if (pgraph->channel(dev) == chan)
 		pgraph->unload_context(dev);
Signature · 1 line
1.6.6.1

A message that is not in the archive (sent off-list or not yet received): 1265146565-6048-6-git-send-email-madman2003-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org

#12 lore raw

Re: [PATCH 6/6] drm/nouveau: give pgraph a chance to idle before spinlock

Patches 4-6 will be pushed tomorrow if there are no objections.

Acks or comments appreciated as usual.

Maarten.

Quoted 39 lines · Maarten Maathuis

- Under some rare conditions i've managed to get pgraph errors after the channel is closed, which has very undesirable effects.
- This is the only reason i can think off.

---
 drivers/gpu/drm/nouveau/nouveau_channel.c |   13 ++++++++++---

 1 files changed, 10 insertions(+), 3 deletions(-)
drivers/gpu/drm/nouveau/nouveau_channel.c +10 -4
index 86399f6..d25ed61 100644
@@ -280,11 +280,18 @@ nouveau_channel_free(struct nouveau_channel *chan)
         */
        nouveau_fence_fini(chan);
 
-       spin_lock_irqsave(&dev_priv->engine.lock, flags);
-
-       /* Ensure the channel is no longer active on the GPU */
+       /* This will prevent pfifo from switching channels. */
        pfifo->reassign(dev, false);
 
+       /* We want to give pgraph a chance to idle and get rid of all potential
+        * errors. We need to do this before the lock, otherwise the irq handler
+        * is unable to process them.
+        */
+       if (pgraph->channel(dev) == chan)
+               nouveau_wait_for_idle(dev);
+
+       spin_lock_irqsave(&dev_priv->engine.lock, flags);
+
        pgraph->fifo_access(dev, false);
        if (pgraph->channel(dev) == chan)
                pgraph->unload_context(dev);
--

1.6.6.1

A message that is not in the archive (sent off-list or not yet received): 6d4bc9fc1002031002w18832748k1b62344dbe55adce-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org

#14 lore raw

Re: [PATCH 6/6] drm/nouveau: give pgraph a chance to idle before spinlock

Pushed as announced, with a few minor style changes that checkpatch pointed out.

Quoted 47 lines · Maarten Maathuis

Patches 4-6 will be pushed tomorrow if there are no objections.

Acks or comments appreciated as usual.

Maarten.

Quoted 39 lines · Maarten Maathuis

- Under some rare conditions i've managed to get pgraph errors after the channel is closed, which has very undesirable effects.
- This is the only reason i can think off.

---
 drivers/gpu/drm/nouveau/nouveau_channel.c |   13 ++++++++++---

 1 files changed, 10 insertions(+), 3 deletions(-)
drivers/gpu/drm/nouveau/nouveau_channel.c +10 -4
index 86399f6..d25ed61 100644
@@ -280,11 +280,18 @@ nouveau_channel_free(struct nouveau_channel *chan)
         */
        nouveau_fence_fini(chan);
 
-       spin_lock_irqsave(&dev_priv->engine.lock, flags);
-
-       /* Ensure the channel is no longer active on the GPU */
+       /* This will prevent pfifo from switching channels. */
        pfifo->reassign(dev, false);
 
+       /* We want to give pgraph a chance to idle and get rid of all potential
+        * errors. We need to do this before the lock, otherwise the irq handler
+        * is unable to process them.
+        */
+       if (pgraph->channel(dev) == chan)
+               nouveau_wait_for_idle(dev);
+
+       spin_lock_irqsave(&dev_priv->engine.lock, flags);
+
        pgraph->fifo_access(dev, false);
        if (pgraph->channel(dev) == chan)
                pgraph->unload_context(dev);
--

1.6.6.1

#15 lore raw

Re: [PATCH 3/6] drm/nv50: delete ramfc object after disabling fifo, not before

In reply to a message not in the archive

I intend to push patch 1-3 tomorrow if there are no objections.

Acks are appreciated as usual.

Quoted 40 lines · Maarten Maathuis

- ramfc is zero'ed upon destruction, so it's safer to do things in the right order.

---
 drivers/gpu/drm/nouveau/nv50_fifo.c |    9 ++++++---

 1 files changed, 6 insertions(+), 3 deletions(-)
drivers/gpu/drm/nouveau/nv50_fifo.c +6 -3
index 32b244b..204a79f 100644
@@ -317,17 +317,20 @@ void
  nv50_fifo_destroy_context(struct nouveau_channel *chan)
  {
        struct drm_device *dev = chan->dev;
+       struct nouveau_gpuobj_ref *ramfc = chan->ramfc;
 
        NV_DEBUG(dev, "ch%d\n", chan->id);
 
-       nouveau_gpuobj_ref_del(dev, &chan->ramfc);
-       nouveau_gpuobj_ref_del(dev, &chan->cache);
-
+       /* This will ensure the channel is seen as disabled. */
+       chan->ramfc = NULL;
        nv50_fifo_channel_disable(dev, chan->id, false);
 
        /* Dummy channel, also used on ch 127 */
        if (chan->id == 0)
                nv50_fifo_channel_disable(dev, 127, false);
+
+       nouveau_gpuobj_ref_del(dev, &ramfc);
+       nouveau_gpuobj_ref_del(dev, &chan->cache);
  }
 

 int
--
1.6.6.1

A message that is not in the archive (sent off-list or not yet received): 6d4bc9fc1002021337n781618bfkd4e7220eb832fc21-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org

#17 lore raw

Re: [PATCH 3/6] drm/nv50: delete ramfc object after disabling fifo, not before

1-3 pushed as announced.

Quoted 46 lines · Maarten Maathuis

I intend to push patch 1-3 tomorrow if there are no objections.

Acks are appreciated as usual.

Quoted 40 lines · Maarten Maathuis

- ramfc is zero'ed upon destruction, so it's safer to do things in the right order.

---
 drivers/gpu/drm/nouveau/nv50_fifo.c |    9 ++++++---

 1 files changed, 6 insertions(+), 3 deletions(-)
drivers/gpu/drm/nouveau/nv50_fifo.c +6 -3
index 32b244b..204a79f 100644
@@ -317,17 +317,20 @@ void
  nv50_fifo_destroy_context(struct nouveau_channel *chan)
  {
        struct drm_device *dev = chan->dev;
+       struct nouveau_gpuobj_ref *ramfc = chan->ramfc;
 
        NV_DEBUG(dev, "ch%d\n", chan->id);
 
-       nouveau_gpuobj_ref_del(dev, &chan->ramfc);
-       nouveau_gpuobj_ref_del(dev, &chan->cache);
-
+       /* This will ensure the channel is seen as disabled. */
+       chan->ramfc = NULL;
        nv50_fifo_channel_disable(dev, chan->id, false);
 
        /* Dummy channel, also used on ch 127 */
        if (chan->id == 0)
                nv50_fifo_channel_disable(dev, 127, false);
+
+       nouveau_gpuobj_ref_del(dev, &ramfc);
+       nouveau_gpuobj_ref_del(dev, &chan->cache);
  }
 

 int
--
1.6.6.1