Re: [PATCH v3 08/10] drm: rcar-du: Create a group state object

2019-06-18 Thread Ulrich Hecht


> On June 17, 2019 at 11:09 PM Laurent Pinchart 
>  wrote:
> 
> 
> From: Kieran Bingham 
> 
> Create a new private state object for the DU groups, and move the
> initialisation of a group object to a new function rcar_du_group_init().
> 
> Signed-off-by: Kieran Bingham 
> Signed-off-by: Laurent Pinchart 
> ---
> Changes since v2:
> 
> - Call mutex_destroy() when cleaning up the group
> - Include mutex.h and slab.h
> - Squash "drm: rcar-du: Add rcar_du_get_{old,new}_group_state()"
> ---
>  drivers/gpu/drm/rcar-du/rcar_du_group.c | 144 
>  drivers/gpu/drm/rcar-du/rcar_du_group.h |  29 +
>  drivers/gpu/drm/rcar-du/rcar_du_kms.c   |  27 +
>  3 files changed, 177 insertions(+), 23 deletions(-)
> 
> diff --git a/drivers/gpu/drm/rcar-du/rcar_du_group.c 
> b/drivers/gpu/drm/rcar-du/rcar_du_group.c
> index 9eee47969e77..8e12bd42890e 100644
> --- a/drivers/gpu/drm/rcar-du/rcar_du_group.c
> +++ b/drivers/gpu/drm/rcar-du/rcar_du_group.c
> @@ -25,6 +25,11 @@
>  
>  #include 
>  #include 
> +#include 
> +
> +#include 
> +#include 
> +#include 
>  
>  #include "rcar_du_drv.h"
>  #include "rcar_du_group.h"
> @@ -351,3 +356,142 @@ int rcar_du_group_set_routing(struct rcar_du_group 
> *rgrp)
>  
>   return rcar_du_set_dpad0_vsp1_routing(rgrp->dev);
>  }
> +
> +/* 
> -
> + * Group State Handling
> + */
> +
> +static struct drm_private_state *
> +rcar_du_group_atomic_duplicate_state(struct drm_private_obj *obj)
> +{
> + struct rcar_du_group_state *state;
> +
> + if (WARN_ON(!obj->state))
> + return NULL;
> +
> + state = kzalloc(sizeof(*state), GFP_KERNEL);
> + if (state == NULL)
> + return NULL;
> +
> + __drm_atomic_helper_private_obj_duplicate_state(obj, >state);
> +
> + return >state;
> +}
> +
> +static void rcar_du_group_atomic_destroy_state(struct drm_private_obj *obj,
> +struct drm_private_state *state)
> +{
> + kfree(to_rcar_group_state(state));
> +}
> +
> +static const struct drm_private_state_funcs rcar_du_group_state_funcs = {
> + .atomic_duplicate_state = rcar_du_group_atomic_duplicate_state,
> + .atomic_destroy_state = rcar_du_group_atomic_destroy_state,
> +};
> +
> +/**
> + * rcar_du_get_old_group_state - get old group state, if it exists
> + * @state: global atomic state object
> + * @rgrp: group to grab
> + *
> + * This function returns the old group state for the given group, or
> + * NULL if the group is not part of the global atomic state.
> + */
> +struct rcar_du_group_state *
> +rcar_du_get_old_group_state(struct drm_atomic_state *state,
> + struct rcar_du_group *rgrp)
> +{
> + struct drm_private_obj *obj = >private;
> + struct drm_private_state *pstate;
> + unsigned int i;
> +
> + for (i = 0; i < state->num_private_objs; i++) {
> + if (obj == state->private_objs[i].ptr) {
> + pstate = state->private_objs[i].old_state;
> + return to_rcar_group_state(pstate);
> + }
> + }
> +
> + return NULL;
> +}
> +
> +/**
> + * rcar_du_get_new_group_state - get new group state, if it exists
> + * @state: global atomic state object
> + * @rgrp: group to grab
> + *
> + * This function returns the new group state for the given group, or
> + * NULL if the group is not part of the global atomic state.
> + */
> +struct rcar_du_group_state *
> +rcar_du_get_new_group_state(struct drm_atomic_state *state,
> + struct rcar_du_group *rgrp)
> +{
> + struct drm_private_obj *obj = >private;
> + struct drm_private_state *pstate;
> + unsigned int i;
> +
> + for (i = 0; i < state->num_private_objs; i++) {
> + if (obj == state->private_objs[i].ptr) {
> + pstate = state->private_objs[i].new_state;
> + return to_rcar_group_state(pstate);
> + }
> + }
> +
> + return NULL;
> +}
> +
> +/* 
> -
> + * Init and Cleanup
> + */
> +
> +/*
> + * rcar_du_group_init - Initialise and reset a group object
> + *
> + * Return 0 in case of success or a negative error code otherwise.
> + */
> +int rcar_du_group_init(struct rcar_du_device *rcdu, struct rcar_du_group 
> *rgrp,
> +unsigned int index)
> +{
> + static const unsigned int mmio_offsets[] = {
> + DU0_REG_OFFSET, DU2_REG_OFFSET
> + };
> +
> + struct rcar_du_group_state *state;
> +
> + state = kzalloc(sizeof(*state), GFP_KERNEL);
> + if (!state)
> + return -ENOMEM;
> +
> + drm_atomic_private_obj_init(rcdu->ddev, >private, >state,
> + _du_group_state_funcs);
> +
> + mutex_init(>lock);
> +
> + rgrp->dev = rcdu;
> + rgrp->mmio_offset = mmio_offsets[index];
> + rgrp->index = index;
> +   

[PATCH v3 08/10] drm: rcar-du: Create a group state object

2019-06-17 Thread Laurent Pinchart
From: Kieran Bingham 

Create a new private state object for the DU groups, and move the
initialisation of a group object to a new function rcar_du_group_init().

Signed-off-by: Kieran Bingham 
Signed-off-by: Laurent Pinchart 
---
Changes since v2:

- Call mutex_destroy() when cleaning up the group
- Include mutex.h and slab.h
- Squash "drm: rcar-du: Add rcar_du_get_{old,new}_group_state()"
---
 drivers/gpu/drm/rcar-du/rcar_du_group.c | 144 
 drivers/gpu/drm/rcar-du/rcar_du_group.h |  29 +
 drivers/gpu/drm/rcar-du/rcar_du_kms.c   |  27 +
 3 files changed, 177 insertions(+), 23 deletions(-)

diff --git a/drivers/gpu/drm/rcar-du/rcar_du_group.c 
b/drivers/gpu/drm/rcar-du/rcar_du_group.c
index 9eee47969e77..8e12bd42890e 100644
--- a/drivers/gpu/drm/rcar-du/rcar_du_group.c
+++ b/drivers/gpu/drm/rcar-du/rcar_du_group.c
@@ -25,6 +25,11 @@
 
 #include 
 #include 
+#include 
+
+#include 
+#include 
+#include 
 
 #include "rcar_du_drv.h"
 #include "rcar_du_group.h"
@@ -351,3 +356,142 @@ int rcar_du_group_set_routing(struct rcar_du_group *rgrp)
 
return rcar_du_set_dpad0_vsp1_routing(rgrp->dev);
 }
