drm/msm/dpu: use devres-managed allocation for HW blocks
authorDmitry Baryshkov <dmitry.baryshkov@linaro.org>
Fri, 1 Dec 2023 21:18:38 +0000 (00:18 +0300)
committerDmitry Baryshkov <dmitry.baryshkov@linaro.org>
Tue, 5 Dec 2023 19:14:33 +0000 (22:14 +0300)
Use devm_kzalloc to create HW block structure. This allows us to remove
corresponding kfree and drop all dpu_hw_*_destroy() functions as well as
dpu_rm_destroy(), which becomes empty afterwards.

Reviewed-by: Jessica Zhang <quic_jesszhan@quicinc.com>
Signed-off-by: Dmitry Baryshkov <dmitry.baryshkov@linaro.org>
Patchwork: https://patchwork.freedesktop.org/patch/570041/
Link: https://lore.kernel.org/r/20231201211845.1026967-7-dmitry.baryshkov@linaro.org
23 files changed:
drivers/gpu/drm/msm/disp/dpu1/dpu_hw_ctl.c
drivers/gpu/drm/msm/disp/dpu1/dpu_hw_ctl.h
drivers/gpu/drm/msm/disp/dpu1/dpu_hw_dsc.c
drivers/gpu/drm/msm/disp/dpu1/dpu_hw_dsc.h
drivers/gpu/drm/msm/disp/dpu1/dpu_hw_dsc_1_2.c
drivers/gpu/drm/msm/disp/dpu1/dpu_hw_dspp.c
drivers/gpu/drm/msm/disp/dpu1/dpu_hw_dspp.h
drivers/gpu/drm/msm/disp/dpu1/dpu_hw_intf.c
drivers/gpu/drm/msm/disp/dpu1/dpu_hw_intf.h
drivers/gpu/drm/msm/disp/dpu1/dpu_hw_lm.c
drivers/gpu/drm/msm/disp/dpu1/dpu_hw_lm.h
drivers/gpu/drm/msm/disp/dpu1/dpu_hw_merge3d.c
drivers/gpu/drm/msm/disp/dpu1/dpu_hw_merge3d.h
drivers/gpu/drm/msm/disp/dpu1/dpu_hw_pingpong.c
drivers/gpu/drm/msm/disp/dpu1/dpu_hw_pingpong.h
drivers/gpu/drm/msm/disp/dpu1/dpu_hw_sspp.c
drivers/gpu/drm/msm/disp/dpu1/dpu_hw_sspp.h
drivers/gpu/drm/msm/disp/dpu1/dpu_hw_wb.c
drivers/gpu/drm/msm/disp/dpu1/dpu_hw_wb.h
drivers/gpu/drm/msm/disp/dpu1/dpu_kms.c
drivers/gpu/drm/msm/disp/dpu1/dpu_kms.h
drivers/gpu/drm/msm/disp/dpu1/dpu_rm.c
drivers/gpu/drm/msm/disp/dpu1/dpu_rm.h

index 86182c73460603513c9b1b9426a5e7e270df7905..e7b680a151d6d15503e973584fc009087835150b 100644 (file)
@@ -4,6 +4,9 @@
  */
 
 #include <linux/delay.h>
+
+#include <drm/drm_managed.h>
+
 #include "dpu_hwio.h"
 #include "dpu_hw_ctl.h"
 #include "dpu_kms.h"
@@ -680,14 +683,15 @@ static void _setup_ctl_ops(struct dpu_hw_ctl_ops *ops,
                ops->set_active_pipes = dpu_hw_ctl_set_fetch_pipe_active;
 };
 
