Re: [PATCH v7 2/4] drm: introduce drm_writeback_connector_init_with_encoder() API

2022-04-08 Thread Dmitry Baryshkov
On Sat, 9 Apr 2022 at 03:54, Abhinav Kumar  wrote:
>
> For vendors drivers which pass an already allocated and
> initialized encoder especially for cases where the encoder
> hardware is shared OR the writeback encoder shares the resources
> with the rest of the display pipeline introduce a new API,
> drm_writeback_connector_init_with_encoder() which expects
> an initialized encoder as a parameter and only sets up the
> writeback connector.
>
> changes in v4:
> - removed the possible_crtcs part
>
> changes in v5:
> - reorder this change to come before in the series
>   to avoid incorrect functionality in subsequent changes
> - continue using struct drm_encoder instead of
>   struct drm_encoder * and switch it in next change
>
> changes in v6:
> - remove drm_writeback_connector_setup() and instead
>   directly call drm_writeback_connector_init_with_encoder()
> - fix a drm_writeback_connector typo and function doc which
>   incorrectly shows that the function accepts enc_helper_funcs
> - pass encoder as a parameter explicitly to the new API
>   for better readability
>
> changes in v7:
> - fix the function doc slightly as suggested by Liviu
>
> Reviewed-by: Liviu Dudau 
> Signed-off-by: Abhinav Kumar 

Reviewed-by: Dmitry Baryshkov 


