From patchwork Wed Feb 3 13:10:41 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Zimmermann X-Patchwork-Id: 12064333 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.9 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,UNWANTED_LANGUAGE_BODY, URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 60485C433E9 for ; Wed, 3 Feb 2021 13:10:58 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id E9DB764F95 for ; Wed, 3 Feb 2021 13:10:57 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org E9DB764F95 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=suse.de Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 5395C6EAB0; Wed, 3 Feb 2021 13:10:52 +0000 (UTC) Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) by gabe.freedesktop.org (Postfix) with ESMTPS id 9BE476EAA3 for ; Wed, 3 Feb 2021 13:10:50 +0000 (UTC) X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 32B04AFD2; Wed, 3 Feb 2021 13:10:49 +0000 (UTC) From: Thomas Zimmermann To: daniel@ffwll.ch, airlied@linux.ie, maarten.lankhorst@linux.intel.com, mripard@kernel.org, kraxel@redhat.com, hdegoede@redhat.com, sean@poorly.run, sam@ravnborg.org, noralf@tronnes.org Subject: [PATCH 1/6] drm/simple-kms: Add plane-state helpers Date: Wed, 3 Feb 2021 14:10:41 +0100 Message-Id: <20210203131046.22371-2-tzimmermann@suse.de> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20210203131046.22371-1-tzimmermann@suse.de> References: <20210203131046.22371-1-tzimmermann@suse.de> MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Thomas Zimmermann , dri-devel@lists.freedesktop.org, virtualization@lists.linux-foundation.org Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Just like regular plane-state helpers, drivers can use these new callbacks to create and destroy private plane state. Signed-off-by: Thomas Zimmermann --- drivers/gpu/drm/drm_simple_kms_helper.c | 40 +++++++++++++++++++++++-- include/drm/drm_simple_kms_helper.h | 28 +++++++++++++++++ 2 files changed, 65 insertions(+), 3 deletions(-) diff --git a/drivers/gpu/drm/drm_simple_kms_helper.c b/drivers/gpu/drm/drm_simple_kms_helper.c index 6ce8f5cd1eb5..0c5bb0f98fa0 100644 --- a/drivers/gpu/drm/drm_simple_kms_helper.c +++ b/drivers/gpu/drm/drm_simple_kms_helper.c @@ -253,13 +253,47 @@ static const struct drm_plane_helper_funcs drm_simple_kms_plane_helper_funcs = { .atomic_update = drm_simple_kms_plane_atomic_update, }; +static void drm_simple_kms_plane_reset(struct drm_plane *plane) +{ + struct drm_simple_display_pipe *pipe; + + pipe = container_of(plane, struct drm_simple_display_pipe, plane); + if (!pipe->funcs || !pipe->funcs->reset_plane) + return drm_atomic_helper_plane_reset(plane); + + return pipe->funcs->reset_plane(pipe); +} + +static struct drm_plane_state *drm_simple_kms_plane_duplicate_state(struct drm_plane *plane) +{ + struct drm_simple_display_pipe *pipe; + + pipe = container_of(plane, struct drm_simple_display_pipe, plane); + if (!pipe->funcs || !pipe->funcs->duplicate_plane_state) + return drm_atomic_helper_plane_duplicate_state(plane); + + return pipe->funcs->duplicate_plane_state(pipe, plane->state); +} + +static void drm_simple_kms_plane_destroy_state(struct drm_plane *plane, + struct drm_plane_state *state) +{ + struct drm_simple_display_pipe *pipe; + + pipe = container_of(plane, struct drm_simple_display_pipe, plane); + if (!pipe->funcs || !pipe->funcs->destroy_plane_state) + drm_atomic_helper_plane_destroy_state(plane, state); + else + pipe->funcs->destroy_plane_state(pipe, state); +} + static const struct drm_plane_funcs drm_simple_kms_plane_funcs = { .update_plane = drm_atomic_helper_update_plane, .disable_plane = drm_atomic_helper_disable_plane, .destroy = drm_plane_cleanup, - .reset = drm_atomic_helper_plane_reset, - .atomic_duplicate_state = drm_atomic_helper_plane_duplicate_state, - .atomic_destroy_state = drm_atomic_helper_plane_destroy_state, + .reset = drm_simple_kms_plane_reset, + .atomic_duplicate_state = drm_simple_kms_plane_duplicate_state, + .atomic_destroy_state = drm_simple_kms_plane_destroy_state, .format_mod_supported = drm_simple_kms_format_mod_supported, }; diff --git a/include/drm/drm_simple_kms_helper.h b/include/drm/drm_simple_kms_helper.h index e6dbf3161c2f..0c1a2e07caf2 100644 --- a/include/drm/drm_simple_kms_helper.h +++ b/include/drm/drm_simple_kms_helper.h @@ -149,6 +149,34 @@ struct drm_simple_display_pipe_funcs { * more details. */ void (*disable_vblank)(struct drm_simple_display_pipe *pipe); + + /** + * @reset_plane: + * + * Optional, called by &drm_plane_funcs.reset. Please read the + * documentation for the &drm_plane_funcs.reset hook for more details. + */ + void (*reset_plane)(struct drm_simple_display_pipe *pipe); + + /** + * @duplicate_plane_state: + * + * Optional, called by &drm_plane_funcs.atomic_duplicate_state. Please + * read the documentation for the &drm_plane_funcs.atomic_duplicate_state + * hook for more details. + */ + struct drm_plane_state * (*duplicate_plane_state)(struct drm_simple_display_pipe *pipe, + struct drm_plane_state *plane_state); + + /** + * @destroy_plane_state: + * + * Optional, called by &drm_plane_funcs.atomic_destroy_state. Please + * read the documentation for the &drm_plane_funcs.atomic_destroy_state + * hook for more details. + */ + void (*destroy_plane_state)(struct drm_simple_display_pipe *pipe, + struct drm_plane_state *plane_state); }; /** From patchwork Wed Feb 3 13:10:42 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Zimmermann X-Patchwork-Id: 12064335 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6D262C433DB for ; Wed, 3 Feb 2021 13:11:01 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 141CD64F92 for ; Wed, 3 Feb 2021 13:11:01 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 141CD64F92 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=suse.de Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id F366C6EAB4; Wed, 3 Feb 2021 13:10:52 +0000 (UTC) Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) by gabe.freedesktop.org (Postfix) with ESMTPS id 3DF8B6EAA5 for ; Wed, 3 Feb 2021 13:10:51 +0000 (UTC) X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id CE307B12B; Wed, 3 Feb 2021 13:10:49 +0000 (UTC) From: Thomas Zimmermann To: daniel@ffwll.ch, airlied@linux.ie, maarten.lankhorst@linux.intel.com, mripard@kernel.org, kraxel@redhat.com, hdegoede@redhat.com, sean@poorly.run, sam@ravnborg.org, noralf@tronnes.org Subject: [PATCH 2/6] drm/shmem-helper: Add additional KMS helpers Date: Wed, 3 Feb 2021 14:10:42 +0100 Message-Id: <20210203131046.22371-3-tzimmermann@suse.de> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20210203131046.22371-1-tzimmermann@suse.de> References: <20210203131046.22371-1-tzimmermann@suse.de> MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Thomas Zimmermann , dri-devel@lists.freedesktop.org, virtualization@lists.linux-foundation.org Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Several drivers use GEM SHMEM buffer objects as shadow buffers for the actual framebuffer memory. Right now, drivers do these vmap operations in their commit tail, which is actually not allowed by the locking rules for the dma-buf reservation lock. The involved SHMEM BO has to be vmapped in the plane's prepare_fb callback and vunmapped in cleanup_fb. This patch introduces a DRM library that implements KMS helpers for GEM SHMEM buffer objects. The first set of helpers is the plane state for shadow planes. The provided implementations for prepare_fb and cleanup_fb vmap and vunmap all BOs of struct drm_plane_state.fb. The mappings are afterwards available in the plane's commit-tail functions. All rsp drivers use the simple KMS helpers, so we add the plane callbacks and wrappers for simple KMS. Signed-off-by: Thomas Zimmermann --- drivers/gpu/drm/Kconfig | 7 + drivers/gpu/drm/Makefile | 1 + drivers/gpu/drm/drm_gem_shmem_kms_helper.c | 159 +++++++++++++++++++++ include/drm/drm_gem_shmem_kms_helper.h | 56 ++++++++ 4 files changed, 223 insertions(+) create mode 100644 drivers/gpu/drm/drm_gem_shmem_kms_helper.c create mode 100644 include/drm/drm_gem_shmem_kms_helper.h diff --git a/drivers/gpu/drm/Kconfig b/drivers/gpu/drm/Kconfig index 8bf103de1594..b8d8b00ab5d4 100644 --- a/drivers/gpu/drm/Kconfig +++ b/drivers/gpu/drm/Kconfig @@ -214,6 +214,13 @@ config DRM_GEM_SHMEM_HELPER help Choose this if you need the GEM shmem helper functions +config DRM_GEM_SHMEM_KMS_HELPER + bool + depends on DRM_GEM_SHMEM_HELPER + help + help + Choose this if you need the GEM SHMEM helper functions for KMS + config DRM_SCHED tristate depends on DRM diff --git a/drivers/gpu/drm/Makefile b/drivers/gpu/drm/Makefile index 926adef289db..37a73dee5baf 100644 --- a/drivers/gpu/drm/Makefile +++ b/drivers/gpu/drm/Makefile @@ -53,6 +53,7 @@ drm_kms_helper-$(CONFIG_DRM_FBDEV_EMULATION) += drm_fb_helper.o drm_kms_helper-$(CONFIG_DRM_KMS_CMA_HELPER) += drm_fb_cma_helper.o drm_kms_helper-$(CONFIG_DRM_DP_AUX_CHARDEV) += drm_dp_aux_dev.o drm_kms_helper-$(CONFIG_DRM_DP_CEC) += drm_dp_cec.o +drm_kms_helper-$(CONFIG_DRM_GEM_SHMEM_KMS_HELPER) += drm_gem_shmem_kms_helper.o obj-$(CONFIG_DRM_KMS_HELPER) += drm_kms_helper.o obj-$(CONFIG_DRM_DEBUG_SELFTEST) += selftests/ diff --git a/drivers/gpu/drm/drm_gem_shmem_kms_helper.c b/drivers/gpu/drm/drm_gem_shmem_kms_helper.c new file mode 100644 index 000000000000..8843c5837f98 --- /dev/null +++ b/drivers/gpu/drm/drm_gem_shmem_kms_helper.c @@ -0,0 +1,159 @@ +// SPDX-License-Identifier: GPL-2.0 + +#include +#include +#include +#include +#include + +/* + * Helpers for struct drm_plane_funcs + * + */ + +static struct drm_plane_state * +drm_gem_shmem_duplicate_shadow_plane_state(struct drm_plane *plane, + struct drm_plane_state *plane_state) +{ + struct drm_gem_shmem_shadow_plane_state *new_shadow_plane_state; + + if (!plane_state) + return NULL; + + new_shadow_plane_state = kzalloc(sizeof(*new_shadow_plane_state), GFP_KERNEL); + if (!new_shadow_plane_state) + return NULL; + __drm_atomic_helper_plane_duplicate_state(plane, &new_shadow_plane_state->base); + + return &new_shadow_plane_state->base; +} + +static void drm_gem_shmem_destroy_shadow_plane_state(struct drm_plane *plane, + struct drm_plane_state *plane_state) +{ + struct drm_gem_shmem_shadow_plane_state *shadow_plane_state = + to_drm_gem_shmem_shadow_plane_state(plane_state); + + __drm_atomic_helper_plane_destroy_state(&shadow_plane_state->base); + kfree(shadow_plane_state); +} + +static void drm_gem_shmem_reset_shadow_plane(struct drm_plane *plane) +{ + struct drm_gem_shmem_shadow_plane_state *shadow_plane_state; + + if (plane->state) { + drm_gem_shmem_destroy_shadow_plane_state(plane, plane->state); + plane->state = NULL; /* must be set to NULL here */ + } + + shadow_plane_state = kzalloc(sizeof(*shadow_plane_state), GFP_KERNEL); + if (!shadow_plane_state) + return; + __drm_atomic_helper_plane_reset(plane, &shadow_plane_state->base); +} + +/* + * Helpers for struct drm_plane_helper_funcs + */ + +static int drm_gem_shmem_prepare_shadow_fb(struct drm_plane *plane, + struct drm_plane_state *plane_state) +{ + struct drm_gem_shmem_shadow_plane_state *shadow_plane_state = + to_drm_gem_shmem_shadow_plane_state(plane_state); + struct drm_framebuffer *fb = plane_state->fb; + struct drm_gem_object *obj; + struct dma_buf_map map; + int ret; + size_t i; + + if (!fb) + return 0; + + ret = drm_gem_fb_prepare_fb(plane, plane_state); + if (ret) + return ret; + + for (i = 0; i < ARRAY_SIZE(shadow_plane_state->map); ++i) { + obj = drm_gem_fb_get_obj(fb, i); + if (!obj) + continue; + ret = drm_gem_shmem_vmap(obj, &map); + if (ret) + goto err_drm_gem_shmem_vunmap; + shadow_plane_state->map[i] = map; + } + + return 0; + +err_drm_gem_shmem_vunmap: + while (i) { + --i; + obj = drm_gem_fb_get_obj(fb, i); + if (!obj) + continue; + drm_gem_shmem_vunmap(obj, &shadow_plane_state->map[i]); + } + return ret; +} + +static void drm_gem_shmem_cleanup_shadow_fb(struct drm_plane *plane, + struct drm_plane_state *plane_state) +{ + struct drm_gem_shmem_shadow_plane_state *shadow_plane_state = + to_drm_gem_shmem_shadow_plane_state(plane_state); + struct drm_framebuffer *fb = plane_state->fb; + size_t i = ARRAY_SIZE(shadow_plane_state->map); + struct drm_gem_object *obj; + + if (!fb) + return; + + while (i) { + --i; + obj = drm_gem_fb_get_obj(fb, i); + if (!obj) + continue; + drm_gem_shmem_vunmap(obj, &shadow_plane_state->map[i]); + } +} + +/* + * Simple KMS helpers + */ + +int drm_gem_shmem_simple_kms_prepare_shadow_fb(struct drm_simple_display_pipe *pipe, + struct drm_plane_state *plane_state) +{ + return drm_gem_shmem_prepare_shadow_fb(&pipe->plane, plane_state); +} +EXPORT_SYMBOL(drm_gem_shmem_simple_kms_prepare_shadow_fb); + +void drm_gem_shmem_simple_kms_cleanup_shadow_fb(struct drm_simple_display_pipe *pipe, + struct drm_plane_state *plane_state) +{ + drm_gem_shmem_cleanup_shadow_fb(&pipe->plane, plane_state); +} +EXPORT_SYMBOL(drm_gem_shmem_simple_kms_cleanup_shadow_fb); + +void drm_gem_shmem_simple_kms_reset_shadow_plane(struct drm_simple_display_pipe *pipe) +{ + drm_gem_shmem_reset_shadow_plane(&pipe->plane); +} +EXPORT_SYMBOL(drm_gem_shmem_simple_kms_reset_shadow_plane); + +struct drm_plane_state * +drm_gem_shmem_simple_kms_duplicate_shadow_plane_state(struct drm_simple_display_pipe *pipe, + struct drm_plane_state *plane_state) +{ + return drm_gem_shmem_duplicate_shadow_plane_state(&pipe->plane, plane_state); +} +EXPORT_SYMBOL(drm_gem_shmem_simple_kms_duplicate_shadow_plane_state); + +void drm_gem_shmem_simple_kms_destroy_shadow_plane_state(struct drm_simple_display_pipe *pipe, + struct drm_plane_state *plane_state) +{ + drm_gem_shmem_destroy_shadow_plane_state(&pipe->plane, plane_state); +} +EXPORT_SYMBOL(drm_gem_shmem_simple_kms_destroy_shadow_plane_state); diff --git a/include/drm/drm_gem_shmem_kms_helper.h b/include/drm/drm_gem_shmem_kms_helper.h new file mode 100644 index 000000000000..bd42c9c0a39e --- /dev/null +++ b/include/drm/drm_gem_shmem_kms_helper.h @@ -0,0 +1,56 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +#ifndef __DRM_GEM_SHMEM_KMS_HELPER_H__ +#define __DRM_GEM_SHMEM_KMS_HELPER_H__ + +#include + +#include + +struct drm_simple_display_pipe; + +struct drm_gem_shmem_shadow_plane_state { + struct drm_plane_state base; + + /* Transitional state - do not export or duplicate */ + + struct dma_buf_map map[4]; +}; + +static inline struct drm_gem_shmem_shadow_plane_state * +to_drm_gem_shmem_shadow_plane_state(struct drm_plane_state *state) +{ + return container_of(state, struct drm_gem_shmem_shadow_plane_state, base); +} + +/* + * Simple KMS helpers + */ + +int drm_gem_shmem_simple_kms_prepare_shadow_fb(struct drm_simple_display_pipe *pipe, + struct drm_plane_state *plane_state); +void drm_gem_shmem_simple_kms_cleanup_shadow_fb(struct drm_simple_display_pipe *pipe, + struct drm_plane_state *plane_state); +void drm_gem_shmem_simple_kms_reset_shadow_plane(struct drm_simple_display_pipe *pipe); +struct drm_plane_state * +drm_gem_shmem_simple_kms_duplicate_shadow_plane_state(struct drm_simple_display_pipe *pipe, + struct drm_plane_state *plane_state); +void +drm_gem_shmem_simple_kms_destroy_shadow_plane_state(struct drm_simple_display_pipe *pipe, + struct drm_plane_state *plane_state); + +/** + * DRM_GEM_SHMEM_SIMPLE_DISPLAY_PIPE_SHADOW_PLANE_FUNCS - + * Initializes struct drm_simple_display_pipe_funcs for SHMEM shadow planes + * + * Drivers may use GEM SHMEM BOs as shadow buffers over the framebuffer memory. This + * macro initializes struct drm_simple_display_pipe_funcs to use the rsp helper functions. + */ +#define DRM_GEM_SHMEM_SIMPLE_DISPLAY_PIPE_SHADOW_PLANE_FUNCS \ + .prepare_fb = drm_gem_shmem_simple_kms_prepare_shadow_fb, \ + .cleanup_fb = drm_gem_shmem_simple_kms_cleanup_shadow_fb, \ + .reset_plane = drm_gem_shmem_simple_kms_reset_shadow_plane, \ + .duplicate_plane_state = drm_gem_shmem_simple_kms_duplicate_shadow_plane_state, \ + .destroy_plane_state = drm_gem_shmem_simple_kms_destroy_shadow_plane_state + +#endif /* __DRM_GEM_SHMEM_KMS_HELPER_H__ */ From patchwork Wed Feb 3 13:10:43 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Zimmermann X-Patchwork-Id: 12064337 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A9104C43381 for ; Wed, 3 Feb 2021 13:11:03 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 51D0964F92 for ; Wed, 3 Feb 2021 13:11:03 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 51D0964F92 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=suse.de Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 1C0896EAB5; Wed, 3 Feb 2021 13:10:53 +0000 (UTC) Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) by gabe.freedesktop.org (Postfix) with ESMTPS id E48C46EAAB for ; Wed, 3 Feb 2021 13:10:51 +0000 (UTC) X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 7B402B12C; Wed, 3 Feb 2021 13:10:50 +0000 (UTC) From: Thomas Zimmermann To: daniel@ffwll.ch, airlied@linux.ie, maarten.lankhorst@linux.intel.com, mripard@kernel.org, kraxel@redhat.com, hdegoede@redhat.com, sean@poorly.run, sam@ravnborg.org, noralf@tronnes.org Subject: [PATCH 3/6] drm/mgag200: Move vmap out of commit tail Date: Wed, 3 Feb 2021 14:10:43 +0100 Message-Id: <20210203131046.22371-4-tzimmermann@suse.de> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20210203131046.22371-1-tzimmermann@suse.de> References: <20210203131046.22371-1-tzimmermann@suse.de> MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Thomas Zimmermann , dri-devel@lists.freedesktop.org, virtualization@lists.linux-foundation.org Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Vmap operations may acquire the dmabuf reservation lock, which is not allowed within atomic commit-tail functions. Therefore move vmap and vunmap from the damage handler into prepare_fb and cleanup_fb callbacks. The mapping is provided as GEM SHMEM shadow plane. The enable and prepare callbacks use the established mapping for damage handling. Signed-off-by: Thomas Zimmermann --- drivers/gpu/drm/mgag200/Kconfig | 1 + drivers/gpu/drm/mgag200/mgag200_mode.c | 25 ++++++++++--------------- 2 files changed, 11 insertions(+), 15 deletions(-) diff --git a/drivers/gpu/drm/mgag200/Kconfig b/drivers/gpu/drm/mgag200/Kconfig index eec59658a938..b4e5a1eb57ce 100644 --- a/drivers/gpu/drm/mgag200/Kconfig +++ b/drivers/gpu/drm/mgag200/Kconfig @@ -3,6 +3,7 @@ config DRM_MGAG200 tristate "Matrox G200" depends on DRM && PCI && MMU select DRM_GEM_SHMEM_HELPER + select DRM_GEM_SHMEM_KMS_HELPER select DRM_KMS_HELPER help This is a KMS driver for Matrox G200 chips. It supports the original diff --git a/drivers/gpu/drm/mgag200/mgag200_mode.c b/drivers/gpu/drm/mgag200/mgag200_mode.c index 1dfc42170059..70040a02ee98 100644 --- a/drivers/gpu/drm/mgag200/mgag200_mode.c +++ b/drivers/gpu/drm/mgag200/mgag200_mode.c @@ -18,6 +18,7 @@ #include #include #include +#include #include #include #include @@ -1549,22 +1550,12 @@ mgag200_simple_display_pipe_mode_valid(struct drm_simple_display_pipe *pipe, static void mgag200_handle_damage(struct mga_device *mdev, struct drm_framebuffer *fb, - struct drm_rect *clip) + struct drm_rect *clip, const struct dma_buf_map *map) { - struct drm_device *dev = &mdev->base; - struct dma_buf_map map; - void *vmap; - int ret; - - ret = drm_gem_shmem_vmap(fb->obj[0], &map); - if (drm_WARN_ON(dev, ret)) - return; /* BUG: SHMEM BO should always be vmapped */ - vmap = map.vaddr; /* TODO: Use mapping abstraction properly */ + void *vmap = map->vaddr; /* TODO: Use mapping abstraction properly */ drm_fb_memcpy_dstclip(mdev->vram, vmap, fb, clip); - drm_gem_shmem_vunmap(fb->obj[0], &map); - /* Always scanout image at VRAM offset 0 */ mgag200_set_startadd(mdev, (u32)0); mgag200_set_offset(mdev, fb); @@ -1580,6 +1571,8 @@ mgag200_simple_display_pipe_enable(struct drm_simple_display_pipe *pipe, struct mga_device *mdev = to_mga_device(dev); struct drm_display_mode *adjusted_mode = &crtc_state->adjusted_mode; struct drm_framebuffer *fb = plane_state->fb; + struct drm_gem_shmem_shadow_plane_state *shadow_plane_state = + to_drm_gem_shmem_shadow_plane_state(plane_state); struct drm_rect fullscreen = { .x1 = 0, .x2 = fb->width, @@ -1608,7 +1601,7 @@ mgag200_simple_display_pipe_enable(struct drm_simple_display_pipe *pipe, mga_crtc_load_lut(crtc); mgag200_enable_display(mdev); - mgag200_handle_damage(mdev, fb, &fullscreen); + mgag200_handle_damage(mdev, fb, &fullscreen, &shadow_plane_state->map[0]); } static void @@ -1649,6 +1642,8 @@ mgag200_simple_display_pipe_update(struct drm_simple_display_pipe *pipe, struct drm_device *dev = plane->dev; struct mga_device *mdev = to_mga_device(dev); struct drm_plane_state *state = plane->state; + struct drm_gem_shmem_shadow_plane_state *shadow_plane_state = + to_drm_gem_shmem_shadow_plane_state(state); struct drm_framebuffer *fb = state->fb; struct drm_rect damage; @@ -1656,7 +1651,7 @@ mgag200_simple_display_pipe_update(struct drm_simple_display_pipe *pipe, return; if (drm_atomic_helper_damage_merged(old_state, state, &damage)) - mgag200_handle_damage(mdev, fb, &damage); + mgag200_handle_damage(mdev, fb, &damage, &shadow_plane_state->map[0]); } static const struct drm_simple_display_pipe_funcs @@ -1666,7 +1661,7 @@ mgag200_simple_display_pipe_funcs = { .disable = mgag200_simple_display_pipe_disable, .check = mgag200_simple_display_pipe_check, .update = mgag200_simple_display_pipe_update, - .prepare_fb = drm_gem_fb_simple_display_pipe_prepare_fb, + DRM_GEM_SHMEM_SIMPLE_DISPLAY_PIPE_SHADOW_PLANE_FUNCS, }; static const uint32_t mgag200_simple_display_pipe_formats[] = { From patchwork Wed Feb 3 13:10:44 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Zimmermann X-Patchwork-Id: 12064341 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 54C84C433E0 for ; Wed, 3 Feb 2021 13:11:07 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id ECBE564F95 for ; Wed, 3 Feb 2021 13:11:06 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org ECBE564F95 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=suse.de Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id B85B36EAB2; Wed, 3 Feb 2021 13:10:55 +0000 (UTC) Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) by gabe.freedesktop.org (Postfix) with ESMTPS id 813396EAA5 for ; Wed, 3 Feb 2021 13:10:52 +0000 (UTC) X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 12487B12F; Wed, 3 Feb 2021 13:10:51 +0000 (UTC) From: Thomas Zimmermann To: daniel@ffwll.ch, airlied@linux.ie, maarten.lankhorst@linux.intel.com, mripard@kernel.org, kraxel@redhat.com, hdegoede@redhat.com, sean@poorly.run, sam@ravnborg.org, noralf@tronnes.org Subject: [PATCH 4/6] drm/cirrus: Move vmap out of commit tail Date: Wed, 3 Feb 2021 14:10:44 +0100 Message-Id: <20210203131046.22371-5-tzimmermann@suse.de> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20210203131046.22371-1-tzimmermann@suse.de> References: <20210203131046.22371-1-tzimmermann@suse.de> MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Thomas Zimmermann , dri-devel@lists.freedesktop.org, virtualization@lists.linux-foundation.org Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Vmap operations may acquire the dmabuf reservation lock, which is not allowed within atomic commit-tail functions. Therefore move vmap and vunmap from the damage handler into prepare_fb and cleanup_fb callbacks. The mapping is provided as GEM SHMEM shadow plane. The enable and prepare callbacks use the established mapping for damage handling. Signed-off-by: Thomas Zimmermann --- drivers/gpu/drm/tiny/Kconfig | 3 ++- drivers/gpu/drm/tiny/cirrus.c | 45 +++++++++++++++-------------------- 2 files changed, 21 insertions(+), 27 deletions(-) diff --git a/drivers/gpu/drm/tiny/Kconfig b/drivers/gpu/drm/tiny/Kconfig index 2b6414f0fa75..e0aef6cf8e26 100644 --- a/drivers/gpu/drm/tiny/Kconfig +++ b/drivers/gpu/drm/tiny/Kconfig @@ -3,8 +3,9 @@ config DRM_CIRRUS_QEMU tristate "Cirrus driver for QEMU emulated device" depends on DRM && PCI && MMU - select DRM_KMS_HELPER select DRM_GEM_SHMEM_HELPER + select DRM_GEM_SHMEM_KMS_HELPER + select DRM_KMS_HELPER help This is a KMS driver for emulated cirrus device in qemu. It is *NOT* intended for real cirrus devices. This requires diff --git a/drivers/gpu/drm/tiny/cirrus.c b/drivers/gpu/drm/tiny/cirrus.c index a043e602199e..aac627615b2d 100644 --- a/drivers/gpu/drm/tiny/cirrus.c +++ b/drivers/gpu/drm/tiny/cirrus.c @@ -33,8 +33,9 @@ #include #include #include -#include #include +#include +#include #include #include #include @@ -311,22 +312,15 @@ static int cirrus_mode_set(struct cirrus_device *cirrus, return 0; } -static int cirrus_fb_blit_rect(struct drm_framebuffer *fb, +static int cirrus_fb_blit_rect(struct drm_framebuffer *fb, const struct dma_buf_map *map, struct drm_rect *rect) { struct cirrus_device *cirrus = to_cirrus(fb->dev); - struct dma_buf_map map; - void *vmap; - int idx, ret; + void *vmap = map->vaddr; /* TODO: Use mapping abstraction properly */ + int idx; - ret = -ENODEV; if (!drm_dev_enter(&cirrus->dev, &idx)) - goto out; - - ret = drm_gem_shmem_vmap(fb->obj[0], &map); - if (ret) - goto out_dev_exit; - vmap = map.vaddr; /* TODO: Use mapping abstraction properly */ + return -ENODEV; if (cirrus->cpp == fb->format->cpp[0]) drm_fb_memcpy_dstclip(cirrus->vram, @@ -345,16 +339,12 @@ static int cirrus_fb_blit_rect(struct drm_framebuffer *fb, else WARN_ON_ONCE("cpp mismatch"); - drm_gem_shmem_vunmap(fb->obj[0], &map); - ret = 0; - -out_dev_exit: drm_dev_exit(idx); -out: - return ret; + + return 0; } -static int cirrus_fb_blit_fullscreen(struct drm_framebuffer *fb) +static int cirrus_fb_blit_fullscreen(struct drm_framebuffer *fb, const struct dma_buf_map *map) { struct drm_rect fullscreen = { .x1 = 0, @@ -362,7 +352,7 @@ static int cirrus_fb_blit_fullscreen(struct drm_framebuffer *fb) .y1 = 0, .y2 = fb->height, }; - return cirrus_fb_blit_rect(fb, &fullscreen); + return cirrus_fb_blit_rect(fb, map, &fullscreen); } static int cirrus_check_size(int width, int height, @@ -441,9 +431,11 @@ static void cirrus_pipe_enable(struct drm_simple_display_pipe *pipe, struct drm_plane_state *plane_state) { struct cirrus_device *cirrus = to_cirrus(pipe->crtc.dev); + struct drm_gem_shmem_shadow_plane_state *shadow_plane_state = + to_drm_gem_shmem_shadow_plane_state(plane_state); cirrus_mode_set(cirrus, &crtc_state->mode, plane_state->fb); - cirrus_fb_blit_fullscreen(plane_state->fb); + cirrus_fb_blit_fullscreen(plane_state->fb, &shadow_plane_state->map[0]); } static void cirrus_pipe_update(struct drm_simple_display_pipe *pipe, @@ -451,16 +443,16 @@ static void cirrus_pipe_update(struct drm_simple_display_pipe *pipe, { struct cirrus_device *cirrus = to_cirrus(pipe->crtc.dev); struct drm_plane_state *state = pipe->plane.state; + struct drm_gem_shmem_shadow_plane_state *shadow_plane_state = + to_drm_gem_shmem_shadow_plane_state(state); struct drm_crtc *crtc = &pipe->crtc; struct drm_rect rect; - if (pipe->plane.state->fb && - cirrus->cpp != cirrus_cpp(pipe->plane.state->fb)) - cirrus_mode_set(cirrus, &crtc->mode, - pipe->plane.state->fb); + if (state->fb && cirrus->cpp != cirrus_cpp(state->fb)) + cirrus_mode_set(cirrus, &crtc->mode, state->fb); if (drm_atomic_helper_damage_merged(old_state, state, &rect)) - cirrus_fb_blit_rect(pipe->plane.state->fb, &rect); + cirrus_fb_blit_rect(state->fb, &shadow_plane_state->map[0], &rect); } static const struct drm_simple_display_pipe_funcs cirrus_pipe_funcs = { @@ -468,6 +460,7 @@ static const struct drm_simple_display_pipe_funcs cirrus_pipe_funcs = { .check = cirrus_pipe_check, .enable = cirrus_pipe_enable, .update = cirrus_pipe_update, + DRM_GEM_SHMEM_SIMPLE_DISPLAY_PIPE_SHADOW_PLANE_FUNCS, }; static const uint32_t cirrus_formats[] = { From patchwork Wed Feb 3 13:10:45 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Zimmermann X-Patchwork-Id: 12064343 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 03E7AC433DB for ; Wed, 3 Feb 2021 13:11:09 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id AA13764F9F for ; Wed, 3 Feb 2021 13:11:08 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org AA13764F9F Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=suse.de Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id E6F516EAB7; Wed, 3 Feb 2021 13:10:56 +0000 (UTC) Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) by gabe.freedesktop.org (Postfix) with ESMTPS id 193E26EAAE for ; Wed, 3 Feb 2021 13:10:53 +0000 (UTC) X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id A8B8CB131; Wed, 3 Feb 2021 13:10:51 +0000 (UTC) From: Thomas Zimmermann To: daniel@ffwll.ch, airlied@linux.ie, maarten.lankhorst@linux.intel.com, mripard@kernel.org, kraxel@redhat.com, hdegoede@redhat.com, sean@poorly.run, sam@ravnborg.org, noralf@tronnes.org Subject: [PATCH 5/6] drm/gm12u320: Move vmap out of commit tail Date: Wed, 3 Feb 2021 14:10:45 +0100 Message-Id: <20210203131046.22371-6-tzimmermann@suse.de> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20210203131046.22371-1-tzimmermann@suse.de> References: <20210203131046.22371-1-tzimmermann@suse.de> MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Thomas Zimmermann , dri-devel@lists.freedesktop.org, virtualization@lists.linux-foundation.org Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Vmap operations may acquire the dmabuf reservation lock, which is not allowed within atomic commit-tail functions. Therefore move vmap and vunmap from the damage handler into prepare_fb and cleanup_fb callbacks. The mapping is provided as GEM SHMEM shadow plane. The enable and prepare callbacks use the established mapping for damage handling. Signed-off-by: Thomas Zimmermann --- drivers/gpu/drm/tiny/Kconfig | 3 ++- drivers/gpu/drm/tiny/gm12u320.c | 30 +++++++++++++++--------------- 2 files changed, 17 insertions(+), 16 deletions(-) diff --git a/drivers/gpu/drm/tiny/Kconfig b/drivers/gpu/drm/tiny/Kconfig index e0aef6cf8e26..faf3926fd4fa 100644 --- a/drivers/gpu/drm/tiny/Kconfig +++ b/drivers/gpu/drm/tiny/Kconfig @@ -23,8 +23,9 @@ config DRM_CIRRUS_QEMU config DRM_GM12U320 tristate "GM12U320 driver for USB projectors" depends on DRM && USB - select DRM_KMS_HELPER select DRM_GEM_SHMEM_HELPER + select DRM_GEM_SHMEM_KMS_HELPER + select DRM_KMS_HELPER help This is a KMS driver for projectors which use the GM12U320 chipset for video transfer over USB2/3, such as the Acer C120 mini projector. diff --git a/drivers/gpu/drm/tiny/gm12u320.c b/drivers/gpu/drm/tiny/gm12u320.c index 33f65f4626e5..1d20949f429a 100644 --- a/drivers/gpu/drm/tiny/gm12u320.c +++ b/drivers/gpu/drm/tiny/gm12u320.c @@ -16,8 +16,9 @@ #include #include #include -#include #include +#include +#include #include #include #include @@ -94,6 +95,7 @@ struct gm12u320_device { struct drm_rect rect; int frame; int draw_status_timeout; + struct dma_buf_map src_map; } fb_update; }; @@ -250,7 +252,6 @@ static void gm12u320_copy_fb_to_blocks(struct gm12u320_device *gm12u320) { int block, dst_offset, len, remain, ret, x1, x2, y1, y2; struct drm_framebuffer *fb; - struct dma_buf_map map; void *vaddr; u8 *src; @@ -264,20 +265,14 @@ static void gm12u320_copy_fb_to_blocks(struct gm12u320_device *gm12u320) x2 = gm12u320->fb_update.rect.x2; y1 = gm12u320->fb_update.rect.y1; y2 = gm12u320->fb_update.rect.y2; - - ret = drm_gem_shmem_vmap(fb->obj[0], &map); - if (ret) { - GM12U320_ERR("failed to vmap fb: %d\n", ret); - goto put_fb; - } - vaddr = map.vaddr; /* TODO: Use mapping abstraction properly */ + vaddr = gm12u320->fb_update.src_map.vaddr; /* TODO: Use mapping abstraction properly */ if (fb->obj[0]->import_attach) { ret = dma_buf_begin_cpu_access( fb->obj[0]->import_attach->dmabuf, DMA_FROM_DEVICE); if (ret) { GM12U320_ERR("dma_buf_begin_cpu_access err: %d\n", ret); - goto vunmap; + goto put_fb; } } @@ -321,8 +316,6 @@ static void gm12u320_copy_fb_to_blocks(struct gm12u320_device *gm12u320) if (ret) GM12U320_ERR("dma_buf_end_cpu_access err: %d\n", ret); } -vunmap: - drm_gem_shmem_vunmap(fb->obj[0], &map); put_fb: drm_framebuffer_put(fb); gm12u320->fb_update.fb = NULL; @@ -410,7 +403,7 @@ static void gm12u320_fb_update_work(struct work_struct *work) GM12U320_ERR("Frame update error: %d\n", ret); } -static void gm12u320_fb_mark_dirty(struct drm_framebuffer *fb, +static void gm12u320_fb_mark_dirty(struct drm_framebuffer *fb, const struct dma_buf_map *map, struct drm_rect *dirty) { struct gm12u320_device *gm12u320 = to_gm12u320(fb->dev); @@ -424,6 +417,7 @@ static void gm12u320_fb_mark_dirty(struct drm_framebuffer *fb, drm_framebuffer_get(fb); gm12u320->fb_update.fb = fb; gm12u320->fb_update.rect = *dirty; + gm12u320->fb_update.src_map = *map; wakeup = true; } else { struct drm_rect *rect = &gm12u320->fb_update.rect; @@ -452,6 +446,7 @@ static void gm12u320_stop_fb_update(struct gm12u320_device *gm12u320) mutex_lock(&gm12u320->fb_update.lock); old_fb = gm12u320->fb_update.fb; gm12u320->fb_update.fb = NULL; + dma_buf_map_clear(&gm12u320->fb_update.src_map); mutex_unlock(&gm12u320->fb_update.lock); drm_framebuffer_put(old_fb); @@ -564,9 +559,11 @@ static void gm12u320_pipe_enable(struct drm_simple_display_pipe *pipe, { struct drm_rect rect = { 0, 0, GM12U320_USER_WIDTH, GM12U320_HEIGHT }; struct gm12u320_device *gm12u320 = to_gm12u320(pipe->crtc.dev); + struct drm_gem_shmem_shadow_plane_state *shadow_plane_state = + to_drm_gem_shmem_shadow_plane_state(plane_state); gm12u320->fb_update.draw_status_timeout = FIRST_FRAME_TIMEOUT; - gm12u320_fb_mark_dirty(plane_state->fb, &rect); + gm12u320_fb_mark_dirty(plane_state->fb, &shadow_plane_state->map[0], &rect); } static void gm12u320_pipe_disable(struct drm_simple_display_pipe *pipe) @@ -580,16 +577,19 @@ static void gm12u320_pipe_update(struct drm_simple_display_pipe *pipe, struct drm_plane_state *old_state) { struct drm_plane_state *state = pipe->plane.state; + struct drm_gem_shmem_shadow_plane_state *shadow_plane_state = + to_drm_gem_shmem_shadow_plane_state(state); struct drm_rect rect; if (drm_atomic_helper_damage_merged(old_state, state, &rect)) - gm12u320_fb_mark_dirty(pipe->plane.state->fb, &rect); + gm12u320_fb_mark_dirty(state->fb, &shadow_plane_state->map[0], &rect); } static const struct drm_simple_display_pipe_funcs gm12u320_pipe_funcs = { .enable = gm12u320_pipe_enable, .disable = gm12u320_pipe_disable, .update = gm12u320_pipe_update, + DRM_GEM_SHMEM_SIMPLE_DISPLAY_PIPE_SHADOW_PLANE_FUNCS, }; static const uint32_t gm12u320_pipe_formats[] = { From patchwork Wed Feb 3 13:10:46 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Zimmermann X-Patchwork-Id: 12064339 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 91BBDC433DB for ; Wed, 3 Feb 2021 13:11:05 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 4415064F92 for ; Wed, 3 Feb 2021 13:11:05 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 4415064F92 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=suse.de Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id B110E6EAAF; Wed, 3 Feb 2021 13:10:55 +0000 (UTC) Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) by gabe.freedesktop.org (Postfix) with ESMTPS id B080D6EAB2 for ; Wed, 3 Feb 2021 13:10:53 +0000 (UTC) X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 492E5B133; Wed, 3 Feb 2021 13:10:52 +0000 (UTC) From: Thomas Zimmermann To: daniel@ffwll.ch, airlied@linux.ie, maarten.lankhorst@linux.intel.com, mripard@kernel.org, kraxel@redhat.com, hdegoede@redhat.com, sean@poorly.run, sam@ravnborg.org, noralf@tronnes.org Subject: [PATCH 6/6] drm/udl: Move vmap out of commit tail Date: Wed, 3 Feb 2021 14:10:46 +0100 Message-Id: <20210203131046.22371-7-tzimmermann@suse.de> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20210203131046.22371-1-tzimmermann@suse.de> References: <20210203131046.22371-1-tzimmermann@suse.de> MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Thomas Zimmermann , dri-devel@lists.freedesktop.org, virtualization@lists.linux-foundation.org Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Vmap operations may acquire the dmabuf reservation lock, which is not allowed within atomic commit-tail functions. Therefore move vmap and vunmap from the damage handler into prepare_fb and cleanup_fb callbacks. The mapping is provided as GEM SHMEM shadow plane. The enable and prepare callbacks use the established mapping for damage handling. Signed-off-by: Thomas Zimmermann --- drivers/gpu/drm/udl/Kconfig | 1 + drivers/gpu/drm/udl/udl_modeset.c | 36 +++++++++++++------------------ 2 files changed, 16 insertions(+), 21 deletions(-) diff --git a/drivers/gpu/drm/udl/Kconfig b/drivers/gpu/drm/udl/Kconfig index 1f497d8f1ae5..1b46d93ca61c 100644 --- a/drivers/gpu/drm/udl/Kconfig +++ b/drivers/gpu/drm/udl/Kconfig @@ -5,6 +5,7 @@ config DRM_UDL depends on USB depends on USB_ARCH_HAS_HCD select DRM_GEM_SHMEM_HELPER + select DRM_GEM_SHMEM_KMS_HELPER select DRM_KMS_HELPER help This is a KMS driver for the USB displaylink video adapters. diff --git a/drivers/gpu/drm/udl/udl_modeset.c b/drivers/gpu/drm/udl/udl_modeset.c index 9d34ec9d03f6..974dffe86a44 100644 --- a/drivers/gpu/drm/udl/udl_modeset.c +++ b/drivers/gpu/drm/udl/udl_modeset.c @@ -17,6 +17,7 @@ #include #include #include +#include #include #include @@ -266,18 +267,17 @@ static int udl_aligned_damage_clip(struct drm_rect *clip, int x, int y, return 0; } -static int udl_handle_damage(struct drm_framebuffer *fb, int x, int y, - int width, int height) +static int udl_handle_damage(struct drm_framebuffer *fb, const struct dma_buf_map *map, + int x, int y, int width, int height) { struct drm_device *dev = fb->dev; struct dma_buf_attachment *import_attach = fb->obj[0]->import_attach; + void *vaddr = map->vaddr; /* TODO: Use mapping abstraction properly */ int i, ret, tmp_ret; char *cmd; struct urb *urb; struct drm_rect clip; int log_bpp; - struct dma_buf_map map; - void *vaddr; ret = udl_log_cpp(fb->format->cpp[0]); if (ret < 0) @@ -297,17 +297,10 @@ static int udl_handle_damage(struct drm_framebuffer *fb, int x, int y, return ret; } - ret = drm_gem_shmem_vmap(fb->obj[0], &map); - if (ret) { - DRM_ERROR("failed to vmap fb\n"); - goto out_dma_buf_end_cpu_access; - } - vaddr = map.vaddr; /* TODO: Use mapping abstraction properly */ - urb = udl_get_urb(dev); if (!urb) { ret = -ENOMEM; - goto out_drm_gem_shmem_vunmap; + goto out_dma_buf_end_cpu_access; } cmd = urb->transfer_buffer; @@ -320,7 +313,7 @@ static int udl_handle_damage(struct drm_framebuffer *fb, int x, int y, &cmd, byte_offset, dev_byte_offset, byte_width); if (ret) - goto out_drm_gem_shmem_vunmap; + goto out_dma_buf_end_cpu_access; } if (cmd > (char *)urb->transfer_buffer) { @@ -336,8 +329,6 @@ static int udl_handle_damage(struct drm_framebuffer *fb, int x, int y, ret = 0; -out_drm_gem_shmem_vunmap: - drm_gem_shmem_vunmap(fb->obj[0], &map); out_dma_buf_end_cpu_access: if (import_attach) { tmp_ret = dma_buf_end_cpu_access(import_attach->dmabuf, @@ -375,6 +366,8 @@ udl_simple_display_pipe_enable(struct drm_simple_display_pipe *pipe, struct drm_framebuffer *fb = plane_state->fb; struct udl_device *udl = to_udl(dev); struct drm_display_mode *mode = &crtc_state->mode; + struct drm_gem_shmem_shadow_plane_state *shadow_plane_state = + to_drm_gem_shmem_shadow_plane_state(plane_state); char *buf; char *wrptr; int color_depth = UDL_COLOR_DEPTH_16BPP; @@ -400,7 +393,7 @@ udl_simple_display_pipe_enable(struct drm_simple_display_pipe *pipe, udl->mode_buf_len = wrptr - buf; - udl_handle_damage(fb, 0, 0, fb->width, fb->height); + udl_handle_damage(fb, &shadow_plane_state->map[0], 0, 0, fb->width, fb->height); if (!crtc_state->mode_changed) return; @@ -435,6 +428,8 @@ udl_simple_display_pipe_update(struct drm_simple_display_pipe *pipe, struct drm_plane_state *old_plane_state) { struct drm_plane_state *state = pipe->plane.state; + struct drm_gem_shmem_shadow_plane_state *shadow_plane_state = + to_drm_gem_shmem_shadow_plane_state(state); struct drm_framebuffer *fb = state->fb; struct drm_rect rect; @@ -442,17 +437,16 @@ udl_simple_display_pipe_update(struct drm_simple_display_pipe *pipe, return; if (drm_atomic_helper_damage_merged(old_plane_state, state, &rect)) - udl_handle_damage(fb, rect.x1, rect.y1, rect.x2 - rect.x1, - rect.y2 - rect.y1); + udl_handle_damage(fb, &shadow_plane_state->map[0], rect.x1, rect.y1, + rect.x2 - rect.x1, rect.y2 - rect.y1); } -static const -struct drm_simple_display_pipe_funcs udl_simple_display_pipe_funcs = { +static const struct drm_simple_display_pipe_funcs udl_simple_display_pipe_funcs = { .mode_valid = udl_simple_display_pipe_mode_valid, .enable = udl_simple_display_pipe_enable, .disable = udl_simple_display_pipe_disable, .update = udl_simple_display_pipe_update, - .prepare_fb = drm_gem_fb_simple_display_pipe_prepare_fb, + DRM_GEM_SHMEM_SIMPLE_DISPLAY_PIPE_SHADOW_PLANE_FUNCS, }; /*