+
+/* 
-
+ * Group State Handling
+ */
+
+static struct drm_private_state *
+rcar_du_group_atomic_duplicate_state(struct drm_private_obj *obj)
+{
+   struct rcar_du_group_state *state;
+
+   if (WARN_ON(!obj->state))
+   return NULL;
+
+   state = kzalloc(sizeof(*state), GFP_KERNEL);
+   if (state == NULL)
+   return NULL;
+
+   __drm_atomic_helper_private_obj_duplicate_state(obj, >state);
+
+   return >state;
+}
+
+static void rcar_du_group_atomic_destroy_state(struct drm_private_obj *obj,
+  struct drm_private_state *state)
+{
+   kfree(to_rcar_group_state(state));
+}
+
+static const struct drm_private_state_funcs rcar_du_group_state_funcs = {
+   .atomic_duplicate_state = rcar_du_group_atomic_duplicate_state,
+   .atomic_destroy_state = rcar_du_group_atomic_destroy_state,
+};
+
+/**
+ * rcar_du_get_old_group_state - get old group state, if it exists
+ * @state: global atomic state object
+ * @rgrp: group to grab
+ *
+ * This function returns the old group state for the given group, or
+ * NULL if the group is not part of the global atomic state.
+ */
+struct rcar_du_group_state *
+rcar_du_get_old_group_state(struct drm_atomic_state *state,
+   struct rcar_du_group *rgrp)
+{
+   struct drm_private_obj *obj = >private;
+   struct drm_private_state *pstate;
+   unsigned int i;
+
+   for (i = 0; i < state->num_private_objs; i++) {
+   if (obj == state->private_objs[i].ptr) {
+   pstate = state->private_objs[i].old_state;
+   return to_rcar_group_state(pstate);
+   }
+   }
+
+   return NULL;
+}
+
+/**
+ * rcar_du_get_new_group_state - get new group state, if it exists
+ * @state: global atomic state object
+ * @rgrp: group to grab
+ *
+ * This function returns the new group state for the given group, or
+ * NULL if the group is not part of the global atomic state.
+ */
+struct rcar_du_group_state *
+rcar_du_get_new_group_state(struct drm_atomic_state *state,
+   struct rcar_du_group *rgrp)
+{
+   struct drm_private_obj *obj = >private;
+   struct drm_private_state *pstate;
+   unsigned int i;
+
+   for (i = 0; i < state->num_private_objs; i++) {
+   if (obj == state->private_objs[i].ptr) {
+   pstate = state->private_objs[i].new_state;
+   return to_rcar_group_state(pstate);
+   }
+   }
+
+   return NULL;
+}
+
+/* 
-
+ * Init and Cleanup
+ */
+
+/*
+ * rcar_du_group_init - Initialise and reset a group object
+ *
+ * Return 0 in case of success or a negative error code otherwise.
+ */
+int rcar_du_group_init(struct rcar_du_device *rcdu, struct rcar_du_group *rgrp,
+  unsigned int index)
+{
+   static const unsigned int mmio_offsets[] = {
+   DU0_REG_OFFSET, DU2_REG_OFFSET
+   };
+
+   struct rcar_du_group_state *state;
+
+   state = kzalloc(sizeof(*state), GFP_KERNEL);
+   if (!state)
+   return -ENOMEM;
+
+   drm_atomic_private_obj_init(rcdu->ddev, >private, >state,
+   _du_group_state_funcs);
+
+   mutex_init(>lock);
+
+   rgrp->dev = rcdu;
+   rgrp->mmio_offset = mmio_offsets[index];
+   rgrp->index = index;
+   /* Extract the channel mask for this group only. */
+   rgrp->channels_mask = (rcdu->info->channels_mask >> (2 * index))
+   & GENMASK(1, 0);
+   rgrp->num_crtcs = hweight8(rgrp->channels_mask);
+
+   /*
+* If we have more than one CRTC in