> ---
>  drivers/gpu/drm/drm_writeback.c | 72 
> +
>  include/drm/drm_writeback.h |  6 
>  2 files changed, 64 insertions(+), 14 deletions(-)
>
> diff --git a/drivers/gpu/drm/drm_writeback.c b/drivers/gpu/drm/drm_writeback.c
> index 9e0b845..92658ad 100644
> --- a/drivers/gpu/drm/drm_writeback.c
> +++ b/drivers/gpu/drm/drm_writeback.c
> @@ -178,6 +178,62 @@ int drm_writeback_connector_init(struct drm_device *dev,
>  const u32 *formats, int n_formats,
>  u32 possible_crtcs)
>  {
> +   int ret = 0;
> +
> +   drm_encoder_helper_add(_connector->encoder, enc_helper_funcs);
> +
> +   wb_connector->encoder.possible_crtcs = possible_crtcs;
> +
> +   ret = drm_encoder_init(dev, _connector->encoder,
> +  _writeback_encoder_funcs,
> +  DRM_MODE_ENCODER_VIRTUAL, NULL);
> +   if (ret)
> +   return ret;
> +
> +   ret = drm_writeback_connector_init_with_encoder(dev, wb_connector, 
> _connector->encoder,
> +   con_funcs, formats, n_formats);
> +
> +   if (ret)
> +   drm_encoder_cleanup(_connector->encoder);
> +
> +   return ret;
> +}
> +EXPORT_SYMBOL(drm_writeback_connector_init);
> +
> +/**
> + * drm_writeback_connector_init_with_encoder - Initialize a writeback 
> connector and its properties
> + * using the encoder which already assigned and initialized
> + *
> + * @dev: DRM device
> + * @wb_connector: Writeback connector to initialize
> + * @enc: handle to the already initialized drm encoder
> + * @con_funcs: Connector funcs vtable
> + * @formats: Array of supported pixel formats for the writeback engine
> + * @n_formats: Length of the formats array
> + *
> + * This function creates the writeback-connector-specific properties if they
> + * have not been already created, initializes the connector as
> + * type DRM_MODE_CONNECTOR_WRITEBACK, and correctly initializes the property
> + * values.
> + *
> + * This function assumes that the drm_writeback_connector's encoder has 
> already been
> + * created and initialized before invoking this function.
> + *
> + * In addition, this function also assumes that callers of this API will 
> manage
> + * assigning the encoder helper functions, possible_crtcs and any other 
> encoder
> + * specific operation.
> + *
> + * Drivers should always use this function instead of drm_connector_init() to
> + * set up writeback connectors if they want to manage themselves the 
> lifetime of the
> + * associated encoder.
> + *
> + * Returns: 0 on success, or a negative error code
> + */
> +int drm_writeback_connector_init_with_encoder(struct drm_device *dev,
> +   struct drm_writeback_connector *wb_connector, struct 
> drm_encoder *enc,
> +   const struct drm_connector_funcs *con_funcs, const u32 
> *formats,
> +   int n_formats)
> +{
> struct drm_property_blob *blob;
> struct drm_connector *connector = _connector->base;
> struct drm_mode_config *config = >mode_config;
> @@ -191,15 +247,6 @@ int drm_writeback_connector_init(struct drm_device *dev,
> if (IS_ERR(blob))
> return PTR_ERR(blob);
>
> -   drm_encoder_helper_add(_connector->encoder, enc_helper_funcs);
> -
> -   wb_connector->encoder.possible_crtcs = possible_crtcs;
> -
> -   ret = drm_encoder_init(dev, _connector->encoder,
> -  _writeback_encoder_funcs,
> -  DRM_MODE_ENCODER_VIRTUAL, NULL);
> -   if (ret)
> -

[PATCH v7 2/4] drm: introduce drm_writeback_connector_init_with_encoder() API

2022-04-08 Thread Abhinav Kumar
For vendors drivers which pass an already allocated and
initialized encoder especially for cases where the encoder
hardware is shared OR the writeback encoder shares the resources
with the rest of the display pipeline introduce a new API,
drm_writeback_connector_init_with_encoder() which expects
an initialized encoder as a parameter and only sets up the
writeback connector.

changes in v4:
- removed the possible_crtcs part

changes in v5:
- reorder this change to come before in the series
  to avoid incorrect functionality in subsequent changes
- continue using struct drm_encoder instead of
  struct drm_encoder * and switch it in next change

changes in v6:
- remove drm_writeback_connector_setup() and instead
  directly call drm_writeback_connector_init_with_encoder()
- fix a drm_writeback_connector typo and function doc which
  incorrectly shows that the function accepts enc_helper_funcs
- pass encoder as a parameter explicitly to the new API
  for better readability

changes in v7:
- fix the function doc slightly as suggested by Liviu

Reviewed-by: Liviu Dudau 
Signed-off-by: Abhinav Kumar 
---
 drivers/gpu/drm/drm_writeback.c | 72 +
 include/drm/drm_writeback.h |  6 
 2 files changed, 64 insertions(+), 14 deletions(-)

diff --git a/drivers/gpu/drm/drm_writeback.c b/drivers/gpu/drm/drm_writeback.c
index 9e0b845..92658ad 100644
--- a/drivers/gpu/drm/drm_writeback.c
+++ b/drivers/gpu/drm/drm_writeback.c
@@ -178,6 +178,62 @@ int drm_writeback_connector_init(struct drm_device *dev,
 const u32 *formats, int n_formats,
 u32 possible_crtcs)
 {
+   int ret = 0;
+
+   drm_encoder_helper_add(_connector->encoder, enc_helper_funcs);
+
+   wb_connector->encoder.possible_crtcs = possible_crtcs;
+
+   ret = drm_encoder_init(dev, _connector->encoder,
+  _writeback_encoder_funcs,
+  DRM_MODE_ENCODER_VIRTUAL, NULL);
+   if (ret)
+   return ret;
+
+   ret = drm_writeback_connector_init_with_encoder(dev, wb_connector, 
_connector->encoder,
+   con_funcs, formats, n_formats);
+
+   if (ret)
+   drm_encoder_cleanup(_connector->encoder);
+
+   return ret;
+}
+EXPORT_SYMBOL(drm_writeback_connector_init);
+
+/**
+ * drm_writeback_connector_init_with_encoder - Initialize a writeback 
connector and its properties
+ * using the encoder which already assigned and initialized
+ *
+ * @dev: DRM device
+ * @wb_connector: Writeback connector to initialize
+ * @enc: handle to the already initialized drm encoder
+ * @con_funcs: Connector funcs vtable
+ * @formats: Array of supported pixel formats for the writeback engine
+ * @n_formats: Length of the formats array
+ *
+ * This function creates the writeback-connector-specific properties if they
+ * have not been already created, initializes the connector as
+ * type DRM_MODE_CONNECTOR_WRITEBACK, and correctly initializes the property
+ * values.
+ *
+ * This function assumes that the drm_writeback_connector's encoder has 
already been
+ * created and initialized before invoking this function.
+ *
+ * In addition, this function also assumes that callers of this API will manage
+ * assigning the encoder helper functions, possible_crtcs and any other encoder
+ * specific operation.
+ *
+ * Drivers should always use this function instead of drm_connector_init() to
+ * set up writeback connectors if they want to manage themselves the lifetime 
of the
+ * associated encoder.
+ *
+ * Returns: 0 on success, or a negative error code
+ */
+int drm_writeback_connector_init_with_encoder(struct drm_device *dev,
+   struct drm_writeback_connector *wb_connector, struct 
drm_encoder *enc,
+   const struct drm_connector_funcs *con_funcs, const u32 *formats,
+   int n_formats)
+{
struct drm_property_blob *blob;
struct drm_connector *connector = _connector->base;
struct drm_mode_config *config = >mode_config;
@@ -191,15 +247,6 @@ int drm_writeback_connector_init(struct drm_device *dev,
if (IS_ERR(blob))
return PTR_ERR(blob);
 
-   drm_encoder_helper_add(_connector->encoder, enc_helper_funcs);
-
-   wb_connector->encoder.possible_crtcs = possible_crtcs;
-
-   ret = drm_encoder_init(dev, _connector->encoder,
-  _writeback_encoder_funcs,
-  DRM_MODE_ENCODER_VIRTUAL, NULL);
-   if (ret)
-   goto fail;
 
connector->interlace_allowed = 0;
 
@@ -208,8 +255,7 @@ int drm_writeback_connector_init(struct drm_device *dev,
if (ret)
goto connector_fail;
 
-   ret = drm_connector_attach_encoder(connector,
-   _connector->encoder);
+   ret =