From: Maarten Lankhorst <m.b.lankhorst@gmail.com>
To: dri-devel@lists.freedesktop.org
Cc: linaro-mm-sig@lists.linaro.org, linux-media@vger.kernel.org,
linux-kernel@vger.kernel.org,
Maarten Lankhorst <maarten.lankhorst@canonical.com>
Subject: [RFC PATCH 7/8] nouveau: nvc0 fence prime implementation
Date: Tue, 10 Jul 2012 12:57:50 +0200 [thread overview]
Message-ID: <1341917871-2512-8-git-send-email-m.b.lankhorst@gmail.com> (raw)
In-Reply-To: <1341917871-2512-1-git-send-email-m.b.lankhorst@gmail.com>
From: Maarten Lankhorst <maarten.lankhorst@canonical.com>
Create a read-only mapping for every imported bo, and create a prime
bo in in system memory.
Signed-off-by: Maarten Lankhorst <maarten.lankhorst@canonical.com>
---
drivers/gpu/drm/nouveau/nvc0_fence.c | 104 +++++++++++++++++++++++++++++-----
1 file changed, 89 insertions(+), 15 deletions(-)
diff --git a/drivers/gpu/drm/nouveau/nvc0_fence.c b/drivers/gpu/drm/nouveau/nvc0_fence.c
index 198e31f..dc6ccab 100644
--- a/drivers/gpu/drm/nouveau/nvc0_fence.c
+++ b/drivers/gpu/drm/nouveau/nvc0_fence.c
@@ -37,6 +37,7 @@ struct nvc0_fence_priv {
struct nvc0_fence_chan {
struct nouveau_fence_chan base;
struct nouveau_vma vma;
+ struct nouveau_vma prime_vma;
};
static int
@@ -45,19 +46,23 @@ nvc0_fence_emit(struct nouveau_fence *fence, bool prime)
struct nouveau_channel *chan = fence->channel;
struct nvc0_fence_chan *fctx = chan->engctx[NVOBJ_ENGINE_FENCE];
u64 addr = fctx->vma.offset + chan->id * 16;
- int ret;
+ int ret, i;
- ret = RING_SPACE(chan, 5);
- if (ret == 0) {
+ ret = RING_SPACE(chan, prime ? 10 : 5);
+ if (ret)
+ return ret;
+
+ for (i = 0; i < (prime ? 2 : 1); ++i) {
+ if (i)
+ addr = fctx->prime_vma.offset + chan->id * 16;
BEGIN_NVC0(chan, 0, NV84_SUBCHAN_SEMAPHORE_ADDRESS_HIGH, 4);
OUT_RING (chan, upper_32_bits(addr));
OUT_RING (chan, lower_32_bits(addr));
OUT_RING (chan, fence->sequence);
OUT_RING (chan, NV84_SUBCHAN_SEMAPHORE_TRIGGER_WRITE_LONG);
- FIRE_RING (chan);
}
-
- return ret;
+ FIRE_RING(chan);
+ return 0;
}
static int
@@ -95,6 +100,8 @@ nvc0_fence_context_del(struct nouveau_channel *chan, int engine)
struct nvc0_fence_priv *priv = nv_engine(chan->dev, engine);
struct nvc0_fence_chan *fctx = chan->engctx[engine];
+ if (priv->base.prime_bo)
+ nouveau_bo_vma_del(priv->base.prime_bo, &fctx->prime_vma);
nouveau_bo_vma_del(priv->bo, &fctx->vma);
nouveau_fence_context_del(chan->dev, &fctx->base);
chan->engctx[engine] = NULL;
@@ -115,10 +122,16 @@ nvc0_fence_context_new(struct nouveau_channel *chan, int engine)
nouveau_fence_context_new(&fctx->base);
ret = nouveau_bo_vma_add(priv->bo, chan->vm, &fctx->vma);
+ if (!ret && priv->base.prime_bo)
+ ret = nouveau_bo_vma_add(priv->base.prime_bo, chan->vm,
+ &fctx->prime_vma);
if (ret)
nvc0_fence_context_del(chan, engine);
- nouveau_bo_wr32(priv->bo, chan->id * 16/4, 0x00000000);
+ fctx->base.sequence = nouveau_bo_rd32(priv->bo, chan->id * 16/4);
+ if (priv->base.prime_bo)
+ nouveau_bo_wr32(priv->base.prime_bo, chan->id * 16/4,
+ fctx->base.sequence);
return ret;
}
@@ -140,12 +153,55 @@ nvc0_fence_destroy(struct drm_device *dev, int engine)
struct drm_nouveau_private *dev_priv = dev->dev_private;
struct nvc0_fence_priv *priv = nv_engine(dev, engine);
+ nouveau_fence_prime_del(&priv->base);
nouveau_bo_unmap(priv->bo);
+ nouveau_bo_unpin(priv->bo);
nouveau_bo_ref(NULL, &priv->bo);
dev_priv->eng[engine] = NULL;
kfree(priv);
}
+static int
+nvc0_fence_prime_sync(struct nouveau_channel *chan,
+ struct nouveau_bo *bo,
+ u32 ofs, u32 val, u64 sema_start)
+{
+ struct nvc0_fence_chan *fctx = chan->engctx[NVOBJ_ENGINE_FENCE];
+ struct nvc0_fence_priv *priv = nv_engine(chan->dev, NVOBJ_ENGINE_FENCE);
+ int ret = RING_SPACE(chan, 5);
+ if (ret)
+ return ret;
+
+ if (bo == priv->base.prime_bo)
+ sema_start = fctx->prime_vma.offset;
+ else
+ NV_ERROR(chan->dev, "syncing with %08Lx + %08x >= %08x\n",
+ sema_start, ofs, val);
+ sema_start += ofs;
+
+ BEGIN_NVC0(chan, 0, NV84_SUBCHAN_SEMAPHORE_ADDRESS_HIGH, 4);
+ OUT_RING (chan, upper_32_bits(sema_start));
+ OUT_RING (chan, lower_32_bits(sema_start));
+ OUT_RING (chan, val);
+ OUT_RING (chan, NV84_SUBCHAN_SEMAPHORE_TRIGGER_ACQUIRE_GEQUAL |
+ NVC0_SUBCHAN_SEMAPHORE_TRIGGER_YIELD);
+ FIRE_RING (chan);
+ return ret;
+}
+
+static void
+nvc0_fence_prime_del_import(struct nouveau_fence_prime_bo_entry *entry) {
+ nouveau_bo_vma_del(entry->bo, &entry->vma);
+}
+
+static int
+nvc0_fence_prime_add_import(struct nouveau_fence_prime_bo_entry *entry) {
+ int ret = nouveau_bo_vma_add_access(entry->bo, entry->chan->vm,
+ &entry->vma, NV_MEM_ACCESS_RO);
+ entry->sema_start = entry->vma.offset;
+ return ret;
+}
+
int
nvc0_fence_create(struct drm_device *dev)
{
@@ -168,17 +224,35 @@ nvc0_fence_create(struct drm_device *dev)
priv->base.read = nvc0_fence_read;
dev_priv->eng[NVOBJ_ENGINE_FENCE] = &priv->base.engine;
+ priv->base.prime_sync = nvc0_fence_prime_sync;
+ priv->base.prime_add_import = nvc0_fence_prime_add_import;
+ priv->base.prime_del_import = nvc0_fence_prime_del_import;
+
ret = nouveau_bo_new(dev, 16 * pfifo->channels, 0, TTM_PL_FLAG_VRAM,
0, 0, NULL, &priv->bo);
- if (ret == 0) {
- ret = nouveau_bo_pin(priv->bo, TTM_PL_FLAG_VRAM);
- if (ret == 0)
- ret = nouveau_bo_map(priv->bo);
- if (ret)
- nouveau_bo_ref(NULL, &priv->bo);
- }
+ if (ret)
+ goto err;
+ ret = nouveau_bo_pin(priv->bo, TTM_PL_FLAG_VRAM);
+ if (ret)
+ goto err_ref;
+ ret = nouveau_bo_map(priv->bo);
if (ret)
- nvc0_fence_destroy(dev, NVOBJ_ENGINE_FENCE);
+ goto err_unpin;
+
+ ret = nouveau_fence_prime_init(dev, &priv->base, 16);
+ if (ret)
+ goto err_unmap;
+ return 0;
+
+err_unmap:
+ nouveau_bo_unmap(priv->bo);
+err_unpin:
+ nouveau_bo_unpin(priv->bo);
+err_ref:
+ nouveau_bo_ref(NULL, &priv->bo);
+err:
+ dev_priv->eng[NVOBJ_ENGINE_FENCE] = NULL;
+ kfree(priv);
return ret;
}
--
1.7.9.5
next prev parent reply other threads:[~2012-07-10 10:59 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-07-10 10:57 [RFC PATCH 0/8] Dmabuf synchronization Maarten Lankhorst
2012-07-10 10:57 ` [RFC PATCH 1/8] dma-buf-mgr: Try 2 Maarten Lankhorst
2012-07-10 10:57 ` [RFC PATCH 2/8] prime wip: i915 Maarten Lankhorst
2012-07-10 10:57 ` [RFC PATCH 3/8] nouveau: Extend prime code Maarten Lankhorst
2012-07-10 10:57 ` [RFC PATCH 4/8] nouveau: add nouveau_bo_vma_add_access Maarten Lankhorst
2012-07-10 10:57 ` [RFC PATCH 5/8] nouveau: Add methods preparing for prime fencing Maarten Lankhorst
2012-07-10 10:57 ` [RFC PATCH 6/8] nouveau: nv84 fence prime implementation Maarten Lankhorst
2012-07-10 10:57 ` Maarten Lankhorst [this message]
2012-07-10 10:57 ` [RFC PATCH 8/8] nouveau: Prime execbuffer submission synchronization Maarten Lankhorst
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1341917871-2512-8-git-send-email-m.b.lankhorst@gmail.com \
--to=m.b.lankhorst@gmail.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=linaro-mm-sig@lists.linaro.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=maarten.lankhorst@canonical.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®