From patchwork Tue Jul 10 10:57:49 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maarten Lankhorst X-Patchwork-Id: 1176921 Return-Path: X-Original-To: patchwork-dri-devel@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by patchwork2.kernel.org (Postfix) with ESMTP id 861C6DFF34 for ; Tue, 10 Jul 2012 11:06:22 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 4673EA0990 for ; Tue, 10 Jul 2012 04:06:22 -0700 (PDT) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-ey0-f177.google.com (mail-ey0-f177.google.com [209.85.215.177]) by gabe.freedesktop.org (Postfix) with ESMTP id ECA739EC0F for ; Tue, 10 Jul 2012 03:58:34 -0700 (PDT) Received: by mail-ey0-f177.google.com with SMTP id f11so4612614eaa.36 for ; Tue, 10 Jul 2012 03:58:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references; bh=6NkYel9b3eECSGeuktXg2lz+SDKMH6PIDCmJwjCvDow=; b=AqaqPZt+IvA4UczuJXzUKYnu2NxzNJe3Q5gcGs1QQIpNXQo26y6c7Lb5jDOfjiAzNV I+E4Ah5YRRjvDTMpxSIQX3AXaJFfDooUwHrC9qnKYH4ACZDKOkBe5YwvNHJ9GvZbuXqa QeefnggiPyGvWXUH3ZMjUidilQsfSgyRTSkMfMUFHeh+wNfZHbmL0t759P+8pSV/tWWj ernmXreBnGpGMqS46Jq/7j5mIdtmVS10GkdHVprapxHimKIpSrjt40MQteJvR9v9xRNY HgtqPwebbcJ/iYP3bXa5QR6/xAY3TJDRtvimmUZjGm43PDdJJ+J+SRtzZ+IHbhtcekQ7 IphA== Received: by 10.14.99.201 with SMTP id x49mr8734340eef.142.1341917914322; Tue, 10 Jul 2012 03:58:34 -0700 (PDT) Received: from localhost (5ED48CEF.cm-7-5c.dynamic.ziggo.nl. [94.212.140.239]) by mx.google.com with ESMTPS id e48sm101493787eea.12.2012.07.10.03.58.29 (version=TLSv1/SSLv3 cipher=OTHER); Tue, 10 Jul 2012 03:58:32 -0700 (PDT) Received: by localhost (sSMTP sendmail emulation); Tue, 10 Jul 2012 12:58:28 +0200 From: Maarten Lankhorst To: dri-devel@lists.freedesktop.org Subject: [RFC PATCH 6/8] nouveau: nv84 fence prime implementation Date: Tue, 10 Jul 2012 12:57:49 +0200 Message-Id: <1341917871-2512-7-git-send-email-m.b.lankhorst@gmail.com> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1341917871-2512-1-git-send-email-m.b.lankhorst@gmail.com> References: <1341917871-2512-1-git-send-email-m.b.lankhorst@gmail.com> Cc: linaro-mm-sig@lists.linaro.org, Maarten Lankhorst , linux-kernel@vger.kernel.org, linux-media@vger.kernel.org X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: dri-devel-bounces+patchwork-dri-devel=patchwork.kernel.org@lists.freedesktop.org Errors-To: dri-devel-bounces+patchwork-dri-devel=patchwork.kernel.org@lists.freedesktop.org From: Maarten Lankhorst Create a dma object for the prime semaphore and every imported sync bo. Signed-off-by: Maarten Lankhorst --- drivers/gpu/drm/nouveau/nv84_fence.c | 121 ++++++++++++++++++++++++++++++++-- 1 file changed, 115 insertions(+), 6 deletions(-) diff --git a/drivers/gpu/drm/nouveau/nv84_fence.c b/drivers/gpu/drm/nouveau/nv84_fence.c index b5cfbcb..f739dfc 100644 --- a/drivers/gpu/drm/nouveau/nv84_fence.c +++ b/drivers/gpu/drm/nouveau/nv84_fence.c @@ -31,6 +31,7 @@ struct nv84_fence_chan { struct nouveau_fence_chan base; + u32 sema_start; }; struct nv84_fence_priv { @@ -42,21 +43,25 @@ static int nv84_fence_emit(struct nouveau_fence *fence, bool prime) { struct nouveau_channel *chan = fence->channel; - int ret = RING_SPACE(chan, 7); - if (ret == 0) { + int i, ret; + + ret = RING_SPACE(chan, prime ? 14 : 7); + if (ret) + return ret; + + for (i = 0; i < (prime ? 2 : 1); ++i) { BEGIN_NV04(chan, 0, NV11_SUBCHAN_DMA_SEMAPHORE, 1); - OUT_RING (chan, NvSema); + OUT_RING (chan, i ? NvSemaPrime : NvSema); BEGIN_NV04(chan, 0, NV84_SUBCHAN_SEMAPHORE_ADDRESS_HIGH, 4); OUT_RING (chan, upper_32_bits(chan->id * 16)); OUT_RING (chan, lower_32_bits(chan->id * 16)); OUT_RING (chan, fence->sequence); OUT_RING (chan, NV84_SUBCHAN_SEMAPHORE_TRIGGER_WRITE_LONG); - FIRE_RING (chan); } + FIRE_RING (chan); return ret; } - static int nv84_fence_sync(struct nouveau_fence *fence, struct nouveau_channel *prev, struct nouveau_channel *chan) @@ -82,12 +87,94 @@ nv84_fence_read(struct nouveau_channel *chan) return nv_ro32(priv->mem, chan->id * 16); } +static int +nv84_fence_prime_sync(struct nouveau_channel *chan, + struct nouveau_bo *bo, + u32 ofs, u32 val, u64 sema_start) +{ + struct nv84_fence_priv *priv = nv_engine(chan->dev, NVOBJ_ENGINE_FENCE); + int ret = RING_SPACE(chan, 7); + u32 sema = 0; + if (ret < 0) + return ret; + + if (bo == priv->base.prime_bo) { + sema = NvSema; + } else { + struct sg_table *sgt = bo->bo.sg; + struct scatterlist *sg; + u32 i; + sema = sema_start; + for_each_sg(sgt->sgl, sg, sgt->nents, i) { + if (ofs < sg->offset + sg->length) { + ofs -= sg->offset; + break; + } + sema++; + } + } + + BEGIN_NV04(chan, 0, NV11_SUBCHAN_DMA_SEMAPHORE, 1); + OUT_RING (chan, sema); + BEGIN_NV04(chan, 0, NV84_SUBCHAN_SEMAPHORE_ADDRESS_HIGH, 4); + OUT_RING (chan, 0); + OUT_RING (chan, ofs); + OUT_RING (chan, val); + OUT_RING (chan, NV84_SUBCHAN_SEMAPHORE_TRIGGER_ACQUIRE_GEQUAL); + FIRE_RING (chan); + return ret; +} + +static void +nv84_fence_prime_del_import(struct nouveau_fence_prime_bo_entry *entry) { + u32 i; + for (i = entry->sema_start; i < entry->sema_start + entry->sema_len; ++i) + nouveau_ramht_remove(entry->chan, i); +} + +static int +nv84_fence_prime_add_import(struct nouveau_fence_prime_bo_entry *entry) { + struct sg_table *sgt = entry->bo->bo.sg; + struct nouveau_channel *chan = entry->chan; + struct nv84_fence_chan *fctx = chan->engctx[NVOBJ_ENGINE_FENCE]; + struct scatterlist *sg; + u32 i, sema; + int ret; + + sema = entry->sema_start = fctx->sema_start; + entry->sema_len = 0; + + for_each_sg(sgt->sgl, sg, sgt->nents, i) { + struct nouveau_gpuobj *obj; + ret = nouveau_gpuobj_dma_new(chan, NV_CLASS_DMA_FROM_MEMORY, + sg_dma_address(sg), PAGE_SIZE, + NV_MEM_ACCESS_RO, + NV_MEM_TARGET_PCI, &obj); + if (ret) + goto err; + + ret = nouveau_ramht_insert(chan, sema, obj); + nouveau_gpuobj_ref(NULL, &obj); + if (ret) + goto err; + entry->sema_len++; + sema++; + } + fctx->sema_start += (entry->sema_len + 0xff) & ~0xff; + return 0; + +err: + nv84_fence_prime_del_import(entry); + return ret; +} + static void nv84_fence_context_del(struct nouveau_channel *chan, int engine) { struct nv84_fence_chan *fctx = chan->engctx[engine]; nouveau_fence_context_del(chan->dev, &fctx->base); chan->engctx[engine] = NULL; + kfree(fctx); } @@ -104,6 +191,7 @@ nv84_fence_context_new(struct nouveau_channel *chan, int engine) return -ENOMEM; nouveau_fence_context_new(&fctx->base); + fctx->sema_start = 0xc0000000 | (chan->id << 20); ret = nouveau_gpuobj_dma_new(chan, NV_CLASS_DMA_FROM_MEMORY, priv->mem->vinst, priv->mem->size, @@ -112,7 +200,21 @@ nv84_fence_context_new(struct nouveau_channel *chan, int engine) if (ret == 0) { ret = nouveau_ramht_insert(chan, NvSema, obj); nouveau_gpuobj_ref(NULL, &obj); - nv_wo32(priv->mem, chan->id * 16, 0x00000000); + fctx->base.sequence = nv_ro32(priv->mem, chan->id * 16); + } + + if (priv->base.prime_bo) { + struct nouveau_mem *mem = priv->base.prime_bo->bo.mem.mm_node; + ret = nouveau_gpuobj_dma_new(chan, NV_CLASS_DMA_FROM_MEMORY, + mem->pages[0], PAGE_SIZE, + NV_MEM_ACCESS_RW, + NV_MEM_TARGET_PCI, &obj); + if (ret == 0) { + ret = nouveau_ramht_insert(chan, NvSemaPrime, obj); + nouveau_gpuobj_ref(NULL, &obj); + nouveau_bo_wr32(priv->base.prime_bo, chan->id * 4, + fctx->base.sequence); + } } if (ret) @@ -138,6 +240,7 @@ nv84_fence_destroy(struct drm_device *dev, int engine) struct drm_nouveau_private *dev_priv = dev->dev_private; struct nv84_fence_priv *priv = nv_engine(dev, engine); + nouveau_fence_prime_del(&priv->base); nouveau_gpuobj_ref(NULL, &priv->mem); dev_priv->eng[engine] = NULL; kfree(priv); @@ -163,6 +266,10 @@ nv84_fence_create(struct drm_device *dev) priv->base.emit = nv84_fence_emit; priv->base.sync = nv84_fence_sync; priv->base.read = nv84_fence_read; + + priv->base.prime_sync = nv84_fence_prime_sync; + priv->base.prime_add_import = nv84_fence_prime_add_import; + priv->base.prime_del_import = nv84_fence_prime_del_import; dev_priv->eng[NVOBJ_ENGINE_FENCE] = &priv->base.engine; ret = nouveau_gpuobj_new(dev, NULL, 16 * pfifo->channels, @@ -170,6 +277,8 @@ nv84_fence_create(struct drm_device *dev) if (ret) goto out; + ret = nouveau_fence_prime_init(dev, &priv->base, 16); + out: if (ret) nv84_fence_destroy(dev, NVOBJ_ENGINE_FENCE);