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

drm/crtc: Introduce drmm_crtc_init_with_planes

The DRM-managed function to register a CRTC is
drmm_crtc_alloc_with_planes(), which will allocate the underlying
structure and initialisation the CRTC.

However, we might want to separate the structure creation and the CRTC
initialisation, for example if the structure is shared across multiple
DRM entities, for example an encoder and a connector.

Let's create an helper to only initialise a CRTC that would be passed as
an argument.

Acked-by: Thomas Zimmermann <tzimmermann@suse.de>
Signed-off-by: Maxime Ripard <maxime@cerno.tech>
Link: https://lore.kernel.org/r/20220711173939.1132294-3-maxime@cerno.tech

+91 -12
+82 -12
drivers/gpu/drm/drm_crtc.c
··· 343 343 * The @primary and @cursor planes are only relevant for legacy uAPI, see 344 344 * &drm_crtc.primary and &drm_crtc.cursor. 345 345 * 346 - * Note: consider using drmm_crtc_alloc_with_planes() instead of 347 - * drm_crtc_init_with_planes() to let the DRM managed resource infrastructure 348 - * take care of cleanup and deallocation. 346 + * Note: consider using drmm_crtc_alloc_with_planes() or 347 + * drmm_crtc_init_with_planes() instead of drm_crtc_init_with_planes() 348 + * to let the DRM managed resource infrastructure take care of cleanup 349 + * and deallocation. 349 350 * 350 351 * Returns: 351 352 * Zero on success, error code on failure. ··· 371 370 } 372 371 EXPORT_SYMBOL(drm_crtc_init_with_planes); 373 372 374 - static void drmm_crtc_alloc_with_planes_cleanup(struct drm_device *dev, 375 - void *ptr) 373 + static void drmm_crtc_init_with_planes_cleanup(struct drm_device *dev, 374 + void *ptr) 376 375 { 377 376 struct drm_crtc *crtc = ptr; 378 377 379 378 drm_crtc_cleanup(crtc); 380 379 } 380 + 381 + __printf(6, 0) 382 + static int __drmm_crtc_init_with_planes(struct drm_device *dev, 383 + struct drm_crtc *crtc, 384 + struct drm_plane *primary, 385 + struct drm_plane *cursor, 386 + const struct drm_crtc_funcs *funcs, 387 + const char *name, 388 + va_list args) 389 + { 390 + int ret; 391 + 392 + drm_WARN_ON(dev, funcs && funcs->destroy); 393 + 394 + ret = __drm_crtc_init_with_planes(dev, crtc, primary, cursor, funcs, 395 + name, args); 396 + if (ret) 397 + return ret; 398 + 399 + ret = drmm_add_action_or_reset(dev, drmm_crtc_init_with_planes_cleanup, 400 + crtc); 401 + if (ret) 402 + return ret; 403 + 404 + return 0; 405 + } 406 + 407 + /** 408 + * drmm_crtc_init_with_planes - Initialise a new CRTC object with 409 + * specified primary and cursor planes. 410 + * @dev: DRM device 411 + * @crtc: CRTC object to init 412 + * @primary: Primary plane for CRTC 413 + * @cursor: Cursor plane for CRTC 414 + * @funcs: callbacks for the new CRTC 415 + * @name: printf style format string for the CRTC name, or NULL for default name 416 + * 417 + * Inits a new object created as base part of a driver crtc object. Drivers 418 + * should use this function instead of drm_crtc_init(), which is only provided 419 + * for backwards compatibility with drivers which do not yet support universal 420 + * planes). For really simple hardware which has only 1 plane look at 421 + * drm_simple_display_pipe_init() instead. 422 + * 423 + * Cleanup is automatically handled through registering 424 + * drmm_crtc_cleanup() with drmm_add_action(). The crtc structure should 425 + * be allocated with drmm_kzalloc(). 426 + * 427 + * The @drm_crtc_funcs.destroy hook must be NULL. 428 + * 429 + * The @primary and @cursor planes are only relevant for legacy uAPI, see 430 + * &drm_crtc.primary and &drm_crtc.cursor. 431 + * 432 + * Returns: 433 + * Zero on success, error code on failure. 434 + */ 435 + int drmm_crtc_init_with_planes(struct drm_device *dev, struct drm_crtc *crtc, 436 + struct drm_plane *primary, 437 + struct drm_plane *cursor, 438 + const struct drm_crtc_funcs *funcs, 439 + const char *name, ...) 440 + { 441 + va_list ap; 442 + int ret; 443 + 444 + va_start(ap, name); 445 + ret = __drmm_crtc_init_with_planes(dev, crtc, primary, cursor, funcs, 446 + name, ap); 447 + va_end(ap); 448 + if (ret) 449 + return ret; 450 + 451 + return 0; 452 + } 453 + EXPORT_SYMBOL(drmm_crtc_init_with_planes); 381 454 382 455 void *__drmm_crtc_alloc_with_planes(struct drm_device *dev, 383 456 size_t size, size_t offset, ··· 475 400 crtc = container + offset; 476 401 477 402 va_start(ap, name); 478 - ret = __drm_crtc_init_with_planes(dev, crtc, primary, cursor, funcs, 479 - name, ap); 403 + ret = __drmm_crtc_init_with_planes(dev, crtc, primary, cursor, funcs, 404 + name, ap); 480 405 va_end(ap); 481 - if (ret) 482 - return ERR_PTR(ret); 483 - 484 - ret = drmm_add_action_or_reset(dev, drmm_crtc_alloc_with_planes_cleanup, 485 - crtc); 486 406 if (ret) 487 407 return ERR_PTR(ret); 488 408
+9
include/drm/drm_crtc.h
··· 1216 1216 struct drm_plane *cursor, 1217 1217 const struct drm_crtc_funcs *funcs, 1218 1218 const char *name, ...); 1219 + 1220 + __printf(6, 7) 1221 + int drmm_crtc_init_with_planes(struct drm_device *dev, 1222 + struct drm_crtc *crtc, 1223 + struct drm_plane *primary, 1224 + struct drm_plane *cursor, 1225 + const struct drm_crtc_funcs *funcs, 1226 + const char *name, ...); 1227 + 1219 1228 void drm_crtc_cleanup(struct drm_crtc *crtc); 1220 1229 1221 1230 __printf(7, 8)