drm/nvc0/fence: restore pre-suspend fence buffer context on resume
authorBen Skeggs <bskeggs@redhat.com>
Fri, 28 Sep 2012 01:50:29 +0000 (11:50 +1000)
committerBen Skeggs <bskeggs@redhat.com>
Wed, 3 Oct 2012 03:12:22 +0000 (13:12 +1000)
Fixes some unfortunate races on resume.  The G84 version of the code doesn't
need this as "gpuobj"s are automagically suspended/resumed by the core code
whereas pinned buffer objects are not.

Cc: stable@vger.kernel.org
Signed-off-by: Ben Skeggs <bskeggs@redhat.com>
drivers/gpu/drm/nouveau/nvc0_fence.c

index 47ab388a606e83facae6bfe5a8452cfe6ad757fa..8e5a2f407ed4d165527e96929c2a3e806baab52c 100644 (file)
@@ -32,6 +32,7 @@
 struct nvc0_fence_priv {
        struct nouveau_fence_priv base;
        struct nouveau_bo *bo;
+       u32 *suspend;
 };
 
 struct nvc0_fence_chan {
@@ -125,12 +126,36 @@ nvc0_fence_context_new(struct nouveau_channel *chan, int engine)
 static int
 nvc0_fence_fini(struct drm_device *dev, int engine, bool suspend)
 {
+       struct nouveau_fifo_priv *pfifo = nv_engine(dev, NVOBJ_ENGINE_FIFO);
+       struct nvc0_fence_priv *priv = nv_engine(dev, engine);
+       int i;
+
+       if (suspend) {
+               priv->suspend = vmalloc(pfifo->channels * sizeof(u32));
+               if (!priv->suspend)
+                       return -ENOMEM;
+
+               for (i = 0; i < pfifo->channels; i++)
+                       priv->suspend[i] = nouveau_bo_rd32(priv->bo, i);
+       }
+
        return 0;
 }
 
 static int
 nvc0_fence_init(struct drm_device *dev, int engine)
 {
+       struct nouveau_fifo_priv *pfifo = nv_engine(dev, NVOBJ_ENGINE_FIFO);
+       struct nvc0_fence_priv *priv = nv_engine(dev, engine);
+       int i;
+
+       if (priv->suspend) {
+               for (i = 0; i < pfifo->channels; i++)
+                       nouveau_bo_wr32(priv->bo, i, priv->suspend[i]);
+               vfree(priv->suspend);
+               priv->suspend = NULL;
+       }
+
        return 0;
 }