From patchwork Wed Feb 28 19:19:02 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Paul X-Patchwork-Id: 10249429 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 1D6F860211 for ; Wed, 28 Feb 2018 19:20:04 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 05B9D28DB1 for ; Wed, 28 Feb 2018 19:20:04 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E9CC628E61; Wed, 28 Feb 2018 19:20:03 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.1 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 13D7C28DB1 for ; Wed, 28 Feb 2018 19:20:02 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id A64426EB5B; Wed, 28 Feb 2018 19:19:28 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-yw0-x244.google.com (mail-yw0-x244.google.com [IPv6:2607:f8b0:4002:c05::244]) by gabe.freedesktop.org (Postfix) with ESMTPS id C85826EB41 for ; Wed, 28 Feb 2018 19:19:15 +0000 (UTC) Received: by mail-yw0-x244.google.com with SMTP id g198so1206180ywb.3 for ; Wed, 28 Feb 2018 11:19:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=v16A/8CLCuwGqsFHcyI2jxjwcEEvv3PBILpHTFj79wA=; b=Id0OS2w+fSfU8IhzFW5UX9DzW2YcxZpjYn6JG6EQZmScqwCekpZc9FV7QRHjIu9Lzq 0WA6ZIkhgbt9+9jrtdqJjm/MN79V/A+mNOSY32vgVG9+/9SJiilsB/y61Q7s12kMTAm2 /dfdRTAjUB9nScUjk7Xkg+gTU+Az9dp39zjmE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=v16A/8CLCuwGqsFHcyI2jxjwcEEvv3PBILpHTFj79wA=; b=SXAGaz+R67ZH7YrgIL2LO5yOvFG31HqK3/c4zXt+YF4jlu3ajopdVjs56OWTVWpthe 3g+xrwZzGsuTikDAAjrTHvgVBaZY0dyT7mqoT6P1/aBs1N6wyNwQp7ZbVoGseFMFIgJ6 +WVxpJP0WgE1rueKGfQuL/HruUMbDy8S+Kr6maXmXL+ZDZZikrtsRssNR0jpkxIa+GRu XA3MwRZ++xurZE2WxJB47ZJdLQrwxrln6R29LwPuRLK3lCXLceKXd2hlAvAqCUNJIZ9c yvH7NuAO2xn/eyLDtwW+GfgY6bFXxmsT/Xm+YmqUdmdfmTffYc51iiVvv35R36HAgAdZ m4cA== X-Gm-Message-State: APf1xPA7NK0hH/tiL5IonUYEjIPJ+/LLAuzffcHqbAsybIhGcUjbFh9C WSZ+jQVAu9RGe5zwoOsjQ5qWpQ== X-Google-Smtp-Source: AH8x227zk8GZDC8A5wxPXp3eEMKeIDLhJG+5T2UaJmmy3OV3k1icD2hroZQRSTblaPjwRwx7cQ6JTg== X-Received: by 10.129.98.133 with SMTP id w127mr12951171ywb.254.1519845554785; Wed, 28 Feb 2018 11:19:14 -0800 (PST) Received: from rosewood.cam.corp.google.com ([2620:0:1013:11:ad55:b1db:adfe:3b9f]) by smtp.gmail.com with ESMTPSA id u62sm884594ywa.19.2018.02.28.11.19.13 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 28 Feb 2018 11:19:13 -0800 (PST) From: Sean Paul To: freedreno@lists.freedesktop.org, linux-arm-msm@vger.kernel.org, dri-devel@lists.freedesktop.org Subject: [DPU PATCH 07/11] drm/msm: Use atomic private_obj instead of subclassing Date: Wed, 28 Feb 2018 14:19:02 -0500 Message-Id: <20180228191906.185417-8-seanpaul@chromium.org> X-Mailer: git-send-email 2.16.2.395.g2e18187dfd-goog In-Reply-To: <20180228191906.185417-1-seanpaul@chromium.org> References: <20180228191906.185417-1-seanpaul@chromium.org> X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: hoegsberg@chromium.org, abhinavk@codeaurora.org MIME-Version: 1.0 Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP Instead of subclassing atomic state, store driver private data in private_obj/state. This allows us to remove the swap_state driver hook for mdp5 and get closer to using the atomic helpers entirely. Change-Id: I65a4a2887593ae257d584e00b352b5daf00e4e61 Signed-off-by: Sean Paul --- drivers/gpu/drm/msm/disp/mdp5/mdp5_kms.c | 37 ++++++-------- drivers/gpu/drm/msm/msm_atomic.c | 30 ----------- drivers/gpu/drm/msm/msm_drv.c | 65 ++++++++++++++++++++++-- drivers/gpu/drm/msm/msm_drv.h | 4 +- drivers/gpu/drm/msm/msm_kms.h | 28 +++++----- 5 files changed, 95 insertions(+), 69 deletions(-) diff --git a/drivers/gpu/drm/msm/disp/mdp5/mdp5_kms.c b/drivers/gpu/drm/msm/disp/mdp5/mdp5_kms.c index 6d8e3a9a6fc0..f1a248419655 100644 --- a/drivers/gpu/drm/msm/disp/mdp5/mdp5_kms.c +++ b/drivers/gpu/drm/msm/disp/mdp5/mdp5_kms.c @@ -74,36 +74,32 @@ struct mdp5_state *mdp5_get_state(struct drm_atomic_state *s) { struct msm_drm_private *priv = s->dev->dev_private; struct mdp5_kms *mdp5_kms = to_mdp5_kms(to_mdp_kms(priv->kms)); - struct msm_kms_state *state = to_kms_state(s); - struct mdp5_state *new_state; + struct msm_kms_state *kms_state; int ret; - if (state->state) - return state->state; - ret = drm_modeset_lock(&mdp5_kms->state_lock, s->acquire_ctx); if (ret) return ERR_PTR(ret); - new_state = kmalloc(sizeof(*mdp5_kms->state), GFP_KERNEL); - if (!new_state) - return ERR_PTR(-ENOMEM); + kms_state = msm_kms_get_state(s); + if (IS_ERR_OR_NULL(kms_state)) + return (struct mdp5_state *)kms_state; /* casting ERR_PTR */ - /* Copy state: */ - new_state->hwpipe = mdp5_kms->state->hwpipe; - new_state->hwmixer = mdp5_kms->state->hwmixer; - if (mdp5_kms->smp) - new_state->smp = mdp5_kms->state->smp; + return kms_state->state; +} - state->state = new_state; +static void *mdp5_duplicate_state(void *state) +{ + if (!state) + return kzalloc(sizeof(struct mdp5_state), GFP_KERNEL); - return new_state; + return kmemdup(state, sizeof(struct mdp5_state), GFP_KERNEL); } -static void mdp5_swap_state(struct msm_kms *kms, struct drm_atomic_state *state) +static void mdp5_destroy_state(void *state) { - struct mdp5_kms *mdp5_kms = to_mdp5_kms(to_mdp_kms(kms)); - swap(to_kms_state(state)->state, mdp5_kms->state); + struct mdp5_state *mdp_state = state; + kfree(mdp_state); } static void mdp5_prepare_commit(struct msm_kms *kms, struct drm_atomic_state *state) @@ -229,7 +225,8 @@ static const struct mdp_kms_funcs kms_funcs = { .irq = mdp5_irq, .enable_vblank = mdp5_enable_vblank, .disable_vblank = mdp5_disable_vblank, - .swap_state = mdp5_swap_state, + .duplicate_state = mdp5_duplicate_state, + .destroy_state = mdp5_destroy_state, .prepare_commit = mdp5_prepare_commit, .complete_commit = mdp5_complete_commit, .wait_for_crtc_commit_done = mdp5_wait_for_crtc_commit_done, @@ -726,8 +723,6 @@ static void mdp5_destroy(struct platform_device *pdev) if (mdp5_kms->rpm_enabled) pm_runtime_disable(&pdev->dev); - - kfree(mdp5_kms->state); } static int construct_pipes(struct mdp5_kms *mdp5_kms, int cnt, diff --git a/drivers/gpu/drm/msm/msm_atomic.c b/drivers/gpu/drm/msm/msm_atomic.c index 7e54eb65d096..1f53262ea46b 100644 --- a/drivers/gpu/drm/msm/msm_atomic.c +++ b/drivers/gpu/drm/msm/msm_atomic.c @@ -169,9 +169,6 @@ int msm_atomic_commit(struct drm_device *dev, */ BUG_ON(drm_atomic_helper_swap_state(state, false) < 0); - if (to_kms_state(state)->state) - priv->kms->funcs->swap_state(priv->kms, state); - /* * Provide the driver a chance to prepare for output fences. This is * done after the point of no return, but before asynchronous commits @@ -210,30 +207,3 @@ int msm_atomic_commit(struct drm_device *dev, drm_atomic_helper_cleanup_planes(dev, state); return ret; } - -struct drm_atomic_state *msm_atomic_state_alloc(struct drm_device *dev) -{ - struct msm_kms_state *state = kzalloc(sizeof(*state), GFP_KERNEL); - - if (!state || drm_atomic_state_init(dev, &state->base) < 0) { - kfree(state); - return NULL; - } - - return &state->base; -} - -void msm_atomic_state_clear(struct drm_atomic_state *s) -{ - struct msm_kms_state *state = to_kms_state(s); - drm_atomic_state_default_clear(&state->base); - kfree(state->state); - state->state = NULL; -} - -void msm_atomic_state_free(struct drm_atomic_state *state) -{ - kfree(to_kms_state(state)->state); - drm_atomic_state_default_release(state); - kfree(state); -} diff --git a/drivers/gpu/drm/msm/msm_drv.c b/drivers/gpu/drm/msm/msm_drv.c index b354424cccb5..e582d5889b66 100644 --- a/drivers/gpu/drm/msm/msm_drv.c +++ b/drivers/gpu/drm/msm/msm_drv.c @@ -121,9 +121,62 @@ static const struct drm_mode_config_funcs mode_config_funcs = { .output_poll_changed = msm_fb_output_poll_changed, .atomic_check = msm_atomic_check, .atomic_commit = msm_atomic_commit, - .atomic_state_alloc = msm_atomic_state_alloc, - .atomic_state_clear = msm_atomic_state_clear, - .atomic_state_free = msm_atomic_state_free, +}; + +static inline +struct msm_kms *obj_to_kms(struct drm_private_obj *obj) +{ + return container_of(obj, struct msm_kms, base); +} + +static inline +struct msm_kms_state *state_to_kms_state(struct drm_private_state *state) +{ + return container_of(state, struct msm_kms_state, base); +} + +struct msm_kms_state *msm_kms_get_state(struct drm_atomic_state *s) +{ + struct msm_drm_private *priv = s->dev->dev_private; + struct drm_private_obj *obj = &priv->kms->base; + struct drm_private_state *state; + + state = drm_atomic_get_private_obj_state(s, obj); + if (IS_ERR_OR_NULL(state)) + return (struct msm_kms_state *)state; /* casting ERR_PTR */ + + return state_to_kms_state(state); +} + +static struct drm_private_state * +msm_kms_duplicate_state(struct drm_private_obj *obj) +{ + struct msm_kms *kms = obj_to_kms(obj); + struct msm_kms_state *state = state_to_kms_state(obj->state); + struct msm_kms_state *new_state; + + if (kms->funcs->duplicate_state) + new_state = kms->funcs->duplicate_state(state); + + __drm_atomic_helper_private_obj_duplicate_state(obj, &new_state->base); + + return &new_state->base; +} + +static void msm_kms_destroy_state(struct drm_private_obj *obj, + struct drm_private_state *state) +{ + struct msm_kms *kms = obj_to_kms(obj); + struct msm_kms_state *kms_state = state_to_kms_state(obj->state); + + if (kms->funcs->destroy_state) + kms->funcs->destroy_state(kms_state->state); + kfree(kms_state); +} + +static const struct drm_private_state_funcs kms_state_funcs = { + .atomic_duplicate_state = msm_kms_duplicate_state, + .atomic_destroy_state = msm_kms_destroy_state, }; #ifdef CONFIG_DRM_MSM_REGISTER_LOGGING @@ -341,6 +394,8 @@ static int msm_drm_uninit(struct device *dev) } } + drm_atomic_private_obj_fini(&kms->base); + msm_gem_shrinker_cleanup(ddev); drm_kms_helper_poll_fini(ddev); @@ -770,6 +825,10 @@ static int msm_drm_init(struct device *dev, struct drm_driver *drv) } #endif + drm_atomic_private_obj_init(&kms->base, + &kms->state.base, + &kms_state_funcs); + /* perform subdriver post initialization */ if (kms && kms->funcs && kms->funcs->postinit) { ret = kms->funcs->postinit(kms); diff --git a/drivers/gpu/drm/msm/msm_drv.h b/drivers/gpu/drm/msm/msm_drv.h index 292496b682e8..8cab333df717 100644 --- a/drivers/gpu/drm/msm/msm_drv.h +++ b/drivers/gpu/drm/msm/msm_drv.h @@ -598,9 +598,7 @@ struct msm_format { int msm_atomic_commit(struct drm_device *dev, struct drm_atomic_state *state, bool nonblock); -struct drm_atomic_state *msm_atomic_state_alloc(struct drm_device *dev); -void msm_atomic_state_clear(struct drm_atomic_state *state); -void msm_atomic_state_free(struct drm_atomic_state *state); +struct msm_kms_state *msm_kms_get_state(struct drm_atomic_state *state); void msm_gem_unmap_vma(struct msm_gem_address_space *aspace, struct msm_gem_vma *vma, struct sg_table *sgt); diff --git a/drivers/gpu/drm/msm/msm_kms.h b/drivers/gpu/drm/msm/msm_kms.h index 09ba1e79db50..4c5a69258c42 100644 --- a/drivers/gpu/drm/msm/msm_kms.h +++ b/drivers/gpu/drm/msm/msm_kms.h @@ -57,6 +57,8 @@ struct msm_kms_funcs { void (*disable_vblank)(struct msm_kms *kms, struct drm_crtc *crtc); /* swap global atomic state: */ void (*swap_state)(struct msm_kms *kms, struct drm_atomic_state *state); + void *(*duplicate_state)(void *state); + void (*destroy_state)(void *state); /* modeset, bracketing atomic_commit(): */ void (*prepare_fence)(struct msm_kms *kms, struct drm_atomic_state *state); @@ -114,16 +116,6 @@ struct msm_kms_funcs { #endif }; -struct msm_kms { - const struct msm_kms_funcs *funcs; - - /* irq number to be passed on to drm_irq_install */ - int irq; - - /* mapper-id used to request GEM buffer mapped for scanout: */ - struct msm_gem_address_space *aspace; -}; - /** * Subclass of drm_atomic_state, to allow kms backend to have driver * private global state. The kms backend can do whatever it wants @@ -131,10 +123,22 @@ struct msm_kms { * is kfree'd and set back to NULL. */ struct msm_kms_state { - struct drm_atomic_state base; + struct drm_private_state base; void *state; }; -#define to_kms_state(x) container_of(x, struct msm_kms_state, base) + +struct msm_kms { + struct drm_private_obj base; + struct msm_kms_state state; + + const struct msm_kms_funcs *funcs; + + /* irq number to be passed on to drm_irq_install */ + int irq; + + /* mapper-id used to request GEM buffer mapped for scanout: */ + struct msm_gem_address_space *aspace; +}; static inline void msm_kms_init(struct msm_kms *kms, const struct msm_kms_funcs *funcs)