Skip to content

Commit 135d8fc

Browse files
committed
drm: writeback: Create an helper for drm_writeback_connector initialization
As the old drm and the new drmm variants of drm_writeback_connector requires almost the same initialization, create an internal helper to do most of the initialization work. Currently there is no cleanup function for writeback connectors. To allows implementation of drmm variant of writeback connector, create a cleanup function that can be used to properly remove all the writeback-specific properties and allocations. This also introduce an helper to cleanup only the drm_writeback_connector properties, so it can be used during initialization to cleanup in case of failure. Reviewed-by: Maxime Ripard <[email protected]> Acked-by: Thomas Zimmermann <[email protected]> Link: https://patchwork.freedesktop.org/patch/msgid/[email protected] Signed-off-by: Louis Chauvet <[email protected]>
1 parent 8dd92e6 commit 135d8fc

File tree

1 file changed

+61
-26
lines changed

1 file changed

+61
-26
lines changed

drivers/gpu/drm/drm_writeback.c

Lines changed: 61 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include <drm/drm_device.h>
1616
#include <drm/drm_drv.h>
1717
#include <drm/drm_framebuffer.h>
18+
#include <drm/drm_managed.h>
1819
#include <drm/drm_modeset_helper_vtables.h>
1920
#include <drm/drm_property.h>
2021
#include <drm/drm_writeback.h>
@@ -202,7 +203,6 @@ EXPORT_SYMBOL(drm_writeback_connector_init);
202203
* @dev: DRM device
203204
* @wb_connector: Writeback connector to initialize
204205
* @enc: handle to the already initialized drm encoder
205-
* @con_funcs: Connector funcs vtable
206206
* @formats: Array of supported pixel formats for the writeback engine
207207
* @n_formats: Length of the formats array
208208
*
@@ -218,41 +218,31 @@ EXPORT_SYMBOL(drm_writeback_connector_init);
218218
* assigning the encoder helper functions, possible_crtcs and any other encoder
219219
* specific operation.
220220
*
221-
* Drivers should always use this function instead of drm_connector_init() to
222-
* set up writeback connectors if they want to manage themselves the lifetime of the
223-
* associated encoder.
224-
*
225221
* Returns: 0 on success, or a negative error code
226222
*/
227-
int drm_writeback_connector_init_with_encoder(struct drm_device *dev,
228-
struct drm_writeback_connector *wb_connector, struct drm_encoder *enc,
229-
const struct drm_connector_funcs *con_funcs, const u32 *formats,
230-
int n_formats)
223+
static int __drm_writeback_connector_init(struct drm_device *dev,
224+
struct drm_writeback_connector *wb_connector,
225+
struct drm_encoder *enc, const u32 *formats,
226+
int n_formats)
231227
{
232-
struct drm_property_blob *blob;
233228
struct drm_connector *connector = &wb_connector->base;
234229
struct drm_mode_config *config = &dev->mode_config;
230+
struct drm_property_blob *blob;
235231
int ret = create_writeback_properties(dev);
236232

237233
if (ret != 0)
238234
return ret;
239235

240-
blob = drm_property_create_blob(dev, n_formats * sizeof(*formats),
241-
formats);
242-
if (IS_ERR(blob))
243-
return PTR_ERR(blob);
244-
245-
246236
connector->interlace_allowed = 0;
247237

248-
ret = drm_connector_init(dev, connector, con_funcs,
249-
DRM_MODE_CONNECTOR_WRITEBACK);
250-
if (ret)
251-
goto connector_fail;
252-
253238
ret = drm_connector_attach_encoder(connector, enc);
254239
if (ret)
255-
goto attach_fail;
240+
return ret;
241+
242+
blob = drm_property_create_blob(dev, n_formats * sizeof(*formats),
243+
formats);
244+
if (IS_ERR(blob))
245+
return PTR_ERR(blob);
256246

257247
INIT_LIST_HEAD(&wb_connector->job_queue);
258248
spin_lock_init(&wb_connector->job_lock);
@@ -275,11 +265,56 @@ int drm_writeback_connector_init_with_encoder(struct drm_device *dev,
275265
wb_connector->pixel_formats_blob_ptr = blob;
276266

277267
return 0;
268+
}
269+
270+
/**
271+
* drm_writeback_connector_init_with_encoder - Initialize a writeback connector with
272+
* a custom encoder
273+
*
274+
* @dev: DRM device
275+
* @wb_connector: Writeback connector to initialize
276+
* @enc: handle to the already initialized drm encoder
277+
* @con_funcs: Connector funcs vtable
278+
* @formats: Array of supported pixel formats for the writeback engine
279+
* @n_formats: Length of the formats array
280+
*
281+
* This function creates the writeback-connector-specific properties if they
282+
* have not been already created, initializes the connector as
283+
* type DRM_MODE_CONNECTOR_WRITEBACK, and correctly initializes the property
284+
* values.
285+
*
286+
* This function assumes that the drm_writeback_connector's encoder has already been
287+
* created and initialized before invoking this function.
288+
*
289+
* In addition, this function also assumes that callers of this API will manage
290+
* assigning the encoder helper functions, possible_crtcs and any other encoder
291+
* specific operation.
292+
*
293+
* Drivers should always use this function instead of drm_connector_init() to
294+
* set up writeback connectors if they want to manage themselves the lifetime of the
295+
* associated encoder.
296+
*
297+
* Returns: 0 on success, or a negative error code
298+
*/
299+
int drm_writeback_connector_init_with_encoder(struct drm_device *dev,
300+
struct drm_writeback_connector *wb_connector,
301+
struct drm_encoder *enc,
302+
const struct drm_connector_funcs *con_funcs,
303+
const u32 *formats, int n_formats)
304+
{
305+
struct drm_connector *connector = &wb_connector->base;
306+
int ret;
307+
308+
ret = drm_connector_init(dev, connector, con_funcs,
309+
DRM_MODE_CONNECTOR_WRITEBACK);
310+
if (ret)
311+
return ret;
312+
313+
ret = __drm_writeback_connector_init(dev, wb_connector, enc, formats,
314+
n_formats);
315+
if (ret)
316+
drm_connector_cleanup(connector);
278317

279-
attach_fail:
280-
drm_connector_cleanup(connector);
281-
connector_fail:
282-
drm_property_blob_put(blob);
283318
return ret;
284319
}
285320
EXPORT_SYMBOL(drm_writeback_connector_init_with_encoder);

0 commit comments

Comments
 (0)