From patchwork Mon Mar 19 17:31:13 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Paul X-Patchwork-Id: 10293519 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 7C2C7602BD for ; Mon, 19 Mar 2018 17:31:19 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 66BDE294A9 for ; Mon, 19 Mar 2018 17:31:19 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 590822948D; Mon, 19 Mar 2018 17:31:19 +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 8658B294A9 for ; Mon, 19 Mar 2018 17:31:18 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 5BF6F6E5C1; Mon, 19 Mar 2018 17:31:17 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-yb0-x243.google.com (mail-yb0-x243.google.com [IPv6:2607:f8b0:4002:c09::243]) by gabe.freedesktop.org (Postfix) with ESMTPS id ED2036E5A3 for ; Mon, 19 Mar 2018 17:31:15 +0000 (UTC) Received: by mail-yb0-x243.google.com with SMTP id b4-v6so370916ybi.0 for ; Mon, 19 Mar 2018 10:31:15 -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=cCcr0utoQfKhACpwANXQg2nEYh/ne6KWKv1SzU7+344=; b=kXsn4ogsd0XAGE+RAGom1lGTHVf1UfID9x+Q9PQKSD9DY4O9EowJK/80l8GDbwqJUT lPlPRJbBFs2IzgE6FWBhaJKf6FLVwi0G7kJMMKSoRI3LC9udVGNejLvJeruBorRD2j6a jE6cmOmyH1yl/AB3j6IAcetu7G259pKECG/aQ= 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=cCcr0utoQfKhACpwANXQg2nEYh/ne6KWKv1SzU7+344=; b=rWDIUIv4c1b1qU42uDd3nAnZSqKEFnVcZ5a/5ENLGWX1ioqEeQPwSdfAGpCp+U5/6s 1G7m9qqJXxYGmuXSemNKUEeY8yTcOrAw2YAWfkSdEsAv3KELBvw8JIcIFhi56IhfX8bd wW/3JDIg0TR+Cyfl7nRdzgTMQlccd38i8FoH8gQ1N0m469Qq5/AXPaI5zWPuxA91MuiW oJbVM3OniyjLo5gaEj/WYqEyZRwnIFu+eLAJjziA6jSBR+e6pRC6DKnDgjlMT1MODY1d 3GQCap7pTNBWcLY2GW/4DVAcrG/Iw5gzQqMB61ZWvdU0EU1rG4ecIV060z1SF5CuyH/i n+rA== X-Gm-Message-State: AElRT7GOF4pL+hAtOLCZ3B/pF4lqwHX6pOgFv2RNOW/v9VQpkpX+s0Zj kP71HE2Cll7XgSaYzAh73zQ8gQ== X-Google-Smtp-Source: AG47ELvdO9KzN6AjNvNaPSQAeD9CBl4sr+UNZfawbk41AgjAUlckAg4dOjOpCJNflt2awhhVRlfrzg== X-Received: by 2002:a25:c8c6:: with SMTP id y189-v6mr7528740ybf.377.1521480674740; Mon, 19 Mar 2018 10:31:14 -0700 (PDT) Received: from rosewood.cam.corp.google.com ([2620:0:1013:11:ad55:b1db:adfe:3b9f]) by smtp.gmail.com with ESMTPSA id c186sm198283ywe.55.2018.03.19.10.31.13 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 19 Mar 2018 10:31:14 -0700 (PDT) From: Sean Paul To: freedreno@lists.freedesktop.org, linux-arm-msm@vger.kernel.org, dri-devel@lists.freedesktop.org Subject: [DPU PATCH v2] drm/msm: Use atomic private_obj instead of subclassing Date: Mon, 19 Mar 2018 13:31:13 -0400 Message-Id: <20180319173113.94879-1-seanpaul@chromium.org> X-Mailer: git-send-email 2.16.2.804.g6dcf76e118-goog In-Reply-To: <20180312202823.GC223881@art_vandelay> References: <20180312202823.GC223881@art_vandelay> 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) Cc: Jeykumar Sankaran Signed-off-by: Sean Paul Reviewed-by: Jeykumar Sankaran --- 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 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..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)