From patchwork Tue Jul 10 10:57:50 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maarten Lankhorst X-Patchwork-Id: 9926 Return-Path: X-Original-To: patchwork@peony.canonical.com Delivered-To: patchwork@peony.canonical.com Received: from fiordland.canonical.com (fiordland.canonical.com [91.189.94.145]) by peony.canonical.com (Postfix) with ESMTP id 562D923E57 for ; Tue, 10 Jul 2012 10:58:46 +0000 (UTC) Received: from mail-yx0-f180.google.com (mail-yx0-f180.google.com [209.85.213.180]) by fiordland.canonical.com (Postfix) with ESMTP id 268C4A1877D for ; Tue, 10 Jul 2012 10:58:46 +0000 (UTC) Received: by mail-yx0-f180.google.com with SMTP id q6so11859368yen.11 for ; Tue, 10 Jul 2012 03:58:46 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-forwarded-to:x-forwarded-for:delivered-to:received-spf :dkim-signature:from:to:date:message-id:x-mailer:in-reply-to :references:cc:subject:x-beenthere:x-mailman-version:precedence :list-id:list-unsubscribe:list-archive:list-post:list-help :list-subscribe:mime-version:content-type:content-transfer-encoding :sender:errors-to:x-gm-message-state; bh=VzocgyxaoUPUGA2G8w8pv9hNcFlxjA15BQYJjeFGkLQ=; b=mcxLLgex/8YzHYnWJMOXOvvZddNMoEUY5rgcJvpSWED/9pbJry8TG7+T+VrMsHOWrR qybSyX2bV0k17pkjYGY+88YD+GQ4hyTPIdvkkROUNrfyjjPSkrWccpVDlhKPmyL0qazV S7RD1JPezBAFNtQp4A2q+oDDYpTD/0NMpmQlyWs+TV8yKEzKJMbBXSiB4yWl2x7GRUYu T4C/+vaAA7CRwZEXamDyUe1Fiv02nl1ZNXtCgqlXzVWScvzCNLhitN2BWH/VYwBusHEf flTALESIhowrbCFkGywOzIEx9Z93lT5s5LWZXshAReN3HpMpmlkxzvQTkBGUYRdzLMY8 WJoA== Received: by 10.50.195.234 with SMTP id ih10mr11007773igc.0.1341917925741; Tue, 10 Jul 2012 03:58:45 -0700 (PDT) X-Forwarded-To: linaro-patchwork@canonical.com X-Forwarded-For: patch@linaro.org linaro-patchwork@canonical.com Delivered-To: patches@linaro.org Received: by 10.231.24.148 with SMTP id v20csp47689ibb; Tue, 10 Jul 2012 03:58:44 -0700 (PDT) Received: by 10.205.135.146 with SMTP id ig18mr17044387bkc.80.1341917924248; Tue, 10 Jul 2012 03:58:44 -0700 (PDT) Received: from mombin.canonical.com (mombin.canonical.com. [91.189.95.16]) by mx.google.com with ESMTP id gz3si35178756bkc.124.2012.07.10.03.58.42; Tue, 10 Jul 2012 03:58:44 -0700 (PDT) Received-SPF: neutral (google.com: 91.189.95.16 is neither permitted nor denied by best guess record for domain of linaro-mm-sig-bounces@lists.linaro.org) client-ip=91.189.95.16; Authentication-Results: mx.google.com; spf=neutral (google.com: 91.189.95.16 is neither permitted nor denied by best guess record for domain of linaro-mm-sig-bounces@lists.linaro.org) smtp.mail=linaro-mm-sig-bounces@lists.linaro.org; dkim=neutral (body hash did not verify) header.i=@gmail.com Received: from localhost ([127.0.0.1] helo=mombin.canonical.com) by mombin.canonical.com with esmtp (Exim 4.71) (envelope-from ) id 1SoY9R-0002kc-O2; Tue, 10 Jul 2012 10:58:41 +0000 Received: from mail-ey0-f170.google.com ([209.85.215.170]) by mombin.canonical.com with esmtp (Exim 4.71) (envelope-from ) id 1SoY9Q-0002aX-6U for linaro-mm-sig@lists.linaro.org; Tue, 10 Jul 2012 10:58:41 +0000 Received: by mail-ey0-f170.google.com with SMTP id l12so7970290eaa.1 for ; Tue, 10 Jul 2012 03:58:40 -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=2TUAd4mfP2bfNFvrQlJcliVO1WbzXH8LenvEuaXudW0=; b=clzqwS797HUyHOFi5nAzQHemJ6RCpnClHEOHvAQ31oCMz9Z6YT8YcNsQq65Q8dmErq YgTxQ0BRvBdxVMn8pcodpDmxj+lqNuz3aTt/k+mq9o/pyjPFvMpDURHhOIosT7glnUDk iaXaK1CyrJOnmIDSuGjHCgXsh3umciwqZLJDfRGyaRqMVXzRDkJ2Wra4EH9ZqTOc6Wya /jhcnohbv+KecvwSJoTr8NeAjTYNFcrR+m5tiLKgmzcXIkWzdXhOzHbf2aiVXkvF//UH AKuZoOI7ChcgqZh1gLLm3JdhvwXsMJKW/S0Du+zD+corn6R/bNofgKmS6uLhSEPfLL6e 2kFQ== Received: by 10.14.99.136 with SMTP id x8mr10709862eef.64.1341917920015; Tue, 10 Jul 2012 03:58:40 -0700 (PDT) Received: from localhost (5ED48CEF.cm-7-5c.dynamic.ziggo.nl. [94.212.140.239]) by mx.google.com with ESMTPS id a16sm101547760eeg.0.2012.07.10.03.58.35 (version=TLSv1/SSLv3 cipher=OTHER); Tue, 10 Jul 2012 03:58:38 -0700 (PDT) Received: by localhost (sSMTP sendmail emulation); Tue, 10 Jul 2012 12:58:34 +0200 From: Maarten Lankhorst To: dri-devel@lists.freedesktop.org Date: Tue, 10 Jul 2012 12:57:50 +0200 Message-Id: <1341917871-2512-8-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 Subject: [Linaro-mm-sig] [RFC PATCH 7/8] nouveau: nvc0 fence prime implementation X-BeenThere: linaro-mm-sig@lists.linaro.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: "Unified memory management interest group." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: linaro-mm-sig-bounces@lists.linaro.org Errors-To: linaro-mm-sig-bounces@lists.linaro.org X-Gm-Message-State: ALoCoQmf3YP+JcWKIEXG6FFWqqBQq36Bltwyry+USGEEVvRqqjKRTr7JJPyPfcxDfmy7juBZxfCl From: Maarten Lankhorst Create a read-only mapping for every imported bo, and create a prime bo in in system memory. Signed-off-by: Maarten Lankhorst --- 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; }