From patchwork Thu Jun 4 09:03:02 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tomi Valkeinen X-Patchwork-Id: 6545571 Return-Path: X-Original-To: patchwork-dri-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 314D2C0433 for ; Thu, 4 Jun 2015 11:06:47 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 3E9C3207B3 for ; Thu, 4 Jun 2015 11:06:46 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id 370E02070A for ; Thu, 4 Jun 2015 11:06:45 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 0934D6EAFD; Thu, 4 Jun 2015 04:06:36 -0700 (PDT) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from comal.ext.ti.com (comal.ext.ti.com [198.47.26.152]) by gabe.freedesktop.org (Postfix) with ESMTP id ECE596EA73 for ; Thu, 4 Jun 2015 02:11:52 -0700 (PDT) Received: from dlelxv90.itg.ti.com ([172.17.2.17]) by comal.ext.ti.com (8.13.7/8.13.7) with ESMTP id t5494ciG010419; Thu, 4 Jun 2015 04:04:38 -0500 Received: from DLEE71.ent.ti.com (dlee71.ent.ti.com [157.170.170.114]) by dlelxv90.itg.ti.com (8.14.3/8.13.8) with ESMTP id t5494c1v012368; Thu, 4 Jun 2015 04:04:38 -0500 Received: from dlep33.itg.ti.com (157.170.170.75) by DLEE71.ent.ti.com (157.170.170.114) with Microsoft SMTP Server id 14.3.224.2; Thu, 4 Jun 2015 04:04:37 -0500 Received: from deskari.ti.com (ileax41-snat.itg.ti.com [10.172.224.153]) by dlep33.itg.ti.com (8.14.3/8.13.8) with ESMTP id t5493Ywl014785; Thu, 4 Jun 2015 04:04:36 -0500 From: Tomi Valkeinen To: , Laurent Pinchart Subject: [PATCHv2 45/45] drm: omapdrm: add lock for fb pinning Date: Thu, 4 Jun 2015 12:03:02 +0300 Message-ID: <1433408582-9828-46-git-send-email-tomi.valkeinen@ti.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1433408582-9828-1-git-send-email-tomi.valkeinen@ti.com> References: <1433408582-9828-1-git-send-email-tomi.valkeinen@ti.com> MIME-Version: 1.0 X-Mailman-Approved-At: Thu, 04 Jun 2015 04:06:34 -0700 Cc: Tomi Valkeinen X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Before atomic modesetting omap_framebuffer_pin() and omap_framebuffer_unpin() were always called with modesetting locks taken. With atomic modesetting support this is no longer the case, and we need locking to protect the pin_count and the paddr, as multiple threads may pin the same fb concurrently. This patch adds a mutex to struct omap_framebuffer, and uses it in omap_framebuffer_pin() and omap_framebuffer_unpin(). Signed-off-by: Tomi Valkeinen Acked-by: Laurent Pinchart --- drivers/gpu/drm/omapdrm/omap_fb.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/omapdrm/omap_fb.c b/drivers/gpu/drm/omapdrm/omap_fb.c index e505140a8782..0b967e76df1a 100644 --- a/drivers/gpu/drm/omapdrm/omap_fb.c +++ b/drivers/gpu/drm/omapdrm/omap_fb.c @@ -89,6 +89,8 @@ struct omap_framebuffer { int pin_count; const struct format *format; struct plane planes[4]; + /* lock for pinning (pin_count and planes.paddr) */ + struct mutex lock; }; static int omap_framebuffer_create_handle(struct drm_framebuffer *fb, @@ -250,8 +252,11 @@ int omap_framebuffer_pin(struct drm_framebuffer *fb) struct omap_framebuffer *omap_fb = to_omap_framebuffer(fb); int ret, i, n = drm_format_num_planes(fb->pixel_format); + mutex_lock(&omap_fb->lock); + if (omap_fb->pin_count > 0) { omap_fb->pin_count++; + mutex_unlock(&omap_fb->lock); return 0; } @@ -265,6 +270,8 @@ int omap_framebuffer_pin(struct drm_framebuffer *fb) omap_fb->pin_count++; + mutex_unlock(&omap_fb->lock); + return 0; fail: @@ -274,6 +281,8 @@ fail: plane->paddr = 0; } + mutex_unlock(&omap_fb->lock); + return ret; } @@ -283,10 +292,14 @@ int omap_framebuffer_unpin(struct drm_framebuffer *fb) struct omap_framebuffer *omap_fb = to_omap_framebuffer(fb); int ret, i, n = drm_format_num_planes(fb->pixel_format); + mutex_lock(&omap_fb->lock); + omap_fb->pin_count--; - if (omap_fb->pin_count > 0) + if (omap_fb->pin_count > 0) { + mutex_unlock(&omap_fb->lock); return 0; + } for (i = 0; i < n; i++) { struct plane *plane = &omap_fb->planes[i]; @@ -296,9 +309,12 @@ int omap_framebuffer_unpin(struct drm_framebuffer *fb) plane->paddr = 0; } + mutex_unlock(&omap_fb->lock); + return 0; fail: + mutex_unlock(&omap_fb->lock); return ret; } @@ -411,6 +427,7 @@ struct drm_framebuffer *omap_framebuffer_init(struct drm_device *dev, fb = &omap_fb->base; omap_fb->format = format; + mutex_init(&omap_fb->lock); for (i = 0; i < n; i++) { struct plane *plane = &omap_fb->planes[i];