-struct dpu_hw_ctl *dpu_hw_ctl_init(const struct dpu_ctl_cfg *cfg,
-               void __iomem *addr,
-               u32 mixer_count,
-               const struct dpu_lm_cfg *mixer)
+struct dpu_hw_ctl *dpu_hw_ctl_init(struct drm_device *dev,
+                                  const struct dpu_ctl_cfg *cfg,
+                                  void __iomem *addr,
+                                  u32 mixer_count,
+                                  const struct dpu_lm_cfg *mixer)
 {
        struct dpu_hw_ctl *c;
 
-       c = kzalloc(sizeof(*c), GFP_KERNEL);
+       c = drmm_kzalloc(dev, sizeof(*c), GFP_KERNEL);
        if (!c)
                return ERR_PTR(-ENOMEM);
 
@@ -702,8 +706,3 @@ struct dpu_hw_ctl *dpu_hw_ctl_init(const struct dpu_ctl_cfg *cfg,
 
        return c;
 }
-
-void dpu_hw_ctl_destroy(struct dpu_hw_ctl *ctx)
-{
-       kfree(ctx);
-}
index 1c242298ff2ee0d47e2bc90f2c73259f79f7b746..279ebd8dfbff756969bab1c8bc495cd1f462b612 100644 (file)
@@ -274,20 +274,16 @@ static inline struct dpu_hw_ctl *to_dpu_hw_ctl(struct dpu_hw_blk *hw)
 /**
  * dpu_hw_ctl_init() - Initializes the ctl_path hw driver object.
  * Should be called before accessing any ctl_path register.
+ * @dev:  Corresponding device for devres management
  * @cfg:  ctl_path catalog entry for which driver object is required
  * @addr: mapped register io address of MDP
  * @mixer_count: Number of mixers in @mixer
  * @mixer: Pointer to an array of Layer Mixers defined in the catalog
  */
-struct dpu_hw_ctl *dpu_hw_ctl_init(const struct dpu_ctl_cfg *cfg,
-               void __iomem *addr,
-               u32 mixer_count,
-               const struct dpu_lm_cfg *mixer);
-
-/**
- * dpu_hw_ctl_destroy(): Destroys ctl driver context
- * should be called to free the context
- */
-void dpu_hw_ctl_destroy(struct dpu_hw_ctl *ctx);
+struct dpu_hw_ctl *dpu_hw_ctl_init(struct drm_device *dev,
+                                  const struct dpu_ctl_cfg *cfg,
+                                  void __iomem *addr,
+                                  u32 mixer_count,
+                                  const struct dpu_lm_cfg *mixer);
 
 #endif /*_DPU_HW_CTL_H */
index 509dbaa51d87864c05adf1ec026b0327bd7dafb6..5e9aad1b2aa28361b61b2242a2f460b9960530ea 100644 (file)
@@ -3,6 +3,8 @@
  * Copyright (c) 2020-2022, Linaro Limited
  */
 
+#include <drm/drm_managed.h>
+
 #include <drm/display/drm_dsc_helper.h>
 
 #include "dpu_kms.h"
@@ -188,12 +190,13 @@ static void _setup_dsc_ops(struct dpu_hw_dsc_ops *ops,
                ops->dsc_bind_pingpong_blk = dpu_hw_dsc_bind_pingpong_blk;
 };
 
-struct dpu_hw_dsc *dpu_hw_dsc_init(const struct dpu_dsc_cfg *cfg,
+struct dpu_hw_dsc *dpu_hw_dsc_init(struct drm_device *dev,
+                                  const struct dpu_dsc_cfg *cfg,
                                   void __iomem *addr)
 {
        struct dpu_hw_dsc *c;
 
-       c = kzalloc(sizeof(*c), GFP_KERNEL);
+       c = drmm_kzalloc(dev, sizeof(*c), GFP_KERNEL);
        if (!c)
                return ERR_PTR(-ENOMEM);
 
@@ -206,8 +209,3 @@ struct dpu_hw_dsc *dpu_hw_dsc_init(const struct dpu_dsc_cfg *cfg,
 
        return c;
 }
-
-void dpu_hw_dsc_destroy(struct dpu_hw_dsc *dsc)
-{
-       kfree(dsc);
-}
index d5b597ab8c5ca199cf3d9e19b26be4a2fc546057..989c88d2449b6a8ed40164af71d6c59d905dfcf5 100644 (file)
@@ -64,20 +64,24 @@ struct dpu_hw_dsc {
 
 /**
  * dpu_hw_dsc_init() - Initializes the DSC hw driver object.
+ * @dev:  Corresponding device for devres management
  * @cfg:  DSC catalog entry for which driver object is required
  * @addr: Mapped register io address of MDP
  * Return: Error code or allocated dpu_hw_dsc context
  */
-struct dpu_hw_dsc *dpu_hw_dsc_init(const struct dpu_dsc_cfg *cfg,
-               void __iomem *addr);
+struct dpu_hw_dsc *dpu_hw_dsc_init(struct drm_device *dev,
+                                  const struct dpu_dsc_cfg *cfg,
+                                  void __iomem *addr);
 
 /**
  * dpu_hw_dsc_init_1_2() - initializes the v1.2 DSC hw driver object
+ * @dev:  Corresponding device for devres management
  * @cfg:  DSC catalog entry for which driver object is required
  * @addr: Mapped register io address of MDP
  * Returns: Error code or allocated dpu_hw_dsc context
  */
-struct dpu_hw_dsc *dpu_hw_dsc_init_1_2(const struct dpu_dsc_cfg *cfg,
+struct dpu_hw_dsc *dpu_hw_dsc_init_1_2(struct drm_device *dev,
+                                      const struct dpu_dsc_cfg *cfg,
                                       void __iomem *addr);
 
 /**
index 24fe1d98eb86aed2a922b21967adaaee19161b6a..ba193b0376fe8259cea097320200965694da7521 100644 (file)
@@ -4,6 +4,8 @@
  * Copyright (c) 2023 Qualcomm Innovation Center, Inc. All rights reserved
  */
 
+#include <drm/drm_managed.h>
+
 #include <drm/display/drm_dsc_helper.h>
 
 #include "dpu_kms.h"
@@ -367,12 +369,13 @@ static void _setup_dcs_ops_1_2(struct dpu_hw_dsc_ops *ops,
        ops->dsc_bind_pingpong_blk = dpu_hw_dsc_bind_pingpong_blk_1_2;
 }
 
-struct dpu_hw_dsc *dpu_hw_dsc_init_1_2(const struct dpu_dsc_cfg *cfg,
+struct dpu_hw_dsc *dpu_hw_dsc_init_1_2(struct drm_device *dev,
+                                      const struct dpu_dsc_cfg *cfg,
                                       void __iomem *addr)
 {
        struct dpu_hw_dsc *c;
 
-       c = kzalloc(sizeof(*c), GFP_KERNEL);
+       c = drmm_kzalloc(dev, sizeof(*c), GFP_KERNEL);
        if (!c)
                return ERR_PTR(-ENOMEM);
 
index 9419b2209af88ef500ae68552b5ca53f50778c5a..b1da88e2935f466973f9ee65d2e50e81131c34ee 100644 (file)
@@ -2,6 +2,8 @@
 /* Copyright (c) 2015-2018, The Linux Foundation. All rights reserved.
  */
 
+#include <drm/drm_managed.h>
+
 #include "dpu_hwio.h"
 #include "dpu_hw_catalog.h"
 #include "dpu_hw_lm.h"
@@ -68,15 +70,16 @@ static void _setup_dspp_ops(struct dpu_hw_dspp *c,
                c->ops.setup_pcc = dpu_setup_dspp_pcc;
 }
 
-struct dpu_hw_dspp *dpu_hw_dspp_init(const struct dpu_dspp_cfg *cfg,
-                       void __iomem *addr)
+struct dpu_hw_dspp *dpu_hw_dspp_init(struct drm_device *dev,
+                                    const struct dpu_dspp_cfg *cfg,
+                                    void __iomem *addr)
 {
        struct dpu_hw_dspp *c;
 
        if (!addr)
                return ERR_PTR(-EINVAL);
 
-       c = kzalloc(sizeof(*c), GFP_KERNEL);
+       c = drmm_kzalloc(dev, sizeof(*c), GFP_KERNEL);
        if (!c)
                return ERR_PTR(-ENOMEM);
 
@@ -90,10 +93,3 @@ struct dpu_hw_dspp *dpu_hw_dspp_init(const struct dpu_dspp_cfg *cfg,
 
        return c;
 }
-
-void dpu_hw_dspp_destroy(struct dpu_hw_dspp *dspp)
-{
-       kfree(dspp);
-}
-
-
index bea96568133011109ab6d5bf3dd1ec4216e62ab1..3b435690b6ccbf246a49a38be296d2cd2e38dcc6 100644 (file)
@@ -81,18 +81,14 @@ static inline struct dpu_hw_dspp *to_dpu_hw_dspp(struct dpu_hw_blk *hw)
 /**
  * dpu_hw_dspp_init() - Initializes the DSPP hw driver object.
  * should be called once before accessing every DSPP.
+ * @dev:  Corresponding device for devres management
  * @cfg:  DSPP catalog entry for which driver object is required
  * @addr: Mapped register io address of MDP
  * Return: pointer to structure or ERR_PTR
  */
-struct dpu_hw_dspp *dpu_hw_dspp_init(const struct dpu_dspp_cfg *cfg,
-       void __iomem *addr);
-
-/**
- * dpu_hw_dspp_destroy(): Destroys DSPP driver context
- * @dspp: Pointer to DSPP driver context
- */
-void dpu_hw_dspp_destroy(struct dpu_hw_dspp *dspp);
+struct dpu_hw_dspp *dpu_hw_dspp_init(struct drm_device *dev,
+                                    const struct dpu_dspp_cfg *cfg,
+                                    void __iomem *addr);
 
 #endif /*_DPU_HW_DSPP_H */
 
index e8b8908d3e122671fc1f49dabbad5598805bf44a..0b6a0a7dcc392198a38a0fa7328a8a276fe5b2ea 100644 (file)
@@ -12,6 +12,8 @@
 
 #include <linux/iopoll.h>
 
+#include <drm/drm_managed.h>
+
 #define INTF_TIMING_ENGINE_EN           0x000
 #define INTF_CONFIG                     0x004
 #define INTF_HSYNC_CTL                  0x008
@@ -527,8 +529,10 @@ static void dpu_hw_intf_program_intf_cmd_cfg(struct dpu_hw_intf *ctx,
        DPU_REG_WRITE(&ctx->hw, INTF_CONFIG2, intf_cfg2);
 }
 
-struct dpu_hw_intf *dpu_hw_intf_init(const struct dpu_intf_cfg *cfg,
-               void __iomem *addr, const struct dpu_mdss_version *mdss_rev)
+struct dpu_hw_intf *dpu_hw_intf_init(struct drm_device *dev,
+                                    const struct dpu_intf_cfg *cfg,
+                                    void __iomem *addr,
+                                    const struct dpu_mdss_version *mdss_rev)
 {
        struct dpu_hw_intf *c;
 
@@ -537,7 +541,7 @@ struct dpu_hw_intf *dpu_hw_intf_init(const struct dpu_intf_cfg *cfg,
                return NULL;
        }
 
-       c = kzalloc(sizeof(*c), GFP_KERNEL);
+       c = drmm_kzalloc(dev, sizeof(*c), GFP_KERNEL);
        if (!c)
                return ERR_PTR(-ENOMEM);
 
@@ -581,9 +585,3 @@ struct dpu_hw_intf *dpu_hw_intf_init(const struct dpu_intf_cfg *cfg,
 
        return c;
 }
-
-void dpu_hw_intf_destroy(struct dpu_hw_intf *intf)
-{
-       kfree(intf);
-}
-
index c539025c418bb1d2dd775ffd2b24f3536e1a14ca..215401bb042ebdb95a432d34c3361d30fc084eec 100644 (file)
@@ -131,17 +131,14 @@ struct dpu_hw_intf {
 /**
  * dpu_hw_intf_init() - Initializes the INTF driver for the passed
  * interface catalog entry.
+ * @dev:  Corresponding device for devres management
  * @cfg:  interface catalog entry for which driver object is required
  * @addr: mapped register io address of MDP
  * @mdss_rev: dpu core's major and minor versions
  */
-struct dpu_hw_intf *dpu_hw_intf_init(const struct dpu_intf_cfg *cfg,
-               void __iomem *addr, const struct dpu_mdss_version *mdss_rev);
-
-/**
- * dpu_hw_intf_destroy(): Destroys INTF driver context
- * @intf:   Pointer to INTF driver context
- */
-void dpu_hw_intf_destroy(struct dpu_hw_intf *intf);
+struct dpu_hw_intf *dpu_hw_intf_init(struct drm_device *dev,
+                                    const struct dpu_intf_cfg *cfg,
+                                    void __iomem *addr,
+                                    const struct dpu_mdss_version *mdss_rev);
 
 #endif /*_DPU_HW_INTF_H */
index d1c3bd8379ea947280d84516c607d7d70786c40b..25af52ab602f5abd7abc9167fa6c514500cd0134 100644 (file)
@@ -4,6 +4,8 @@
  * Copyright (c) 2015-2021, The Linux Foundation. All rights reserved.
  */
 
+#include <drm/drm_managed.h>
+
 #include "dpu_kms.h"
 #include "dpu_hw_catalog.h"
 #include "dpu_hwio.h"
@@ -156,8 +158,9 @@ static void _setup_mixer_ops(struct dpu_hw_lm_ops *ops,
        ops->collect_misr = dpu_hw_lm_collect_misr;
 }
 
-struct dpu_hw_mixer *dpu_hw_lm_init(const struct dpu_lm_cfg *cfg,
-               void __iomem *addr)
+struct dpu_hw_mixer *dpu_hw_lm_init(struct drm_device *dev,
+                                   const struct dpu_lm_cfg *cfg,
+                                   void __iomem *addr)
 {
        struct dpu_hw_mixer *c;
 
@@ -166,7 +169,7 @@ struct dpu_hw_mixer *dpu_hw_lm_init(const struct dpu_lm_cfg *cfg,
                return NULL;
        }
 
-       c = kzalloc(sizeof(*c), GFP_KERNEL);
+       c = drmm_kzalloc(dev, sizeof(*c), GFP_KERNEL);
        if (!c)
                return ERR_PTR(-ENOMEM);
 
@@ -180,8 +183,3 @@ struct dpu_hw_mixer *dpu_hw_lm_init(const struct dpu_lm_cfg *cfg,
 
        return c;
 }
-
-void dpu_hw_lm_destroy(struct dpu_hw_mixer *lm)
-{
-       kfree(lm);
-}
index 36992d046a533b979ab674808fe044a2a2a0ce85..8835fd10641311d156db90f597cf1953570c81d5 100644 (file)
@@ -95,16 +95,12 @@ static inline struct dpu_hw_mixer *to_dpu_hw_mixer(struct dpu_hw_blk *hw)
 /**
  * dpu_hw_lm_init() - Initializes the mixer hw driver object.
  * should be called once before accessing every mixer.
+ * @dev:  Corresponding device for devres management
  * @cfg:  mixer catalog entry for which driver object is required
  * @addr: mapped register io address of MDP
  */
-struct dpu_hw_mixer *dpu_hw_lm_init(const struct dpu_lm_cfg *cfg,
-               void __iomem *addr);
-
-/**
- * dpu_hw_lm_destroy(): Destroys layer mixer driver context
- * @lm:   Pointer to LM driver context
- */
-void dpu_hw_lm_destroy(struct dpu_hw_mixer *lm);
+struct dpu_hw_mixer *dpu_hw_lm_init(struct drm_device *dev,
+                                   const struct dpu_lm_cfg *cfg,
+                                   void __iomem *addr);
 
 #endif /*_DPU_HW_LM_H */
index 90e0e05eff8d312e85e8bb10e5fa78c15f26c639..ddfa40a959cbd08c7f6b798db97d7cf607826704 100644 (file)
@@ -4,6 +4,8 @@
 
 #include <linux/iopoll.h>
 
+#include <drm/drm_managed.h>
+
 #include "dpu_hw_mdss.h"
 #include "dpu_hwio.h"
 #include "dpu_hw_catalog.h"
@@ -37,12 +39,13 @@ static void _setup_merge_3d_ops(struct dpu_hw_merge_3d *c,
        c->ops.setup_3d_mode = dpu_hw_merge_3d_setup_3d_mode;
 };
 
-struct dpu_hw_merge_3d *dpu_hw_merge_3d_init(const struct dpu_merge_3d_cfg *cfg,
-               void __iomem *addr)
+struct dpu_hw_merge_3d *dpu_hw_merge_3d_init(struct drm_device *dev,
+                                            const struct dpu_merge_3d_cfg *cfg,
+                                            void __iomem *addr)
 {
        struct dpu_hw_merge_3d *c;
 
-       c = kzalloc(sizeof(*c), GFP_KERNEL);
+       c = drmm_kzalloc(dev, sizeof(*c), GFP_KERNEL);
        if (!c)
                return ERR_PTR(-ENOMEM);
 
@@ -55,8 +58,3 @@ struct dpu_hw_merge_3d *dpu_hw_merge_3d_init(const struct dpu_merge_3d_cfg *cfg,
 
        return c;
 }
-
-void dpu_hw_merge_3d_destroy(struct dpu_hw_merge_3d *hw)
-{
-       kfree(hw);
-}
index 19cec5e8872219ebbc2a1649c27d26c369715247..c192f02ec1abcc4049474d5d2a69cc767cc47671 100644 (file)
@@ -48,18 +48,13 @@ static inline struct dpu_hw_merge_3d *to_dpu_hw_merge_3d(struct dpu_hw_blk *hw)
 /**
  * dpu_hw_merge_3d_init() - Initializes the merge_3d driver for the passed
  * merge3d catalog entry.
+ * @dev:  Corresponding device for devres management
  * @cfg:  Pingpong catalog entry for which driver object is required
  * @addr: Mapped register io address of MDP
  * Return: Error code or allocated dpu_hw_merge_3d context
  */
-struct dpu_hw_merge_3d *dpu_hw_merge_3d_init(const struct dpu_merge_3d_cfg *cfg,
-               void __iomem *addr);
-
-/**
- * dpu_hw_merge_3d_destroy - destroys merge_3d driver context
- *     should be called to free the context
- * @pp:   Pointer to PP driver context returned by dpu_hw_merge_3d_init
- */
-void dpu_hw_merge_3d_destroy(struct dpu_hw_merge_3d *pp);
+struct dpu_hw_merge_3d *dpu_hw_merge_3d_init(struct drm_device *dev,
+                                            const struct dpu_merge_3d_cfg *cfg,
+                                            void __iomem *addr);
 
 #endif /*_DPU_HW_MERGE3D_H */
index 057cac7f5d936f8f84cb3949172c161bf0b0a1c3..2db4c6fba37ac1dc9c7c70c21393bcfbc32e2773 100644 (file)
@@ -4,6 +4,8 @@
 
 #include <linux/iopoll.h>
 
+#include <drm/drm_managed.h>
+
 #include "dpu_hw_mdss.h"
 #include "dpu_hwio.h"
 #include "dpu_hw_catalog.h"
@@ -281,12 +283,14 @@ static int dpu_hw_pp_setup_dsc(struct dpu_hw_pingpong *pp)
        return 0;
 }
 
-struct dpu_hw_pingpong *dpu_hw_pingpong_init(const struct dpu_pingpong_cfg *cfg,
-               void __iomem *addr, const struct dpu_mdss_version *mdss_rev)
+struct dpu_hw_pingpong *dpu_hw_pingpong_init(struct drm_device *dev,
+                                            const struct dpu_pingpong_cfg *cfg,
+                                            void __iomem *addr,
+                                            const struct dpu_mdss_version *mdss_rev)
 {
        struct dpu_hw_pingpong *c;
 
-       c = kzalloc(sizeof(*c), GFP_KERNEL);
+       c = drmm_kzalloc(dev, sizeof(*c), GFP_KERNEL);
        if (!c)
                return ERR_PTR(-ENOMEM);
 
@@ -317,8 +321,3 @@ struct dpu_hw_pingpong *dpu_hw_pingpong_init(const struct dpu_pingpong_cfg *cfg,
 
        return c;
 }
-
-void dpu_hw_pingpong_destroy(struct dpu_hw_pingpong *pp)
-{
-       kfree(pp);
-}
index 0d541ca5b05669191c0f022803c3743a720c11f7..a48b69fd79a3b4e8eee7240091f5ab7945ea7a48 100644 (file)
@@ -121,19 +121,15 @@ static inline struct dpu_hw_pingpong *to_dpu_hw_pingpong(struct dpu_hw_blk *hw)
 /**
  * dpu_hw_pingpong_init() - initializes the pingpong driver for the passed
  * pingpong catalog entry.
+ * @dev:  Corresponding device for devres management
  * @cfg:  Pingpong catalog entry for which driver object is required
  * @addr: Mapped register io address of MDP
  * @mdss_rev: dpu core's major and minor versions
  * Return: Error code or allocated dpu_hw_pingpong context
  */
-struct dpu_hw_pingpong *dpu_hw_pingpong_init(const struct dpu_pingpong_cfg *cfg,
-               void __iomem *addr, const struct dpu_mdss_version *mdss_rev);
-
-/**
- * dpu_hw_pingpong_destroy - destroys pingpong driver context
- *     should be called to free the context
- * @pp:   Pointer to PP driver context returned by dpu_hw_pingpong_init
- */
-void dpu_hw_pingpong_destroy(struct dpu_hw_pingpong *pp);
+struct dpu_hw_pingpong *dpu_hw_pingpong_init(struct drm_device *dev,
+                                            const struct dpu_pingpong_cfg *cfg,
+                                            void __iomem *addr,
+                                            const struct dpu_mdss_version *mdss_rev);
 
 #endif /*_DPU_HW_PINGPONG_H */
index 26307d9fc81d02f3198e8d78cf933c22c6394f9b..0bf8a83e8df368fd5df7425cdac40ebd18fbdde7 100644 (file)
@@ -11,6 +11,7 @@
 #include "msm_mdss.h"
 
 #include <drm/drm_file.h>
+#include <drm/drm_managed.h>
 
 #define DPU_FETCH_CONFIG_RESET_VALUE   0x00000087
 
@@ -669,16 +670,18 @@ int _dpu_hw_sspp_init_debugfs(struct dpu_hw_sspp *hw_pipe, struct dpu_kms *kms,
 }
 #endif
 
-struct dpu_hw_sspp *dpu_hw_sspp_init(const struct dpu_sspp_cfg *cfg,
-               void __iomem *addr, const struct msm_mdss_data *mdss_data,
-               const struct dpu_mdss_version *mdss_rev)
+struct dpu_hw_sspp *dpu_hw_sspp_init(struct drm_device *dev,
+                                    const struct dpu_sspp_cfg *cfg,
+                                    void __iomem *addr,
+                                    const struct msm_mdss_data *mdss_data,
+                                    const struct dpu_mdss_version *mdss_rev)
 {
        struct dpu_hw_sspp *hw_pipe;
 
        if (!addr)
                return ERR_PTR(-EINVAL);
 
-       hw_pipe = kzalloc(sizeof(*hw_pipe), GFP_KERNEL);
+       hw_pipe = drmm_kzalloc(dev, sizeof(*hw_pipe), GFP_KERNEL);
        if (!hw_pipe)
                return ERR_PTR(-ENOMEM);
 
@@ -693,9 +696,3 @@ struct dpu_hw_sspp *dpu_hw_sspp_init(const struct dpu_sspp_cfg *cfg,
 
        return hw_pipe;
 }
-
-void dpu_hw_sspp_destroy(struct dpu_hw_sspp *ctx)
-{
-       kfree(ctx);
-}
-
index 28e7d53bd1918e69652e9c0ce62feec6d7fb6676..b7dc52312c3924e91fa76c4009ebef5e260259bd 100644 (file)
@@ -318,21 +318,17 @@ struct dpu_kms;
 /**
  * dpu_hw_sspp_init() - Initializes the sspp hw driver object.
  * Should be called once before accessing every pipe.
+ * @dev:  Corresponding device for devres management
  * @cfg:  Pipe catalog entry for which driver object is required
  * @addr: Mapped register io address of MDP
  * @mdss_data: UBWC / MDSS configuration data
  * @mdss_rev: dpu core's major and minor versions
  */
-struct dpu_hw_sspp *dpu_hw_sspp_init(const struct dpu_sspp_cfg *cfg,
-               void __iomem *addr, const struct msm_mdss_data *mdss_data,
-               const struct dpu_mdss_version *mdss_rev);
-
-/**
- * dpu_hw_sspp_destroy(): Destroys SSPP driver context
- * should be called during Hw pipe cleanup.
- * @ctx:  Pointer to SSPP driver context returned by dpu_hw_sspp_init
- */
-void dpu_hw_sspp_destroy(struct dpu_hw_sspp *ctx);
+struct dpu_hw_sspp *dpu_hw_sspp_init(struct drm_device *dev,
+                                    const struct dpu_sspp_cfg *cfg,
+                                    void __iomem *addr,
+                                    const struct msm_mdss_data *mdss_data,
+                                    const struct dpu_mdss_version *mdss_rev);
 
 int _dpu_hw_sspp_init_debugfs(struct dpu_hw_sspp *hw_pipe, struct dpu_kms *kms,
                              struct dentry *entry);
index 9668fb97c0478b301d99973303184d1d24766e28..ed0e80616129a6ff39b72109d2869990d08d2ef3 100644 (file)
@@ -3,6 +3,8 @@
   * Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved
   */
 
+#include <drm/drm_managed.h>
+
 #include "dpu_hw_mdss.h"
 #include "dpu_hwio.h"
 #include "dpu_hw_catalog.h"
@@ -208,15 +210,17 @@ static void _setup_wb_ops(struct dpu_hw_wb_ops *ops,
                ops->setup_clk_force_ctrl = dpu_hw_wb_setup_clk_force_ctrl;
 }
 
-struct dpu_hw_wb *dpu_hw_wb_init(const struct dpu_wb_cfg *cfg,
-               void __iomem *addr, const struct dpu_mdss_version *mdss_rev)
+struct dpu_hw_wb *dpu_hw_wb_init(struct drm_device *dev,
+                                const struct dpu_wb_cfg *cfg,
+                                void __iomem *addr,
+                                const struct dpu_mdss_version *mdss_rev)
 {
        struct dpu_hw_wb *c;
 
        if (!addr)
                return ERR_PTR(-EINVAL);
 
-       c = kzalloc(sizeof(*c), GFP_KERNEL);
+       c = drmm_kzalloc(dev, sizeof(*c), GFP_KERNEL);
        if (!c)
                return ERR_PTR(-ENOMEM);
 
@@ -230,8 +234,3 @@ struct dpu_hw_wb *dpu_hw_wb_init(const struct dpu_wb_cfg *cfg,
 
        return c;
 }
-
-void dpu_hw_wb_destroy(struct dpu_hw_wb *hw_wb)
-{
-       kfree(hw_wb);
-}
index 88792f450a9271aad53fd98b2f61f1ca2723df1b..e671796ea379ce0fe7c0eae6b258cbe0e681a2a5 100644 (file)
@@ -76,18 +76,15 @@ struct dpu_hw_wb {
 
 /**
  * dpu_hw_wb_init() - Initializes the writeback hw driver object.
+ * @dev:  Corresponding device for devres management
  * @cfg:  wb_path catalog entry for which driver object is required
  * @addr: mapped register io address of MDP
  * @mdss_rev: dpu core's major and minor versions
  * Return: Error code or allocated dpu_hw_wb context
  */
-struct dpu_hw_wb *dpu_hw_wb_init(const struct dpu_wb_cfg *cfg,
-               void __iomem *addr, const struct dpu_mdss_version *mdss_rev);
-
-/**
- * dpu_hw_wb_destroy(): Destroy writeback hw driver object.
- * @hw_wb:  Pointer to writeback hw driver object
- */
-void dpu_hw_wb_destroy(struct dpu_hw_wb *hw_wb);
+struct dpu_hw_wb *dpu_hw_wb_init(struct drm_device *dev,
+                                const struct dpu_wb_cfg *cfg,
+                                void __iomem *addr,
+                                const struct dpu_mdss_version *mdss_rev);
 
 #endif /*_DPU_HW_WB_H */
index 5fcb256302b2fc0e9ab8778b8c0760bb096fcde3..dc24fe4bb3b0cfad864bf3006f96cbd1eb090f5d 100644 (file)
@@ -804,10 +804,6 @@ static void _dpu_kms_hw_destroy(struct dpu_kms *dpu_kms)
                dpu_kms->hw_vbif[i] = NULL;
        }
 
-       if (dpu_kms->rm_init)
-               dpu_rm_destroy(&dpu_kms->rm);
-       dpu_kms->rm_init = false;
-
        dpu_kms->catalog = NULL;
 
        dpu_kms->hw_mdp = NULL;
@@ -1080,14 +1076,12 @@ static int dpu_kms_hw_init(struct msm_kms *kms)
                goto err_pm_put;
        }
 
-       rc = dpu_rm_init(&dpu_kms->rm, dpu_kms->catalog, dpu_kms->mdss, dpu_kms->mmio);
+       rc = dpu_rm_init(dev, &dpu_kms->rm, dpu_kms->catalog, dpu_kms->mdss, dpu_kms->mmio);
        if (rc) {
                DPU_ERROR("rm init failed: %d\n", rc);
                goto err_pm_put;
        }
 
-       dpu_kms->rm_init = true;
-
        dpu_kms->hw_mdp = dpu_hw_mdptop_init(dev,
                                             dpu_kms->catalog->mdp,
                                             dpu_kms->mmio,
index b6f53ca6e96285324503a0903f11dad867570114..df6271017b8003d9b710c5bf60db7282df91b3cb 100644 (file)
@@ -88,7 +88,6 @@ struct dpu_kms {
        struct drm_private_obj global_state;
 
        struct dpu_rm rm;
-       bool rm_init;
 
        struct dpu_hw_vbif *hw_vbif[VBIF_MAX];
        struct dpu_hw_mdp *hw_mdp;
index 8759466e2f3799e1eb559edce553dd768bb3e0f2..0bb28cf4a6cbcd2dabd7e5f48bc1991e13183399 100644 (file)
@@ -34,72 +34,8 @@ struct dpu_rm_requirements {
        struct msm_display_topology topology;
 };
 
-int dpu_rm_destroy(struct dpu_rm *rm)
-{
-       int i;
-
-       for (i = 0; i < ARRAY_SIZE(rm->dspp_blks); i++) {
-               struct dpu_hw_dspp *hw;
-
-               if (rm->dspp_blks[i]) {
-                       hw = to_dpu_hw_dspp(rm->dspp_blks[i]);
-                       dpu_hw_dspp_destroy(hw);
-               }
-       }
-       for (i = 0; i < ARRAY_SIZE(rm->pingpong_blks); i++) {
-               struct dpu_hw_pingpong *hw;
-
-               if (rm->pingpong_blks[i]) {
-                       hw = to_dpu_hw_pingpong(rm->pingpong_blks[i]);
-                       dpu_hw_pingpong_destroy(hw);
-               }
-       }
-       for (i = 0; i < ARRAY_SIZE(rm->merge_3d_blks); i++) {
-               struct dpu_hw_merge_3d *hw;
-
-               if (rm->merge_3d_blks[i]) {
-                       hw = to_dpu_hw_merge_3d(rm->merge_3d_blks[i]);
-                       dpu_hw_merge_3d_destroy(hw);
-               }
-       }
-       for (i = 0; i < ARRAY_SIZE(rm->mixer_blks); i++) {
-               struct dpu_hw_mixer *hw;
-
-               if (rm->mixer_blks[i]) {
-                       hw = to_dpu_hw_mixer(rm->mixer_blks[i]);
-                       dpu_hw_lm_destroy(hw);
-               }
-       }
-       for (i = 0; i < ARRAY_SIZE(rm->ctl_blks); i++) {
-               struct dpu_hw_ctl *hw;
-
-               if (rm->ctl_blks[i]) {
-                       hw = to_dpu_hw_ctl(rm->ctl_blks[i]);
-                       dpu_hw_ctl_destroy(hw);
-               }
-       }
-       for (i = 0; i < ARRAY_SIZE(rm->hw_intf); i++)
-               dpu_hw_intf_destroy(rm->hw_intf[i]);
-
-       for (i = 0; i < ARRAY_SIZE(rm->dsc_blks); i++) {
-               struct dpu_hw_dsc *hw;
-
-               if (rm->dsc_blks[i]) {
-                       hw = to_dpu_hw_dsc(rm->dsc_blks[i]);
-                       dpu_hw_dsc_destroy(hw);
-               }
-       }
-
-       for (i = 0; i < ARRAY_SIZE(rm->hw_wb); i++)
-               dpu_hw_wb_destroy(rm->hw_wb[i]);
-
-       for (i = 0; i < ARRAY_SIZE(rm->hw_sspp); i++)
-               dpu_hw_sspp_destroy(rm->hw_sspp[i]);
-
-       return 0;
-}
-
-int dpu_rm_init(struct dpu_rm *rm,
+int dpu_rm_init(struct drm_device *dev,
+               struct dpu_rm *rm,
                const struct dpu_mdss_cfg *cat,
                const struct msm_mdss_data *mdss_data,
                void __iomem *mmio)
@@ -119,7 +55,7 @@ int dpu_rm_init(struct dpu_rm *rm,
                struct dpu_hw_mixer *hw;
                const struct dpu_lm_cfg *lm = &cat->mixer[i];
 
-               hw = dpu_hw_lm_init(lm, mmio);
+               hw = dpu_hw_lm_init(dev, lm, mmio);
                if (IS_ERR(hw)) {
                        rc = PTR_ERR(hw);
                        DPU_ERROR("failed lm object creation: err %d\n", rc);
@@ -132,7 +68,7 @@ int dpu_rm_init(struct dpu_rm *rm,
                struct dpu_hw_merge_3d *hw;
                const struct dpu_merge_3d_cfg *merge_3d = &cat->merge_3d[i];
 
-               hw = dpu_hw_merge_3d_init(merge_3d, mmio);
+               hw = dpu_hw_merge_3d_init(dev, merge_3d, mmio);
                if (IS_ERR(hw)) {
                        rc = PTR_ERR(hw);
                        DPU_ERROR("failed merge_3d object creation: err %d\n",
@@ -146,7 +82,7 @@ int dpu_rm_init(struct dpu_rm *rm,
                struct dpu_hw_pingpong *hw;
                const struct dpu_pingpong_cfg *pp = &cat->pingpong[i];
 
-               hw = dpu_hw_pingpong_init(pp, mmio, cat->mdss_ver);
+               hw = dpu_hw_pingpong_init(dev, pp, mmio, cat->mdss_ver);
                if (IS_ERR(hw)) {
                        rc = PTR_ERR(hw);
                        DPU_ERROR("failed pingpong object creation: err %d\n",
@@ -162,7 +98,7 @@ int dpu_rm_init(struct dpu_rm *rm,
                struct dpu_hw_intf *hw;
                const struct dpu_intf_cfg *intf = &cat->intf[i];
 
-               hw = dpu_hw_intf_init(intf, mmio, cat->mdss_ver);
+               hw = dpu_hw_intf_init(dev, intf, mmio, cat->mdss_ver);
                if (IS_ERR(hw)) {
                        rc = PTR_ERR(hw);
                        DPU_ERROR("failed intf object creation: err %d\n", rc);
@@ -175,7 +111,7 @@ int dpu_rm_init(struct dpu_rm *rm,
                struct dpu_hw_wb *hw;
                const struct dpu_wb_cfg *wb = &cat->wb[i];
 
-               hw = dpu_hw_wb_init(wb, mmio, cat->mdss_ver);
+               hw = dpu_hw_wb_init(dev, wb, mmio, cat->mdss_ver);
                if (IS_ERR(hw)) {
                        rc = PTR_ERR(hw);
                        DPU_ERROR("failed wb object creation: err %d\n", rc);
@@ -188,7 +124,7 @@ int dpu_rm_init(struct dpu_rm *rm,
                struct dpu_hw_ctl *hw;
                const struct dpu_ctl_cfg *ctl = &cat->ctl[i];
 
-               hw = dpu_hw_ctl_init(ctl, mmio, cat->mixer_count, cat->mixer);
+               hw = dpu_hw_ctl_init(dev, ctl, mmio, cat->mixer_count, cat->mixer);
                if (IS_ERR(hw)) {
                        rc = PTR_ERR(hw);
                        DPU_ERROR("failed ctl object creation: err %d\n", rc);
@@ -201,7 +137,7 @@ int dpu_rm_init(struct dpu_rm *rm,
                struct dpu_hw_dspp *hw;
                const struct dpu_dspp_cfg *dspp = &cat->dspp[i];
 
-               hw = dpu_hw_dspp_init(dspp, mmio);
+               hw = dpu_hw_dspp_init(dev, dspp, mmio);
                if (IS_ERR(hw)) {
                        rc = PTR_ERR(hw);
                        DPU_ERROR("failed dspp object creation: err %d\n", rc);
@@ -215,9 +151,9 @@ int dpu_rm_init(struct dpu_rm *rm,
                const struct dpu_dsc_cfg *dsc = &cat->dsc[i];
 
                if (test_bit(DPU_DSC_HW_REV_1_2, &dsc->features))
-                       hw = dpu_hw_dsc_init_1_2(dsc, mmio);
+                       hw = dpu_hw_dsc_init_1_2(dev, dsc, mmio);
                else
-                       hw = dpu_hw_dsc_init(dsc, mmio);
+                       hw = dpu_hw_dsc_init(dev, dsc, mmio);
 
                if (IS_ERR(hw)) {
                        rc = PTR_ERR(hw);
@@ -231,7 +167,7 @@ int dpu_rm_init(struct dpu_rm *rm,
                struct dpu_hw_sspp *hw;
                const struct dpu_sspp_cfg *sspp = &cat->sspp[i];
 
-               hw = dpu_hw_sspp_init(sspp, mmio, mdss_data, cat->mdss_ver);
+               hw = dpu_hw_sspp_init(dev, sspp, mmio, mdss_data, cat->mdss_ver);
                if (IS_ERR(hw)) {
                        rc = PTR_ERR(hw);
                        DPU_ERROR("failed sspp object creation: err %d\n", rc);
@@ -243,8 +179,6 @@ int dpu_rm_init(struct dpu_rm *rm,
        return 0;
 
 fail:
-       dpu_rm_destroy(rm);
-
        return rc ? rc : -EFAULT;
 }
 
index 2b551566cbf48666c6c682422dcc7c8dc193b199..36752d837be4c428ddd07c0860765d96e7b79477 100644 (file)
@@ -38,24 +38,19 @@ struct dpu_rm {
 /**
  * dpu_rm_init - Read hardware catalog and create reservation tracking objects
  *     for all HW blocks.
+ * @dev:  Corresponding device for devres management
  * @rm: DPU Resource Manager handle
  * @cat: Pointer to hardware catalog
  * @mdss_data: Pointer to MDSS / UBWC configuration
  * @mmio: mapped register io address of MDP
  * @Return: 0 on Success otherwise -ERROR
  */
-int dpu_rm_init(struct dpu_rm *rm,
+int dpu_rm_init(struct drm_device *dev,
+               struct dpu_rm *rm,
                const struct dpu_mdss_cfg *cat,
                const struct msm_mdss_data *mdss_data,
                void __iomem *mmio);
 
-/**
- * dpu_rm_destroy - Free all memory allocated by dpu_rm_init
- * @rm: DPU Resource Manager handle
- * @Return: 0 on Success otherwise -ERROR
- */
-int dpu_rm_destroy(struct dpu_rm *rm);
-
 /**
  * dpu_rm_reserve - Given a CRTC->Encoder->Connector display chain, analyze
  *     the use connections and user requirements, specified through related