Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

drm: writeback: Create drmm variants for drm_writeback_connector initialization

To allows driver to only use drmm objects, add helper to create
drm_writeback_connectors with automated lifetime management.

Acked-by: Thomas Zimmermann <tzimmermann@suse.de>
Acked-by: Maxime Ripard <mripard@kernel.org>
Link: https://patchwork.freedesktop.org/patch/msgid/20250116-google-vkms-managed-v9-7-3e4ae1bd05a0@bootlin.com
Signed-off-by: Louis Chauvet <louis.chauvet@bootlin.com>

+80
+74
drivers/gpu/drm/drm_writeback.c
··· 340 340 } 341 341 EXPORT_SYMBOL(drm_writeback_connector_init_with_encoder); 342 342 343 + /** 344 + * drm_writeback_connector_cleanup - Cleanup the writeback connector 345 + * @dev: DRM device 346 + * @wb_connector: Pointer to the writeback connector to clean up 347 + * 348 + * This will decrement the reference counter of blobs and destroy properties. It 349 + * will also clean the remaining jobs in this writeback connector. Caution: This helper will not 350 + * clean up the attached encoder and the drm_connector. 351 + */ 352 + static void drm_writeback_connector_cleanup(struct drm_device *dev, 353 + struct drm_writeback_connector *wb_connector) 354 + { 355 + unsigned long flags; 356 + struct drm_writeback_job *pos, *n; 357 + 358 + delete_writeback_properties(dev); 359 + drm_property_blob_put(wb_connector->pixel_formats_blob_ptr); 360 + 361 + spin_lock_irqsave(&wb_connector->job_lock, flags); 362 + list_for_each_entry_safe(pos, n, &wb_connector->job_queue, list_entry) { 363 + drm_writeback_cleanup_job(pos); 364 + list_del(&pos->list_entry); 365 + } 366 + spin_unlock_irqrestore(&wb_connector->job_lock, flags); 367 + } 368 + 369 + /** 370 + * drmm_writeback_connector_init - Initialize a writeback connector with 371 + * a custom encoder 372 + * 373 + * @dev: DRM device 374 + * @wb_connector: Writeback connector to initialize 375 + * @con_funcs: Connector funcs vtable 376 + * @enc: Encoder to connect this writeback connector 377 + * @formats: Array of supported pixel formats for the writeback engine 378 + * @n_formats: Length of the formats array 379 + * 380 + * This function initialize a writeback connector and register its cleanup. 381 + * 382 + * This function creates the writeback-connector-specific properties if they 383 + * have not been already created, initializes the connector as 384 + * type DRM_MODE_CONNECTOR_WRITEBACK, and correctly initializes the property 385 + * values. 386 + * 387 + * Returns: 0 on success, or a negative error code 388 + */ 389 + int drmm_writeback_connector_init(struct drm_device *dev, 390 + struct drm_writeback_connector *wb_connector, 391 + const struct drm_connector_funcs *con_funcs, 392 + struct drm_encoder *enc, 393 + const u32 *formats, int n_formats) 394 + { 395 + struct drm_connector *connector = &wb_connector->base; 396 + int ret; 397 + 398 + ret = drmm_connector_init(dev, connector, con_funcs, 399 + DRM_MODE_CONNECTOR_WRITEBACK, NULL); 400 + if (ret) 401 + return ret; 402 + 403 + ret = __drm_writeback_connector_init(dev, wb_connector, enc, formats, 404 + n_formats); 405 + if (ret) 406 + return ret; 407 + 408 + ret = drmm_add_action_or_reset(dev, (void *)drm_writeback_connector_cleanup, 409 + wb_connector); 410 + if (ret) 411 + return ret; 412 + 413 + return 0; 414 + } 415 + EXPORT_SYMBOL(drmm_writeback_connector_init); 416 + 343 417 int drm_writeback_set_fb(struct drm_connector_state *conn_state, 344 418 struct drm_framebuffer *fb) 345 419 {
+6
include/drm/drm_writeback.h
··· 161 161 const struct drm_connector_funcs *con_funcs, const u32 *formats, 162 162 int n_formats); 163 163 164 + int drmm_writeback_connector_init(struct drm_device *dev, 165 + struct drm_writeback_connector *wb_connector, 166 + const struct drm_connector_funcs *con_funcs, 167 + struct drm_encoder *enc, 168 + const u32 *formats, int n_formats); 169 + 164 170 int drm_writeback_set_fb(struct drm_connector_state *conn_state, 165 171 struct drm_framebuffer *fb); 166 172