From patchwork Thu Dec 20 13:19:49 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Vetter X-Patchwork-Id: 1899701 Return-Path: X-Original-To: patchwork-dri-devel@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by patchwork1.kernel.org (Postfix) with ESMTP id DD79A3FC64 for ; Thu, 20 Dec 2012 13:20:55 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id E035CE6644 for ; Thu, 20 Dec 2012 05:20:55 -0800 (PST) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-ea0-f181.google.com (mail-ea0-f181.google.com [209.85.215.181]) by gabe.freedesktop.org (Postfix) with ESMTP id 14213E6613 for ; Thu, 20 Dec 2012 05:19:56 -0800 (PST) Received: by mail-ea0-f181.google.com with SMTP id k14so1329862eaa.12 for ; Thu, 20 Dec 2012 05:19:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ffwll.ch; s=google; h=x-received:from:to:cc:subject:date:message-id:x-mailer:in-reply-to :references; bh=fYhxEbbYMe0+l2mBy70mIUmWlx6z4lybRhwoq8RmaR4=; b=RMKXef7HX+DpFnG+7GQfP5lM3ix4d2YB4HuZSq8Y6wYAhYbrJFq/shdDfdpD5tZtQt 08o61I2iqC8jTO+uX+SiQEg1GHsObopFi9Iq5MkCJ8S4XGK5JpgZ8HgJXeqzG86utEDn zFFMx8W0xXr31YZsc5OEv+lNrJg7T5IMOHwb0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-received:from:to:cc:subject:date:message-id:x-mailer:in-reply-to :references:x-gm-message-state; bh=fYhxEbbYMe0+l2mBy70mIUmWlx6z4lybRhwoq8RmaR4=; b=MYj2PETGsVnabWG3Mh7oYSguuNUVBMewF0U8bczi0mn9mIo3pHDuZy/yQgtKK5KV25 iHbZSxRu5kmzpp3rv/976Y2nxbiBFzJ3WbeMl6c1c7eHKwUwMi0rEV9W+0DMDWSwkjC1 Bv3QPFwDeqdAy0uB+WI/B29WZk2PE9Ja6eze24dzYHjXow+sYZ73sfMbpF284Vp+ykfP oU9k3GjkhwsmUS/6JPcUs+V2mpmZm971gKCOMov89gq9/OEZrGj6tZO3NK/FKob8uUgR pS1aBeFlyFJDsnCHHXFv0PsOZfy2gW6ytUw1iSjGezadkkHtqt3DkFME/JDLdw9CYnpf 7KJA== X-Received: by 10.14.209.193 with SMTP id s41mr23504611eeo.9.1356009595995; Thu, 20 Dec 2012 05:19:55 -0800 (PST) Received: from biers.ffwll.local (178-83-130-250.dynamic.hispeed.ch. [178.83.130.250]) by mx.google.com with ESMTPS id 43sm15337191eed.10.2012.12.20.05.19.54 (version=TLSv1/SSLv3 cipher=OTHER); Thu, 20 Dec 2012 05:19:55 -0800 (PST) From: Daniel Vetter To: DRI Development Subject: [PATCH] drm/nouveau: protect evo_wait/evo_kick sections with a channel mutex Date: Thu, 20 Dec 2012 14:19:49 +0100 Message-Id: <1356009589-19943-1-git-send-email-daniel.vetter@ffwll.ch> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1355865913-14858-7-git-send-email-daniel.vetter@ffwll.ch> References: <1355865913-14858-7-git-send-email-daniel.vetter@ffwll.ch> X-Gm-Message-State: ALoCoQk2yVbmun7ck+bv0Nolt0nPKjaaQ/QHNTmO6S5tj5jels7nlOFiGBVamrVi5zQUy8CxT0dy Cc: Daniel Vetter 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 With per-crtc locks modeset operations can run in parallel, and the cursor code uses the device-global evo master channel for hw frobbing. But the pageflip code can also sync with the master under some circumstances. Hence just wrap things up in a mutex to ensure that pushbuf access doesn't intermingle. The approach here is a bit overkill since the per-crtc channels used to schedule the pageflips could probably be used without this pushbuf locking, but I'm not familiar enough with the nouveau codebase to be sure of that. v2: Add missing mutex_init to avoid angering lockdep. Signed-off-by: Daniel Vetter --- drivers/gpu/drm/nouveau/nv50_display.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/drivers/gpu/drm/nouveau/nv50_display.c b/drivers/gpu/drm/nouveau/nv50_display.c index 3587408..d4cbea1 100644 --- a/drivers/gpu/drm/nouveau/nv50_display.c +++ b/drivers/gpu/drm/nouveau/nv50_display.c @@ -128,6 +128,11 @@ struct nv50_dmac { struct nv50_chan base; dma_addr_t handle; u32 *ptr; + + /* Protects against concurrent pushbuf access to this channel, lock is + * grabbed by evo_wait (if the pushbuf reservation is successful) and + * dropped again by evo_kick. */ + struct mutex lock; }; static void @@ -271,6 +276,8 @@ nv50_dmac_create(struct nouveau_object *core, u32 bclass, u8 head, u32 pushbuf = *(u32 *)data; int ret; + mutex_init(&dmac->lock); + dmac->ptr = pci_alloc_consistent(nv_device(core)->pdev, PAGE_SIZE, &dmac->handle); if (!dmac->ptr) @@ -395,11 +402,13 @@ evo_wait(void *evoc, int nr) struct nv50_dmac *dmac = evoc; u32 put = nv_ro32(dmac->base.user, 0x0000) / 4; + mutex_lock(&dmac->lock); if (put + nr >= (PAGE_SIZE / 4) - 8) { dmac->ptr[put] = 0x20000000; nv_wo32(dmac->base.user, 0x0000, 0x00000000); if (!nv_wait(dmac->base.user, 0x0004, ~0, 0x00000000)) { + mutex_unlock(&dmac->lock); NV_ERROR(dmac->base.user, "channel stalled\n"); return NULL; } @@ -415,6 +424,7 @@ evo_kick(u32 *push, void *evoc) { struct nv50_dmac *dmac = evoc; nv_wo32(dmac->base.user, 0x0000, (push - dmac->ptr) << 2); + mutex_unlock(&dmac->lock); } #define evo_mthd(p,m,s) *((p)++) = (((s) << 18) | (m))