Skip to content

RFC DRM: Device Handling Cleanup

David Herrmann dri-devel 1 version In review

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 RFC Latest9 patches 5 repliesIn review

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/9drm: add drm_dev_alloc() helperdrivers/gpu/drm/drm_pci.c drivers/gpu/drm/drm_platform.c drivers/gpu/drm/drm_stub.c +2 more+80 -570 replies
2/9drm: merge device setup into drm_dev_register()drivers/gpu/drm/drm_pci.c drivers/gpu/drm/drm_platform.c drivers/gpu/drm/drm_stub.c +2 more+86 -1400 replies
3/9drm/agp: fix AGP cleanup pathsdrivers/gpu/drm/drm_agpsupport.c drivers/gpu/drm/drm_drv.c drivers/gpu/drm/drm_pci.c +2 more+71 -282 replies
4/9drm: move drm_lastclose() to drm_fops.cdrivers/gpu/drm/drm_drv.c drivers/gpu/drm/drm_fops.c+49 -490 replies
5/9drm: introduce drm_dev_free() to fix error pathsdrivers/gpu/drm/drm_pci.c drivers/gpu/drm/drm_platform.c drivers/gpu/drm/drm_stub.c +2 more+29 -130 replies
6/9drm: move device unregistration into drm_dev_unregister()drivers/gpu/drm/drm_stub.c include/drm/drmP.h+36 -220 replies
7/9percpu_rw_sempahore: export symbols for moduleslib/Makefile lib/percpu-rwsem.c+8 -10 replies
8/9drm: track pending user-space actionsdrivers/gpu/drm/Kconfig drivers/gpu/drm/drm_drv.c drivers/gpu/drm/drm_fops.c +2 more+96 -123 replies
9/9drm: support immediate unpluggingDocumentation/DocBook/drm.tmpl drivers/gpu/drm/drm_fops.c drivers/gpu/drm/drm_stub.c +1 more+162 -740 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v1 yet.

Read the v1 thread

Cover letter [RFC 0/9] DRM: Device Handling Cleanup

Hi

This series fixes unplugging of DRM devices. It introduces four new helpers which replace the old drm_put_dev(), drm_unplug_dev(), drm_fill_in_dev() helpers:
- drm_dev_alloc()
Allocate a DRM device, initialize all static objects and fill in driver data. The device is not registered nor advertised to user-space. But to free it again, you must call drm_dev_free() instead of kfree().
Once a device is allocated, you need to call drm_dev_register() to put life in it and let user-space make use of it.
- drm_dev_free()
Free a DRM device. This deallocates any resources that are linked to the object. After that, the "struct drm_device" object is invalid and must no longer be accessed.
- drm_dev_register()
Register a DRM device on the system. This will link it into sysfs and create the device nodes. Once registered, user-space can call into the file-ops.
- drm_dev_unregister()
Unregister a DRM device. This will unlink the device from all other objects, remove it from sysfs and prevent any further file-ops from user-space. It also takes care that all pending file-ops are finished before returning. This call is immediate! That is, we can use it instead of drm_put_dev() and the device will get unregistered immediately without breaking anything. We no longer need to use hacks like drm_unplug_dev() which just unregister the chardev-nodes.

These four are modeled after device_init(), put_device(), device_add() and device_del() from driver-core and follow the standard object rules. However, I didn't add any reference-counting, but instead track device-lifetime via drm_open() and drm_release() callbacks as we always did.
But the ->open_count field is basically a reference-count so maybe I will change this in a next revision to drm_dev_get() and drm_dev_put().

This is slightly based on Maarten Lankhorst's patches from:
http://cgit.freedesktop.org/~mlankhorst/linux/commit/?id=295965264c73f610e9538db2365142d6e2414849

I haven't tested this so far and I need to adjust the mmap() fops of all drivers, but I thought I'd just send a first RFC so people can comment on that.

Furthermore, the first 6 patches can be applied right away and fix error-paths during allocation and unify all the bus systems to use a single helper for device allocation.

Cheers
David

David Herrmann (9):
drm: add drm_dev_alloc() helper
drm: merge device setup into drm_dev_register() drm/agp: fix AGP cleanup paths
drm: move drm_lastclose() to drm_fops.c
drm: introduce drm_dev_free() to fix error paths
drm: move device unregistration into drm_dev_unregister()
percpu_rw_sempahore: export symbols for modules
drm: track pending user-space actions
drm: support immediate unplugging

 Documentation/DocBook/drm.tmpl   |   5 +
 drivers/gpu/drm/Kconfig          |   1 +
 drivers/gpu/drm/drm_agpsupport.c |  51 +++++
 drivers/gpu/drm/drm_drv.c        |  74 +------
 drivers/gpu/drm/drm_fops.c       | 165 +++++++++++----
 drivers/gpu/drm/drm_pci.c        |  65 ++----
 drivers/gpu/drm/drm_platform.c   |  50 +----
 drivers/gpu/drm/drm_stub.c       | 439 +++++++++++++++++++++++++++++----------
 drivers/gpu/drm/drm_usb.c        |  48 +----
 include/drm/drmP.h               |  30 +--
 lib/Makefile                     |   2 +-
 lib/percpu-rwsem.c               |   7 +
 12 files changed, 579 insertions(+), 358 deletions(-)
Signature · 1 line
1.8.3.3