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

drm: Document device unplug infrastructure

While at it, also ocd and give them a consistent drm_dev_ prefix, like
the other device instance functionality. Plus move the functions into
the right places.

Reviewed-by: Alex Deucher <alexander.deucher@amd.com>
Signed-off-by: Daniel Vetter <daniel.vetter@intel.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20170802115604.12734-3-daniel.vetter@ffwll.ch

+51 -28
+21 -3
drivers/gpu/drm/drm_drv.c
··· 291 291 292 292 if (!minor) { 293 293 return ERR_PTR(-ENODEV); 294 - } else if (drm_device_is_unplugged(minor->dev)) { 294 + } else if (drm_dev_is_unplugged(minor->dev)) { 295 295 drm_dev_unref(minor->dev); 296 296 return ERR_PTR(-ENODEV); 297 297 } ··· 364 364 } 365 365 EXPORT_SYMBOL(drm_put_dev); 366 366 367 - void drm_unplug_dev(struct drm_device *dev) 367 + static void drm_device_set_unplugged(struct drm_device *dev) 368 + { 369 + smp_wmb(); 370 + atomic_set(&dev->unplugged, 1); 371 + } 372 + 373 + /** 374 + * drm_dev_unplug - unplug a DRM device 375 + * @dev: DRM device 376 + * 377 + * This unplugs a hotpluggable DRM device, which makes it inaccessible to 378 + * userspace operations. Entry-points can use drm_dev_is_unplugged(). This 379 + * essentially unregisters the device like drm_dev_unregister(), but can be 380 + * called while there are still open users of @dev. 381 + */ 382 + void drm_dev_unplug(struct drm_device *dev) 368 383 { 369 384 /* for a USB device */ 370 385 if (drm_core_check_feature(dev, DRIVER_MODESET)) ··· 398 383 } 399 384 mutex_unlock(&drm_global_mutex); 400 385 } 401 - EXPORT_SYMBOL(drm_unplug_dev); 386 + EXPORT_SYMBOL(drm_dev_unplug); 402 387 403 388 /* 404 389 * DRM internal mount ··· 849 834 * Unregister the DRM device from the system. This does the reverse of 850 835 * drm_dev_register() but does not deallocate the device. The caller must call 851 836 * drm_dev_unref() to drop their final reference. 837 + * 838 + * A special form of unregistering for hotpluggable devices is drm_dev_unplug(), 839 + * which can be called while there are still open users of @dev. 852 840 * 853 841 * This should be called first in the device teardown code to make sure 854 842 * userspace can't access the device instance any more.
+1 -1
drivers/gpu/drm/drm_file.c
··· 436 436 437 437 if (!--dev->open_count) { 438 438 drm_lastclose(dev); 439 - if (drm_device_is_unplugged(dev)) 439 + if (drm_dev_is_unplugged(dev)) 440 440 drm_put_dev(dev); 441 441 } 442 442 mutex_unlock(&drm_global_mutex);
+1 -1
drivers/gpu/drm/drm_gem.c
··· 1001 1001 struct drm_vma_offset_node *node; 1002 1002 int ret; 1003 1003 1004 - if (drm_device_is_unplugged(dev)) 1004 + if (drm_dev_is_unplugged(dev)) 1005 1005 return -ENODEV; 1006 1006 1007 1007 drm_vma_offset_lock_lookup(dev->vma_offset_manager);
+1 -1
drivers/gpu/drm/drm_gem_cma_helper.c
··· 390 390 struct drm_device *dev = priv->minor->dev; 391 391 struct drm_vma_offset_node *node; 392 392 393 - if (drm_device_is_unplugged(dev)) 393 + if (drm_dev_is_unplugged(dev)) 394 394 return -ENODEV; 395 395 396 396 drm_vma_offset_lock_lookup(dev->vma_offset_manager);
+2 -2
drivers/gpu/drm/drm_ioctl.c
··· 716 716 struct drm_device *dev = file_priv->minor->dev; 717 717 int retcode; 718 718 719 - if (drm_device_is_unplugged(dev)) 719 + if (drm_dev_is_unplugged(dev)) 720 720 return -ENODEV; 721 721 722 722 retcode = drm_ioctl_permit(flags, file_priv); ··· 765 765 766 766 dev = file_priv->minor->dev; 767 767 768 - if (drm_device_is_unplugged(dev)) 768 + if (drm_dev_is_unplugged(dev)) 769 769 return -ENODEV; 770 770 771 771 is_driver_ioctl = nr >= DRM_COMMAND_BASE && nr < DRM_COMMAND_END;
+1 -1
drivers/gpu/drm/drm_vm.c
··· 631 631 struct drm_device *dev = priv->minor->dev; 632 632 int ret; 633 633 634 - if (drm_device_is_unplugged(dev)) 634 + if (drm_dev_is_unplugged(dev)) 635 635 return -ENODEV; 636 636 637 637 mutex_lock(&dev->struct_mutex);
+1 -1
drivers/gpu/drm/tinydrm/core/tinydrm-pipe.c
··· 56 56 static enum drm_connector_status 57 57 tinydrm_connector_detect(struct drm_connector *connector, bool force) 58 58 { 59 - if (drm_device_is_unplugged(connector->dev)) 59 + if (drm_dev_is_unplugged(connector->dev)) 60 60 return connector_status_disconnected; 61 61 62 62 return connector->status;
+1 -1
drivers/gpu/drm/udl/udl_connector.c
··· 96 96 static enum drm_connector_status 97 97 udl_detect(struct drm_connector *connector, bool force) 98 98 { 99 - if (drm_device_is_unplugged(connector->dev)) 99 + if (drm_dev_is_unplugged(connector->dev)) 100 100 return connector_status_disconnected; 101 101 return connector_status_connected; 102 102 }
+1 -1
drivers/gpu/drm/udl/udl_drv.c
··· 102 102 drm_kms_helper_poll_disable(dev); 103 103 udl_fbdev_unplug(dev); 104 104 udl_drop_usb(dev); 105 - drm_unplug_dev(dev); 105 + drm_dev_unplug(dev); 106 106 } 107 107 108 108 /*
+1 -1
drivers/gpu/drm/udl/udl_fb.c
··· 198 198 struct udl_device *udl = dev->dev_private; 199 199 200 200 /* If the USB device is gone, we don't accept new opens */ 201 - if (drm_device_is_unplugged(udl->ddev)) 201 + if (drm_dev_is_unplugged(udl->ddev)) 202 202 return -ENODEV; 203 203 204 204 ufbdev->fb_count++;
-13
include/drm/drmP.h
··· 320 320 return ((dev->driver->driver_features & feature) ? 1 : 0); 321 321 } 322 322 323 - static inline void drm_device_set_unplugged(struct drm_device *dev) 324 - { 325 - smp_wmb(); 326 - atomic_set(&dev->unplugged, 1); 327 - } 328 - 329 - static inline int drm_device_is_unplugged(struct drm_device *dev) 330 - { 331 - int ret = atomic_read(&dev->unplugged); 332 - smp_rmb(); 333 - return ret; 334 - } 335 - 336 323 /******************************************************************/ 337 324 /** \name Internal function definitions */ 338 325 /*@{*/
+20 -2
include/drm/drm_drv.h
··· 30 30 #include <linux/list.h> 31 31 #include <linux/irqreturn.h> 32 32 33 - struct drm_device; 33 + #include <drm/drm_device.h> 34 + 34 35 struct drm_file; 35 36 struct drm_gem_object; 36 37 struct drm_master; ··· 614 613 void drm_dev_ref(struct drm_device *dev); 615 614 void drm_dev_unref(struct drm_device *dev); 616 615 void drm_put_dev(struct drm_device *dev); 617 - void drm_unplug_dev(struct drm_device *dev); 616 + void drm_dev_unplug(struct drm_device *dev); 617 + 618 + /** 619 + * drm_dev_is_unplugged - is a DRM device unplugged 620 + * @dev: DRM device 621 + * 622 + * This function can be called to check whether a hotpluggable is unplugged. 623 + * Unplugging itself is singalled through drm_dev_unplug(). If a device is 624 + * unplugged, these two functions guarantee that any store before calling 625 + * drm_dev_unplug() is visible to callers of this function after it completes 626 + */ 627 + static inline int drm_dev_is_unplugged(struct drm_device *dev) 628 + { 629 + int ret = atomic_read(&dev->unplugged); 630 + smp_rmb(); 631 + return ret; 632 + } 633 + 618 634 619 635 int drm_dev_set_unique(struct drm_device *dev, const char *name); 620 636