From patchwork Mon Mar 19 19:58:53 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Paul X-Patchwork-Id: 10294691 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 EE07860385 for ; Mon, 19 Mar 2018 19:58:59 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DD50E2949C for ; Mon, 19 Mar 2018 19:58:59 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D1F04294C8; Mon, 19 Mar 2018 19:58:59 +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 226C0294BC for ; Mon, 19 Mar 2018 19:58:59 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id A42F26E604; Mon, 19 Mar 2018 19:58:57 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-yb0-x242.google.com (mail-yb0-x242.google.com [IPv6:2607:f8b0:4002:c09::242]) by gabe.freedesktop.org (Postfix) with ESMTPS id 4E7816E5FE for ; Mon, 19 Mar 2018 19:58:56 +0000 (UTC) Received: by mail-yb0-x242.google.com with SMTP id p186-v6so526169ybg.7 for ; Mon, 19 Mar 2018 12:58:56 -0700 (PDT) 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=mconvnf4LnJqqRWUY/H6v+mHw+UdNHjqXKZteWWlmSE=; b=frQyiXhc3qzZIb4LOu2f4hL31H55qTagx9KJSL5iW+YQpaE3LlBSJKbKiBrqhIgkdQ sab9sqapj4z0MWQbRHvs7j/z1eLrvavHs8WF1DHhqDqNYFllLB4un2bEnxo4ZUCJwmtK qITBj62gmgu4Gg2UT/wl5vJYfMuIkREqwZWLk= 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=mconvnf4LnJqqRWUY/H6v+mHw+UdNHjqXKZteWWlmSE=; b=EvU3p4aGOVEutieG4OL6UDqus53AoXWs+cUTaNmjJXumhJUq9H/QgqDvM2B4kzBdJ8 oxWRFrV1YdbFON9Jb07Wag/5mR8CvM5VBDaiKCLLnq1jFAqBfIUwfMlz3tKbjHLdVDG+ tlLBN6Dv9FExaSIwntOHynGWu6fQOry0VOfMQOQVf0e3QaELfgWtHnk1QmNAPhm/8Qg1 KGgiIPz04PpDgY/6JlPXSRWVdgxY69IgXYDWPBGa2X0yUQeQIJqxbht2mK0LTQrENMCj QzX3a0ULF6iXfrSukQg9FCOYFWW0gLCSo06FPRNO1jhQa0lZN2d3AdbcB2hDU0Lq8+rd M8JA== X-Gm-Message-State: AElRT7H2k5Ejdra3BOj81OazjfYzUm2EjKEe1J2ZMoZtKN7TgOBYiq+e PlUx7c6xqNi2G/sy1IRTyOmHefFW/is= X-Google-Smtp-Source: AG47ELtPm9Vyma1dku+7KkMHyguTuFS9ek30Ja7D5KM+qy9xg1Q9G1P+ltXM8JYWtHHe23VqtYCzPQ== X-Received: by 2002:a25:5c05:: with SMTP id q5-v6mr7906907ybb.231.1521489535123; Mon, 19 Mar 2018 12:58:55 -0700 (PDT) Received: from rosewood.cam.corp.google.com ([2620:0:1013:11:ad55:b1db:adfe:3b9f]) by smtp.gmail.com with ESMTPSA id b63sm305188ywf.40.2018.03.19.12.58.54 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 19 Mar 2018 12:58:54 -0700 (PDT) From: Sean Paul To: freedreno@lists.freedesktop.org, linux-arm-msm@vger.kernel.org, dri-devel@lists.freedesktop.org Subject: [DPU PATCH v3] drm/msm: Use atomic private_obj instead of subclassing Date: Mon, 19 Mar 2018 15:58:53 -0400 Message-Id: <20180319195853.49006-1-seanpaul@chromium.org> X-Mailer: git-send-email 2.16.2.804.g6dcf76e118-goog In-Reply-To: References: 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. Changes in v2: - Use state->state in disp duplicate_state callback (Jeykumar) Changes in v3: - Update comment describing msm_kms_state (Jeykumar) Cc: Jeykumar Sankaran Reviewed-by: Jeykumar Sankaran 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 | 27 +++++----- 5 files changed, 94 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 5219792e93bc..4c0740dc7854 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 = drm_atomic_helper_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->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..5c1bcaf65fd9 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,7 +116,20 @@ struct msm_kms_funcs { #endif }; +/** + * Subclass of drm_private_state, to allow kms backend to have driver + * private global state. The kms backend can do whatever it wants + * with the ->state ptr. + */ +struct msm_kms_state { + struct drm_private_state base; + void *state; +}; + 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 */ @@ -124,18 +139,6 @@ struct msm_kms { 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 - * with the ->state ptr. On ->atomic_state_clear() the ->state ptr - * is kfree'd and set back to NULL. - */ -struct msm_kms_state { - struct drm_atomic_state base; - void *state; -}; -#define to_kms_state(x) container_of(x, struct msm_kms_state, base) - static inline void msm_kms_init(struct msm_kms *kms, const struct msm_kms_funcs *funcs) {