aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/gpu
diff options
context:
space:
mode:
authorDaniel Vetter <daniel.vetter@ffwll.ch>2012-12-01 17:43:11 -0500
committerDaniel Vetter <daniel.vetter@ffwll.ch>2013-01-20 09:29:04 -0500
commit8faf6b18a2a6bece008de1e6bb80f0c608e58483 (patch)
treee30089b80dc9706a4842c9d53094a4f9ecadb2e4 /drivers/gpu
parent7d1f9aeff1ee4a20b1aeb377dd0f579fe9647619 (diff)
drm: review locking rules in drm_crtc.c
- config_cleanup was confused: It claimed that callers need to hold the modeset lock, but the connector|encoder_cleanup helpers grabbed that themselves (note that crtc_cleanup did _not_ grab the modeset lock). Which resulted in all drivers _not_ hodling the lock. Since this is for single-threaded cleanup code, drop the requirement from docs and also drop the lock_grabbing from all _cleanup functions. - Kill the LOCKING section in the doctype, since clearly we're not good enough to keep them up-to-date. And misleading locking documentation is worse than useless (see e.g. the comment in the vmgfx driver about the cleanup mess). And since for most functions the very first line either grabs the lock or has a WARN_ON(!locked) the documentation doesn't really add anything. - Instead put in some effort into explaining the only two special cases a bit better: config_init and config_cleanup are both called from single-threaded setup/teardown code, so don't do any locking. It's the driver's job though to enforce this. - Where lacking, add a WARN_ON(!is_locked). Not many places though, since locking around fbdev setup/teardown is through-roughly screwed up, and so will break almost every single WARN annotation I've tried to add. - Add a drm_modeset_is_locked helper - the Grate Modset Locking Rework will use the compiler to assist in the big reorg by renaming the mode lock, so start encapsulating things. Unfortunately this ended up in the "wrong" header file since it needs the definition of struct drm_device. v2: Drop most WARNS again - we hit them all over the place, mostly in the setup and teardown sequences. And trying to fix it up leads to nice deadlocks, since the locking in the setup code is really inconsistent. Reviewed-by: Rob Clark <rob@ti.com> Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Diffstat (limited to 'drivers/gpu')
-rw-r--r--drivers/gpu/drm/drm_crtc.c105
1 files changed, 13 insertions, 92 deletions
diff --git a/drivers/gpu/drm/drm_crtc.c b/drivers/gpu/drm/drm_crtc.c
index f2d667b8bee2..b970e4147862 100644
--- a/drivers/gpu/drm/drm_crtc.c
+++ b/drivers/gpu/drm/drm_crtc.c
@@ -208,8 +208,6 @@ char *drm_get_connector_status_name(enum drm_connector_status status)
208 * @ptr: object pointer, used to generate unique ID 208 * @ptr: object pointer, used to generate unique ID
209 * @type: object type 209 * @type: object type
210 * 210 *
211 * LOCKING:
212 *
213 * Create a unique identifier based on @ptr in @dev's identifier space. Used 211 * Create a unique identifier based on @ptr in @dev's identifier space. Used
214 * for tracking modes, CRTCs and connectors. 212 * for tracking modes, CRTCs and connectors.
215 * 213 *
@@ -247,9 +245,6 @@ again:
247 * @dev: DRM device 245 * @dev: DRM device
248 * @id: ID to free 246 * @id: ID to free
249 * 247 *
250 * LOCKING:
251 * Caller must hold DRM mode_config lock.
252 *
253 * Free @id from @dev's unique identifier pool. 248 * Free @id from @dev's unique identifier pool.
254 */ 249 */
255static void drm_mode_object_put(struct drm_device *dev, 250static void drm_mode_object_put(struct drm_device *dev,
@@ -279,9 +274,6 @@ EXPORT_SYMBOL(drm_mode_object_find);
279 * drm_framebuffer_init - initialize a framebuffer 274 * drm_framebuffer_init - initialize a framebuffer
280 * @dev: DRM device 275 * @dev: DRM device
281 * 276 *
282 * LOCKING:
283 * Caller must hold mode config lock.
284 *
285 * Allocates an ID for the framebuffer's parent mode object, sets its mode 277 * Allocates an ID for the framebuffer's parent mode object, sets its mode
286 * functions & device file and adds it to the master fd list. 278 * functions & device file and adds it to the master fd list.
287 * 279 *
@@ -317,15 +309,12 @@ static void drm_framebuffer_free(struct kref *kref)
317 309
318/** 310/**
319 * drm_framebuffer_unreference - unref a framebuffer 311 * drm_framebuffer_unreference - unref a framebuffer
320 *
321 * LOCKING:
322 * Caller must hold mode config lock.
323 */ 312 */
324void drm_framebuffer_unreference(struct drm_framebuffer *fb) 313void drm_framebuffer_unreference(struct drm_framebuffer *fb)
325{ 314{
326 struct drm_device *dev = fb->dev; 315 struct drm_device *dev = fb->dev;
327 DRM_DEBUG("FB ID: %d\n", fb->base.id); 316 DRM_DEBUG("FB ID: %d\n", fb->base.id);
328 WARN_ON(!mutex_is_locked(&dev->mode_config.mutex)); 317 WARN_ON(!drm_modeset_is_locked(dev));
329 kref_put(&fb->refcount, drm_framebuffer_free); 318 kref_put(&fb->refcount, drm_framebuffer_free);
330} 319}
331EXPORT_SYMBOL(drm_framebuffer_unreference); 320EXPORT_SYMBOL(drm_framebuffer_unreference);
@@ -344,15 +333,13 @@ EXPORT_SYMBOL(drm_framebuffer_reference);
344 * drm_framebuffer_cleanup - remove a framebuffer object 333 * drm_framebuffer_cleanup - remove a framebuffer object
345 * @fb: framebuffer to remove 334 * @fb: framebuffer to remove
346 * 335 *
347 * LOCKING:
348 * Caller must hold mode config lock.
349 *
350 * Scans all the CRTCs in @dev's mode_config. If they're using @fb, removes 336 * Scans all the CRTCs in @dev's mode_config. If they're using @fb, removes
351 * it, setting it to NULL. 337 * it, setting it to NULL.
352 */ 338 */
353void drm_framebuffer_cleanup(struct drm_framebuffer *fb) 339void drm_framebuffer_cleanup(struct drm_framebuffer *fb)
354{ 340{
355 struct drm_device *dev = fb->dev; 341 struct drm_device *dev = fb->dev;
342
356 /* 343 /*
357 * This could be moved to drm_framebuffer_remove(), but for 344 * This could be moved to drm_framebuffer_remove(), but for
358 * debugging is nice to keep around the list of fb's that are 345 * debugging is nice to keep around the list of fb's that are
@@ -370,9 +357,6 @@ EXPORT_SYMBOL(drm_framebuffer_cleanup);
370 * drm_framebuffer_remove - remove and unreference a framebuffer object 357 * drm_framebuffer_remove - remove and unreference a framebuffer object
371 * @fb: framebuffer to remove 358 * @fb: framebuffer to remove
372 * 359 *
373 * LOCKING:
374 * Caller must hold mode config lock.
375 *
376 * Scans all the CRTCs and planes in @dev's mode_config. If they're 360 * Scans all the CRTCs and planes in @dev's mode_config. If they're
377 * using @fb, removes it, setting it to NULL. 361 * using @fb, removes it, setting it to NULL.
378 */ 362 */
@@ -384,6 +368,8 @@ void drm_framebuffer_remove(struct drm_framebuffer *fb)
384 struct drm_mode_set set; 368 struct drm_mode_set set;
385 int ret; 369 int ret;
386 370
371 WARN_ON(!drm_modeset_is_locked(dev));
372
387 /* remove from any CRTC */ 373 /* remove from any CRTC */
388 list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) { 374 list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
389 if (crtc->fb == fb) { 375 if (crtc->fb == fb) {
@@ -421,9 +407,6 @@ EXPORT_SYMBOL(drm_framebuffer_remove);
421 * @crtc: CRTC object to init 407 * @crtc: CRTC object to init
422 * @funcs: callbacks for the new CRTC 408 * @funcs: callbacks for the new CRTC
423 * 409 *
424 * LOCKING:
425 * Takes mode_config lock.
426 *
427 * Inits a new object created as base part of an driver crtc object. 410 * Inits a new object created as base part of an driver crtc object.
428 * 411 *
429 * RETURNS: 412 * RETURNS:
@@ -460,9 +443,6 @@ EXPORT_SYMBOL(drm_crtc_init);
460 * drm_crtc_cleanup - Cleans up the core crtc usage. 443 * drm_crtc_cleanup - Cleans up the core crtc usage.
461 * @crtc: CRTC to cleanup 444 * @crtc: CRTC to cleanup
462 * 445 *
463 * LOCKING:
464 * Caller must hold mode config lock.
465 *
466 * Cleanup @crtc. Removes from drm modesetting space 446 * Cleanup @crtc. Removes from drm modesetting space
467 * does NOT free object, caller does that. 447 * does NOT free object, caller does that.
468 */ 448 */
@@ -484,9 +464,6 @@ EXPORT_SYMBOL(drm_crtc_cleanup);
484 * @connector: connector the new mode 464 * @connector: connector the new mode
485 * @mode: mode data 465 * @mode: mode data
486 * 466 *
487 * LOCKING:
488 * Caller must hold mode config lock.
489 *
490 * Add @mode to @connector's mode list for later use. 467 * Add @mode to @connector's mode list for later use.
491 */ 468 */
492void drm_mode_probed_add(struct drm_connector *connector, 469void drm_mode_probed_add(struct drm_connector *connector,
@@ -501,9 +478,6 @@ EXPORT_SYMBOL(drm_mode_probed_add);
501 * @connector: connector list to modify 478 * @connector: connector list to modify
502 * @mode: mode to remove 479 * @mode: mode to remove
503 * 480 *
504 * LOCKING:
505 * Caller must hold mode config lock.
506 *
507 * Remove @mode from @connector's mode list, then free it. 481 * Remove @mode from @connector's mode list, then free it.
508 */ 482 */
509void drm_mode_remove(struct drm_connector *connector, 483void drm_mode_remove(struct drm_connector *connector,
@@ -521,9 +495,6 @@ EXPORT_SYMBOL(drm_mode_remove);
521 * @funcs: callbacks for this connector 495 * @funcs: callbacks for this connector
522 * @name: user visible name of the connector 496 * @name: user visible name of the connector
523 * 497 *
524 * LOCKING:
525 * Takes mode config lock.
526 *
527 * Initialises a preallocated connector. Connectors should be 498 * Initialises a preallocated connector. Connectors should be
528 * subclassed as part of driver connector objects. 499 * subclassed as part of driver connector objects.
529 * 500 *
@@ -577,9 +548,6 @@ EXPORT_SYMBOL(drm_connector_init);
577 * drm_connector_cleanup - cleans up an initialised connector 548 * drm_connector_cleanup - cleans up an initialised connector
578 * @connector: connector to cleanup 549 * @connector: connector to cleanup
579 * 550 *
580 * LOCKING:
581 * Takes mode config lock.
582 *
583 * Cleans up the connector but doesn't free the object. 551 * Cleans up the connector but doesn't free the object.
584 */ 552 */
585void drm_connector_cleanup(struct drm_connector *connector) 553void drm_connector_cleanup(struct drm_connector *connector)
@@ -596,11 +564,9 @@ void drm_connector_cleanup(struct drm_connector *connector)
596 list_for_each_entry_safe(mode, t, &connector->user_modes, head) 564 list_for_each_entry_safe(mode, t, &connector->user_modes, head)
597 drm_mode_remove(connector, mode); 565 drm_mode_remove(connector, mode);
598 566
599 mutex_lock(&dev->mode_config.mutex);
600 drm_mode_object_put(dev, &connector->base); 567 drm_mode_object_put(dev, &connector->base);
601 list_del(&connector->head); 568 list_del(&connector->head);
602 dev->mode_config.num_connector--; 569 dev->mode_config.num_connector--;
603 mutex_unlock(&dev->mode_config.mutex);
604} 570}
605EXPORT_SYMBOL(drm_connector_cleanup); 571EXPORT_SYMBOL(drm_connector_cleanup);
606 572
@@ -721,9 +687,6 @@ EXPORT_SYMBOL(drm_plane_cleanup);
721 * drm_mode_create - create a new display mode 687 * drm_mode_create - create a new display mode
722 * @dev: DRM device 688 * @dev: DRM device
723 * 689 *
724 * LOCKING:
725 * Caller must hold DRM mode_config lock.
726 *
727 * Create a new drm_display_mode, give it an ID, and return it. 690 * Create a new drm_display_mode, give it an ID, and return it.
728 * 691 *
729 * RETURNS: 692 * RETURNS:
@@ -751,9 +714,6 @@ EXPORT_SYMBOL(drm_mode_create);
751 * @dev: DRM device 714 * @dev: DRM device
752 * @mode: mode to remove 715 * @mode: mode to remove
753 * 716 *
754 * LOCKING:
755 * Caller must hold mode config lock.
756 *
757 * Free @mode's unique identifier, then free it. 717 * Free @mode's unique identifier, then free it.
758 */ 718 */
759void drm_mode_destroy(struct drm_device *dev, struct drm_display_mode *mode) 719void drm_mode_destroy(struct drm_device *dev, struct drm_display_mode *mode)
@@ -978,11 +938,13 @@ EXPORT_SYMBOL(drm_mode_create_dirty_info_property);
978 * drm_mode_config_init - initialize DRM mode_configuration structure 938 * drm_mode_config_init - initialize DRM mode_configuration structure
979 * @dev: DRM device 939 * @dev: DRM device
980 * 940 *
981 * LOCKING:
982 * None, should happen single threaded at init time.
983 *
984 * Initialize @dev's mode_config structure, used for tracking the graphics 941 * Initialize @dev's mode_config structure, used for tracking the graphics
985 * configuration of @dev. 942 * configuration of @dev.
943 *
944 * Since this initializes the modeset locks, no locking is possible. Which is no
945 * problem, since this should happen single threaded at init time. It is the
946 * driver's problem to ensure this guarantee.
947 *
986 */ 948 */
987void drm_mode_config_init(struct drm_device *dev) 949void drm_mode_config_init(struct drm_device *dev)
988{ 950{
@@ -1057,12 +1019,13 @@ EXPORT_SYMBOL(drm_mode_group_init_legacy_group);
1057 * drm_mode_config_cleanup - free up DRM mode_config info 1019 * drm_mode_config_cleanup - free up DRM mode_config info
1058 * @dev: DRM device 1020 * @dev: DRM device
1059 * 1021 *
1060 * LOCKING:
1061 * Caller must hold mode config lock.
1062 *
1063 * Free up all the connectors and CRTCs associated with this DRM device, then 1022 * Free up all the connectors and CRTCs associated with this DRM device, then
1064 * free up the framebuffers and associated buffer objects. 1023 * free up the framebuffers and associated buffer objects.
1065 * 1024 *
1025 * Note that since this /should/ happen single-threaded at driver/device
1026 * teardown time, no locking is required. It's the driver's job to ensure that
1027 * this guarantee actually holds true.
1028 *
1066 * FIXME: cleanup any dangling user buffer objects too 1029 * FIXME: cleanup any dangling user buffer objects too
1067 */ 1030 */
1068void drm_mode_config_cleanup(struct drm_device *dev) 1031void drm_mode_config_cleanup(struct drm_device *dev)
@@ -1112,9 +1075,6 @@ EXPORT_SYMBOL(drm_mode_config_cleanup);
1112 * @out: drm_mode_modeinfo struct to return to the user 1075 * @out: drm_mode_modeinfo struct to return to the user
1113 * @in: drm_display_mode to use 1076 * @in: drm_display_mode to use
1114 * 1077 *
1115 * LOCKING:
1116 * None.
1117 *
1118 * Convert a drm_display_mode into a drm_mode_modeinfo structure to return to 1078 * Convert a drm_display_mode into a drm_mode_modeinfo structure to return to
1119 * the user. 1079 * the user.
1120 */ 1080 */
@@ -1151,9 +1111,6 @@ static void drm_crtc_convert_to_umode(struct drm_mode_modeinfo *out,
1151 * @out: drm_display_mode to return to the user 1111 * @out: drm_display_mode to return to the user
1152 * @in: drm_mode_modeinfo to use 1112 * @in: drm_mode_modeinfo to use
1153 * 1113 *
1154 * LOCKING:
1155 * None.
1156 *
1157 * Convert a drm_mode_modeinfo into a drm_display_mode structure to return to 1114 * Convert a drm_mode_modeinfo into a drm_display_mode structure to return to
1158 * the caller. 1115 * the caller.
1159 * 1116 *
@@ -1193,9 +1150,6 @@ static int drm_crtc_convert_umode(struct drm_display_mode *out,
1193 * @cmd: cmd from ioctl 1150 * @cmd: cmd from ioctl
1194 * @arg: arg from ioctl 1151 * @arg: arg from ioctl
1195 * 1152 *
1196 * LOCKING:
1197 * Takes mode config lock.
1198 *
1199 * Construct a set of configuration description structures and return 1153 * Construct a set of configuration description structures and return
1200 * them to the user, including CRTC, connector and framebuffer configuration. 1154 * them to the user, including CRTC, connector and framebuffer configuration.
1201 * 1155 *
@@ -1381,9 +1335,6 @@ out:
1381 * @cmd: cmd from ioctl 1335 * @cmd: cmd from ioctl
1382 * @arg: arg from ioctl 1336 * @arg: arg from ioctl
1383 * 1337 *
1384 * LOCKING:
1385 * Takes mode config lock.
1386 *
1387 * Construct a CRTC configuration structure to return to the user. 1338 * Construct a CRTC configuration structure to return to the user.
1388 * 1339 *
1389 * Called by the user via ioctl. 1340 * Called by the user via ioctl.
@@ -1441,9 +1392,6 @@ out:
1441 * @cmd: cmd from ioctl 1392 * @cmd: cmd from ioctl
1442 * @arg: arg from ioctl 1393 * @arg: arg from ioctl
1443 * 1394 *
1444 * LOCKING:
1445 * Takes mode config lock.
1446 *
1447 * Construct a connector configuration structure to return to the user. 1395 * Construct a connector configuration structure to return to the user.
1448 * 1396 *
1449 * Called by the user via ioctl. 1397 * Called by the user via ioctl.
@@ -1618,9 +1566,6 @@ out:
1618 * @data: ioctl data 1566 * @data: ioctl data
1619 * @file_priv: DRM file info 1567 * @file_priv: DRM file info
1620 * 1568 *
1621 * LOCKING:
1622 * Takes mode config lock.
1623 *
1624 * Return an plane count and set of IDs. 1569 * Return an plane count and set of IDs.
1625 */ 1570 */
1626int drm_mode_getplane_res(struct drm_device *dev, void *data, 1571int drm_mode_getplane_res(struct drm_device *dev, void *data,
@@ -1667,9 +1612,6 @@ out:
1667 * @data: ioctl data 1612 * @data: ioctl data
1668 * @file_priv: DRM file info 1613 * @file_priv: DRM file info
1669 * 1614 *
1670 * LOCKING:
1671 * Takes mode config lock.
1672 *
1673 * Return plane info, including formats supported, gamma size, any 1615 * Return plane info, including formats supported, gamma size, any
1674 * current fb, etc. 1616 * current fb, etc.
1675 */ 1617 */
@@ -1735,9 +1677,6 @@ out:
1735 * @data: ioctl data* 1677 * @data: ioctl data*
1736 * @file_prive: DRM file info 1678 * @file_prive: DRM file info
1737 * 1679 *
1738 * LOCKING:
1739 * Takes mode config lock.
1740 *
1741 * Set plane info, including placement, fb, scaling, and other factors. 1680 * Set plane info, including placement, fb, scaling, and other factors.
1742 * Or pass a NULL fb to disable. 1681 * Or pass a NULL fb to disable.
1743 */ 1682 */
@@ -1867,9 +1806,6 @@ out:
1867 * @cmd: cmd from ioctl 1806 * @cmd: cmd from ioctl
1868 * @arg: arg from ioctl 1807 * @arg: arg from ioctl
1869 * 1808 *
1870 * LOCKING:
1871 * Takes mode config lock.
1872 *
1873 * Build a new CRTC configuration based on user request. 1809 * Build a new CRTC configuration based on user request.
1874 * 1810 *
1875 * Called by the user via ioctl. 1811 * Called by the user via ioctl.
@@ -2125,9 +2061,6 @@ EXPORT_SYMBOL(drm_mode_legacy_fb_format);
2125 * @cmd: cmd from ioctl 2061 * @cmd: cmd from ioctl
2126 * @arg: arg from ioctl 2062 * @arg: arg from ioctl
2127 * 2063 *
2128 * LOCKING:
2129 * Takes mode config lock.
2130 *
2131 * Add a new FB to the specified CRTC, given a user request. 2064 * Add a new FB to the specified CRTC, given a user request.
2132 * 2065 *
2133 * Called by the user via ioctl. 2066 * Called by the user via ioctl.
@@ -2309,9 +2242,6 @@ static int framebuffer_check(const struct drm_mode_fb_cmd2 *r)
2309 * @cmd: cmd from ioctl 2242 * @cmd: cmd from ioctl
2310 * @arg: arg from ioctl 2243 * @arg: arg from ioctl
2311 * 2244 *
2312 * LOCKING:
2313 * Takes mode config lock.
2314 *
2315 * Add a new FB to the specified CRTC, given a user request with format. 2245 * Add a new FB to the specified CRTC, given a user request with format.
2316 * 2246 *
2317 * Called by the user via ioctl. 2247 * Called by the user via ioctl.
@@ -2375,9 +2305,6 @@ out:
2375 * @cmd: cmd from ioctl 2305 * @cmd: cmd from ioctl
2376 * @arg: arg from ioctl 2306 * @arg: arg from ioctl
2377 * 2307 *
2378 * LOCKING:
2379 * Takes mode config lock.
2380 *
2381 * Remove the FB specified by the user. 2308 * Remove the FB specified by the user.
2382 * 2309 *
2383 * Called by the user via ioctl. 2310 * Called by the user via ioctl.
@@ -2430,9 +2357,6 @@ out:
2430 * @cmd: cmd from ioctl 2357 * @cmd: cmd from ioctl
2431 * @arg: arg from ioctl 2358 * @arg: arg from ioctl
2432 * 2359 *
2433 * LOCKING:
2434 * Takes mode config lock.
2435 *
2436 * Lookup the FB given its ID and return info about it. 2360 * Lookup the FB given its ID and return info about it.
2437 * 2361 *
2438 * Called by the user via ioctl. 2362 * Called by the user via ioctl.
@@ -2549,9 +2473,6 @@ out_err1:
2549 * drm_fb_release - remove and free the FBs on this file 2473 * drm_fb_release - remove and free the FBs on this file
2550 * @filp: file * from the ioctl 2474 * @filp: file * from the ioctl
2551 * 2475 *
2552 * LOCKING:
2553 * Takes mode config lock.
2554 *
2555 * Destroy all the FBs associated with @filp. 2476 * Destroy all the FBs associated with @filp.
2556 * 2477 *
2557 * Called by the user via ioctl. 2478 * Called by the user via ioctl.