DRM device-alloc cleanup
Subsystems (2)
cover DRM device-alloc cleanup
Hi
This cleans up the bus drivers in DRM. Instead of copying the device alloc/free semantics into each bus driver (drm_{pci,platform,usb}.c) we now have a central place in drm_stub.c.
This introduces drm_dev_{alloc,free,register,unregister}(). They have the same semantics as most other kernel subsystems. *_alloc() allocates a new device and populates the static fields and sub-objects. *_free() frees an unregistered object allocated via *_alloc(). *_register() registers a DRM device and *_unregister() obviously unregisters a DRM device. A *_free() is still needed after calling *_unregister() (same as for "struct device"). No ref-counting is added as it is not required by any driver.
Note that the bus drivers are modified to use the new helpers directly. However, I didn't modify the drivers to use *_unregister() and *_free() directly. Instead, the drm_put_dev() helper was modified to use these. Reason for that is that I have pending patches to make device hotplugging safer regarding mmaps. But these aren't ready, yet. Hopefully I can get them ready for rc5 or rc6.
Tested on nouveau.
David
David Herrmann (5):
drm: add drm_dev_alloc() helper
drm: merge device setup into drm_dev_register()
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()
drivers/gpu/drm/drm_drv.c | 70 ---------- drivers/gpu/drm/drm_fops.c | 70 ++++++++++ drivers/gpu/drm/drm_pci.c | 62 ++------- drivers/gpu/drm/drm_platform.c | 59 +------- drivers/gpu/drm/drm_stub.c | 310 ++++++++++++++++++++++++++++------------- drivers/gpu/drm/drm_usb.c | 57 +------- include/drm/drmP.h | 8 +- 7 files changed, 308 insertions(+), 328 deletions(-)
Signature · 1 line
1.8.4
PATCH 1/5 drm: add drm_dev_alloc() helper
Instead of managing device allocation+initialization in each bus-driver, we should do that in a central place. drm_fill_in_dev() already does most of it, but also requires the global drm lock for partial AGP device registration.
Split both apart so we have a clean device initialization/allocation phase, and a registration phase.
--- drivers/gpu/drm/drm_pci.c | 4 +- drivers/gpu/drm/drm_platform.c | 3 +- drivers/gpu/drm/drm_stub.c | 121 +++++++++++++++++++++++++---------------- drivers/gpu/drm/drm_usb.c | 7 +-- include/drm/drmP.h | 2 + 5 files changed, 80 insertions(+), 57 deletions(-)
drivers/gpu/drm/drm_pci.c +1 -3
@@ -322,7 +322,7 @@ int drm_get_pci_dev(struct pci_dev *pdev, const struct pci_device_id *ent,DRM_DEBUG ("\n" ); - dev =kzalloc (sizeof (*dev),GFP_KERNEL ); + dev =drm_dev_alloc (driver, &pdev->dev);if (!dev)return -ENOMEM ;
@@ -331,8 +331,6 @@ int drm_get_pci_dev(struct pci_dev *pdev, const struct pci_device_id *ent, goto err_g1; dev->pdev = pdev; - dev->dev = &pdev->dev; - dev->pci_device = pdev->device; dev->pci_vendor = pdev->vendor;
drivers/gpu/drm/drm_platform.c +1 -2
@@ -47,12 +47,11 @@ static int drm_get_platform_dev(struct platform_device *platdev,DRM_DEBUG ("\n" ); - dev =kzalloc (sizeof (*dev),GFP_KERNEL ); + dev =drm_dev_alloc (driver, &platdev->dev);if (!dev)return -ENOMEM ; dev->platformdev = platdev; - dev->dev = &platdev->dev;mutex_lock (&drm_global_mutex);
drivers/gpu/drm/drm_stub.c +74 -47
137 lines not on this page · raw message
drivers/gpu/drm/drm_usb.c +2 -5
@@ -7,18 +7,15 @@ int drm_get_usb_dev(struct usb_interface *interface, struct drm_driver *driver) {struct drm_device *dev; -struct usb_device *usbdev;int ret;DRM_DEBUG ("\n" ); - dev =kzalloc (sizeof (*dev),GFP_KERNEL ); + dev =drm_dev_alloc (driver, &interface->dev);if (!dev)return -ENOMEM ; - usbdev =interface_to_usbdev (interface); - dev->usbdev = usbdev; - dev->dev = &interface->dev; + dev->usbdev =interface_to_usbdev (interface);mutex_lock (&drm_global_mutex);
include/drm/drmP.h +2 -0
@@ -1648,6 +1648,8 @@ static __inline__ void drm_core_dropmap(struct drm_local_map *map)extern int drm_fill_in_dev (struct drm_device *dev,const struct pci_device_id *ent,struct drm_driver *driver); +struct drm_device *drm_dev_alloc (struct drm_driver *driver, +struct device *parent);int drm_get_minor (struct drm_device *dev,struct drm_minor **minor,int type);/*@}*/
Signature · 1 line
1.8.4
PATCH 2/5 drm: merge device setup into drm_dev_register()
In reply to David HerrmannAll bus drivers do device setup themselves. This requires us to adjust all of them if we introduce new core features. Thus, merge all these into a uniform drm_dev_register() helper.
Note that this removes the drm_lastclose() error path for AGP as it is horribly broken. Moreover, no bus driver called this in any other error path either. Instead, we use the recently introduced AGP cleanup helpers.
We also keep a DRIVER_MODESET condition around pci_set_drvdata() to keep semantics.
--- drivers/gpu/drm/drm_pci.c | 56 +++-------------------- drivers/gpu/drm/drm_platform.c | 54 ++-------------------- drivers/gpu/drm/drm_stub.c | 101 +++++++++++++++++++++++++++++++++-------- drivers/gpu/drm/drm_usb.c | 48 ++------------------ include/drm/drmP.h | 4 +- 5 files changed, 96 insertions(+), 167 deletions(-)
drivers/gpu/drm/drm_pci.c +7 -49
@@ -328,7 +328,7 @@ int drm_get_pci_dev(struct pci_dev *pdev, const struct pci_device_id *ent, ret =pci_enable_device (pdev);if (ret) - goto err_g1; + goto err_free; dev->pdev = pdev; dev->pci_device = pdev->device;
@@ -338,65 +338,23 @@ int drm_get_pci_dev(struct pci_dev *pdev, const struct pci_device_id *ent, dev->hose = pdev->sysdata;#endif -mutex_lock (&drm_global_mutex); - -if ((ret =drm_fill_in_dev (dev, ent, driver))) { -printk (KERN_ERR "DRM: Fill_in_dev failed.\n" ); - goto err_g2; - } - -if (drm_core_check_feature (dev,DRIVER_MODESET )) { +if (drm_core_check_feature (dev,DRIVER_MODESET ))pci_set_drvdata (pdev, dev); - ret =drm_get_minor (dev, &dev->control,DRM_MINOR_CONTROL ); -if (ret) - goto err_g2; - } - -if (drm_core_check_feature (dev,DRIVER_RENDER ) && drm_rnodes) { - ret =drm_get_minor (dev, &dev->render,DRM_MINOR_RENDER ); -if (ret) - goto err_g21; - } -if ((ret =drm_get_minor (dev, &dev->primary,DRM_MINOR_LEGACY ))) - goto err_g3; - -if (dev->driver->load) { - ret = dev->driver->load (dev, ent->driver_data); -if (ret) - goto err_g4; - } - -/* setup the grouping for the legacy output */ -if (drm_core_check_feature (dev,DRIVER_MODESET )) { - ret =drm_mode_group_init_legacy_group (dev, - &dev->primary->mode_group); -if (ret) - goto err_g4; - } - -list_add_tail (&dev->driver_item, &driver->device_list); + ret =drm_dev_register (dev); +if (ret) + goto err_pci;DRM_INFO ("Initialized %s %d.%d.%d %s for %s on minor %d\n" , driver->name, driver->major, driver->minor, driver->patchlevel, driver->date,pci_name (pdev), dev->primary->index); -mutex_unlock (&drm_global_mutex);return 0 ; -err_g4: -drm_put_minor (&dev->primary); -err_g3: -if (dev->render) -drm_put_minor (&dev->render); -err_g21: -if (drm_core_check_feature (dev,DRIVER_MODESET )) -drm_put_minor (&dev->control); -err_g2: +err_pci:pci_disable_device (pdev); -err_g1: +err_free:kfree (dev); -mutex_unlock (&drm_global_mutex);return ret; }EXPORT_SYMBOL (drm_get_pci_dev);
drivers/gpu/drm/drm_platform.c +3 -51
68 lines not on this page · raw message
drivers/gpu/drm/drm_stub.c +82 -19
116 lines not on this page · raw message
drivers/gpu/drm/drm_usb.c +3 -45
64 lines not on this page · raw message
include/drm/drmP.h +1 -3
@@ -1645,11 +1645,9 @@ static __inline__ void drm_core_dropmap(struct drm_local_map *map)#include <drm/drm_mem_util.h> -extern int drm_fill_in_dev (struct drm_device *dev, -const struct pci_device_id *ent, -struct drm_driver *driver);struct drm_device *drm_dev_alloc (struct drm_driver *driver,struct device *parent); +int drm_dev_register (struct drm_device *dev);int drm_get_minor (struct drm_device *dev,struct drm_minor **minor,int type);/*@}*/
Signature · 1 line
1.8.4
Re: [PATCH 2/5] drm: merge device setup into drm_dev_register()
Quoted 12 lines · David Herrmann
All bus drivers do device setup themselves. This requires us to adjust all of them if we introduce new core features. Thus, merge all these into a uniform
drm_dev_register()helper.Note that this removes the
drm_lastclose()error path for AGP as it is horribly broken. Moreover, no bus driver called this in any other error path either. Instead, we use the recently introduced AGP cleanup helpers.We also keep a
DRIVER_MODESETcondition aroundpci_set_drvdata()to keep semantics.Signed-off-by David Herrmann <[email protected]>
[snip]
drivers/gpu/drm/drm_stub.c err_free: · line 527
Quoted 11 lines
drivers/gpu/drm/drm_stub.c +11
-0+int drm_dev_register (struct drm_device *dev) +{ +int ret; + +mutex_lock (&drm_global_mutex); + +if (dev->driver->bus->agp_init) { + ret = dev->driver->bus->agp_init (dev); +if (ret) + goto out_unlock; + }
Imo this should stay in drm_get_pci_dev since its pci specific - no other bus type should ever bother with this really.
Looks good otherwise.
-Daniel
Signature · 3 lines
Daniel Vetter Software Engineer, Intel Corporation +41 (0) 79 365 57 48 - http://blog.ffwll.ch
Re: [PATCH 2/5] drm: merge device setup into drm_dev_register()
Hi Daniel
Quoted 16 lines · Daniel Vetter
Quoted 12 lines · David Herrmann
All bus drivers do device setup themselves. This requires us to adjust all of them if we introduce new core features. Thus, merge all these into a uniform
drm_dev_register()helper.Note that this removes the
drm_lastclose()error path for AGP as it is horribly broken. Moreover, no bus driver called this in any other error path either. Instead, we use the recently introduced AGP cleanup helpers.We also keep a
DRIVER_MODESETcondition aroundpci_set_drvdata()to keep semantics.Signed-off-by David Herrmann <[email protected]>[snip]
Quoted 14 lines
drivers/gpu/drm/drm_stub.c err_free: · line 527
Quoted 11 lines
drivers/gpu/drm/drm_stub.c +11
-0+int drm_dev_register (struct drm_device *dev) +{ +int ret; + +mutex_lock (&drm_global_mutex); + +if (dev->driver->bus->agp_init) { + ret = dev->driver->bus->agp_init (dev); +if (ret) + goto out_unlock; + }Imo this should stay in
drm_get_pci_devsince its pci specific - no other bus type should ever bother with this really.
You mean I should _move_ it to drm_pci.c? It has never been pci-specific. But sure, I can do that. It actually makes sense. But I'd like to do that in a followup patch as it's a semantic change that's not directly related. I will include it in v2.
Thanks
David
Re: [PATCH 2/5] drm: merge device setup into drm_dev_register()
Quoted 4 lines · David Herrmann
You mean I should _move_ it to
drm_pci.c? It has never been pci-specific. But sure, I can do that. It actually makes sense. But I'd like to do that in a followup patch as it's a semantic change that's not directly related. I will include it in v2.
Oh right it's always been in fill_in_dev, but never should have been there ;-) Follow-up patch like you've suggested it better. -Daniel
Signature · 3 lines
Daniel Vetter Software Engineer, Intel Corporation +41 (0) 79 365 57 48 - http://blog.ffwll.ch
PATCH 3/5 drm: move drm_lastclose() to drm_fops.c
In reply to David HerrmannTry to keep all functions that handle DRM file_operations in drm_fops.c so internal helpers can be marked static later.
This makes the split between the 3 core files more obvious:
- drm_stub.c: DRM device allocation/destruction and management
- drm_fops.c: DRM file_operations (except for ioctl)
- drm_drv.c: Global DRM init + ioctl handling
Well, ioctl handling is still spread throughout hundreds of source files, but at least the others are clearly defined this way.
--- drivers/gpu/drm/drm_drv.c | 70 ---------------------------------------------- drivers/gpu/drm/drm_fops.c | 70 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 70 insertions(+), 70 deletions(-)
drivers/gpu/drm/drm_drv.c +0 -70
@@ -170,76 +170,6 @@ static const struct drm_ioctl_desc drm_ioctls[] = {#define DRM_CORE_IOCTL_COUNT ARRAY_SIZE( drm_ioctls ) -/** -* drm_legacy_dev_reinit -* -* Reinitializes a legacy/ums drm device in it's lastclose function. -*/ -static void drm_legacy_dev_reinit (struct drm_device *dev) -{ -int i; - -if (drm_core_check_feature (dev,DRIVER_MODESET )) -return ; - -atomic_set (&dev->ioctl_count,0 ); -atomic_set (&dev->vma_count,0 ); - -for (i =0 ; i <ARRAY_SIZE (dev->counts); i++) -atomic_set (&dev->counts[i],0 ); - - dev->sigdata.lock =NULL ; - - dev->context_flag =0 ; - dev->last_context =0 ; - dev->if_version =0 ; -} - -/** -* Take down the DRM device. -* -* \param dev DRM device structure. -* -* Frees every resource in \p dev. -* -* \sa drm_device -*/ -int drm_lastclose (struct drm_device * dev) -{ -struct drm_vma_entry *vma, *vma_temp; - -DRM_DEBUG ("\n" ); - -if (dev->driver->lastclose) - dev->driver->lastclose (dev); -DRM_DEBUG ("driver lastclose completed\n" ); - -if (dev->irq_enabled && !drm_core_check_feature (dev,DRIVER_MODESET )) -drm_irq_uninstall (dev); - -mutex_lock (&dev->struct_mutex); - -drm_agp_clear (dev); - -drm_legacy_sg_cleanup (dev); - -/* Clear vma list (only built for debugging) */ -list_for_each_entry_safe (vma, vma_temp, &dev->vmalist, head) { -list_del (&vma->head); -kfree (vma); - } - -drm_legacy_dma_takedown (dev); - - dev->dev_mapping =NULL ; -mutex_unlock (&dev->struct_mutex); - -drm_legacy_dev_reinit (dev); - -DRM_DEBUG ("lastclose completed\n" ); -return 0 ; -} -/** File operations structure */ static const struct file_operations drm_stub_fops = { .owner =THIS_MODULE ,
drivers/gpu/drm/drm_fops.c +70 -0
76 lines not on this page · raw message
Signature · 1 line
1.8.4
PATCH 4/5 drm: introduce drm_dev_free() to fix error paths
In reply to David HerrmannThe error paths in DRM bus drivers currently leak memory as they don't correctly revert drm_dev_alloc(). Introduce drm_dev_free() to free DRM devices which haven't been registered, yet.
We must be careful not to introduce any side-effects with cleanups done in drm_dev_free(). drm_ht_remove(), drm_ctxbitmap_cleanup() and drm_gem_destroy() are all fine in that regard.
--- drivers/gpu/drm/drm_pci.c | 2 +- drivers/gpu/drm/drm_platform.c | 2 +- drivers/gpu/drm/drm_stub.c | 35 +++++++++++++++++++++++++---------- drivers/gpu/drm/drm_usb.c | 2 +- include/drm/drmP.h | 1 + 5 files changed, 29 insertions(+), 13 deletions(-)
drivers/gpu/drm/drm_pci.c +1 -1
@@ -354,7 +354,7 @@ int drm_get_pci_dev(struct pci_dev *pdev, const struct pci_device_id *ent, err_pci:pci_disable_device (pdev); err_free: -kfree (dev); +drm_dev_free (dev);return ret; }EXPORT_SYMBOL (drm_get_pci_dev);
drivers/gpu/drm/drm_platform.c +1 -1
@@ -64,7 +64,7 @@ static int drm_get_platform_dev(struct platform_device *platdev,return 0 ; err_free: -kfree (dev); +drm_dev_free (dev);return ret; }
drivers/gpu/drm/drm_stub.c +25 -10
@@ -363,7 +363,6 @@ static void drm_unplug_minor(struct drm_minor *minor)*/ void drm_put_dev (struct drm_device *dev) { -struct drm_driver *driver;struct drm_map_list *r_list, *list_temp;DRM_DEBUG ("\n" );
@@ -372,7 +371,6 @@ void drm_put_dev(struct drm_device *dev)DRM_ERROR ("cleanup called no dev\n" );return ; } - driver = dev->driver;drm_lastclose (dev);
@@ -386,9 +384,6 @@ void drm_put_dev(struct drm_device *dev)list_for_each_entry_safe (r_list, list_temp, &dev->maplist, head)drm_rmmap (dev, r_list->map); -drm_ht_remove (&dev->map_hash); - -drm_ctxbitmap_cleanup (dev);if (drm_core_check_feature (dev,DRIVER_MODESET ))drm_put_minor (&dev->control);
@@ -396,14 +391,11 @@ void drm_put_dev(struct drm_device *dev)if (dev->render)drm_put_minor (&dev->render); -if (driver->driver_features &DRIVER_GEM ) -drm_gem_destroy (dev); -drm_put_minor (&dev->primary);list_del (&dev->driver_item); -kfree (dev->devname); -kfree (dev); + +drm_dev_free (dev); }EXPORT_SYMBOL (drm_put_dev);
@@ -502,6 +494,29 @@ err_free:EXPORT_SYMBOL (drm_dev_alloc);/** +* drm_dev_free - Free DRM device +* @dev: DRM device to free +* +* Free a DRM device that has previously been allocated via drm_dev_alloc(). +* You must not use kfree() instead or you will leak memory. +* +* This must not be called once the device got registered. Use drm_put_dev() +* instead, which then calls drm_dev_free(). +*/ +void drm_dev_free (struct drm_device *dev) +{ +if (dev->driver->driver_features &DRIVER_GEM ) +drm_gem_destroy (dev); + +drm_ctxbitmap_cleanup (dev); +drm_ht_remove (&dev->map_hash); + +kfree (dev->devname); +kfree (dev); +} +EXPORT_SYMBOL (drm_dev_free); + +/** * drm_dev_register - Register DRM device * @dev: Device to register *
drivers/gpu/drm/drm_usb.c +1 -1
@@ -29,7 +29,7 @@ int drm_get_usb_dev(struct usb_interface *interface,return 0 ; err_free: -kfree (dev); +drm_dev_free (dev);return ret; }
include/drm/drmP.h +1 -0
@@ -1647,6 +1647,7 @@ static __inline__ void drm_core_dropmap(struct drm_local_map *map)struct drm_device *drm_dev_alloc (struct drm_driver *driver,struct device *parent); +void drm_dev_free (struct drm_device *dev);int drm_dev_register (struct drm_device *dev);int drm_get_minor (struct drm_device *dev,struct drm_minor **minor,int type);/*@}*/
Signature · 1 line
1.8.4
PATCH 5/5 drm: move device unregistration into drm_dev_unregister()
In reply to David HerrmannAnalog to drm_dev_register(), we now provide drm_dev_unregister() which does the reverse. drm_dev_put() is still in place and combines the calls to drm_dev_unregister() and drm_dev_free() so buses don't have to change.
*_get() and *_put() are used for reference-counting in the kernel. However, drm_dev_put() definitely does not do any kind of ref-counting. Hence, use the more appropriate *_register(), *_unregister(), *_alloc() and *_free() names.
--- drivers/gpu/drm/drm_stub.c | 61 +++++++++++++++++++++++++++------------------- include/drm/drmP.h | 1 + 2 files changed, 37 insertions(+), 25 deletions(-)
drivers/gpu/drm/drm_stub.c +36 -25
@@ -363,8 +363,6 @@ static void drm_unplug_minor(struct drm_minor *minor)*/ void drm_put_dev (struct drm_device *dev) { -struct drm_map_list *r_list, *list_temp; -DRM_DEBUG ("\n" );if (!dev) {
@@ -372,29 +370,7 @@ void drm_put_dev(struct drm_device *dev)return ; } -drm_lastclose (dev); - -if (dev->driver->unload) - dev->driver->unload (dev); - -if (dev->driver->bus->agp_destroy) - dev->driver->bus->agp_destroy (dev); - -drm_vblank_cleanup (dev); - -list_for_each_entry_safe (r_list, list_temp, &dev->maplist, head) -drm_rmmap (dev, r_list->map); - -if (drm_core_check_feature (dev,DRIVER_MODESET )) -drm_put_minor (&dev->control); - -if (dev->render) -drm_put_minor (&dev->render); - -drm_put_minor (&dev->primary); - -list_del (&dev->driver_item); - +drm_dev_unregister (dev);drm_dev_free (dev); }EXPORT_SYMBOL (drm_put_dev);
@@ -595,3 +571,38 @@ out_unlock:return ret; }EXPORT_SYMBOL (drm_dev_register); + +/** +* drm_dev_unregister - Unregister DRM device +* @dev: Device to unregister +* +* Unregister the DRM device from the system. This does the reverse of +* drm_dev_register() but does not deallocate the device. The caller must call +* drm_dev_free() to free all resources. +*/ +void drm_dev_unregister (struct drm_device *dev) +{ +struct drm_map_list *r_list, *list_temp; + +drm_lastclose (dev); + +if (dev->driver->unload) + dev->driver->unload (dev); + +if (dev->driver->bus->agp_destroy) + dev->driver->bus->agp_destroy (dev); + +drm_vblank_cleanup (dev); + +list_for_each_entry_safe (r_list, list_temp, &dev->maplist, head) +drm_rmmap (dev, r_list->map); + +if (dev->control) +drm_put_minor (&dev->control); +if (dev->render) +drm_put_minor (&dev->render); +drm_put_minor (&dev->primary); + +list_del (&dev->driver_item); +} +EXPORT_SYMBOL (drm_dev_unregister);
include/drm/drmP.h +1 -0
@@ -1649,6 +1649,7 @@ struct drm_device *drm_dev_alloc(struct drm_driver *driver, struct device *parent);void drm_dev_free (struct drm_device *dev);int drm_dev_register (struct drm_device *dev); +void drm_dev_unregister (struct drm_device *dev);int drm_get_minor (struct drm_device *dev,struct drm_minor **minor,int type);/*@}*/
Signature · 1 line
1.8.4
Re: [PATCH 5/5] drm: move device unregistration into drm_dev_unregister()
Quoted 10 lines · David Herrmann
Analog to
drm_dev_register(), we now providedrm_dev_unregister()which does the reverse.drm_dev_put()is still in place and combines the calls todrm_dev_unregister()anddrm_dev_free()so buses don't have to change.
*_get()and*_put()are used for reference-counting in the kernel. However,drm_dev_put()definitely does not do any kind of ref-counting. Hence, use the more appropriate*_register(),*_unregister(),*_alloc()and*_free()names.Signed-off-by David Herrmann <[email protected]>
With the agp_init call moved back into pci code this series is
We still have a bit a midlayer smell here, and to correctly fix the init/cleanup order I think a bit more work is required. But this is a definit step up imo.
-Daniel
Quoted 107 lines
--- drivers/gpu/drm/drm_stub.c | 61 +++++++++++++++++++++++++++------------------- include/drm/drmP.h | 1 + 2 files changed, 37 insertions(+), 25 deletions(-)drivers/gpu/drm/drm_stub.c +36
-25@@ -363,8 +363,6 @@ static void drm_unplug_minor(struct drm_minor *minor)*/ void drm_put_dev (struct drm_device *dev) { -struct drm_map_list *r_list, *list_temp; -DRM_DEBUG ("\n" );if (!dev) {@@ -372,29 +370,7 @@ void drm_put_dev(struct drm_device *dev)return ; } -drm_lastclose (dev); - -if (dev->driver->unload) - dev->driver->unload (dev); - -if (dev->driver->bus->agp_destroy) - dev->driver->bus->agp_destroy (dev); - -drm_vblank_cleanup (dev); - -list_for_each_entry_safe (r_list, list_temp, &dev->maplist, head) -drm_rmmap (dev, r_list->map); - -if (drm_core_check_feature (dev,DRIVER_MODESET )) -drm_put_minor (&dev->control); - -if (dev->render) -drm_put_minor (&dev->render); - -drm_put_minor (&dev->primary); - -list_del (&dev->driver_item); - +drm_dev_unregister (dev);drm_dev_free (dev); }EXPORT_SYMBOL (drm_put_dev);@@ -595,3 +571,38 @@ out_unlock:return ret; }EXPORT_SYMBOL (drm_dev_register); + +/** +* drm_dev_unregister - Unregister DRM device +* @dev: Device to unregister +* +* Unregister the DRM device from the system. This does the reverse of +* drm_dev_register() but does not deallocate the device. The caller must call +* drm_dev_free() to free all resources. +*/ +void drm_dev_unregister (struct drm_device *dev) +{ +struct drm_map_list *r_list, *list_temp; + +drm_lastclose (dev); + +if (dev->driver->unload) + dev->driver->unload (dev); + +if (dev->driver->bus->agp_destroy) + dev->driver->bus->agp_destroy (dev); + +drm_vblank_cleanup (dev); + +list_for_each_entry_safe (r_list, list_temp, &dev->maplist, head) +drm_rmmap (dev, r_list->map); + +if (dev->control) +drm_put_minor (&dev->control); +if (dev->render) +drm_put_minor (&dev->render); +drm_put_minor (&dev->primary); + +list_del (&dev->driver_item); +} +EXPORT_SYMBOL (drm_dev_unregister);include/drm/drmP.h +1
-0@@ -1649,6 +1649,7 @@ struct drm_device *drm_dev_alloc(struct drm_driver *driver, struct device *parent);void drm_dev_free (struct drm_device *dev);int drm_dev_register (struct drm_device *dev); +void drm_dev_unregister (struct drm_device *dev);int drm_get_minor (struct drm_device *dev,struct drm_minor **minor,int type);/*@}*/ Signature · 6 lines
1.8.4 _______________________________________________ dri-devel mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/dri-devel
Signature · 3 lines
Daniel Vetter Software Engineer, Intel Corporation +41 (0) 79 365 57 48 - http://blog.ffwll.ch
Dave Airlie
maintainerQuoted 14 lines · David Herrmann
Hi
This cleans up the bus drivers in DRM. Instead of copying the device alloc/free semantics into each bus driver (drm_{pci,platform,usb}.c) we now have a central place in
drm_stub.c.This introduces drm_dev_{alloc,free,register,unregister}(). They have the same semantics as most other kernel subsystems.
*_alloc()allocates a new device and populates the static fields and sub-objects.*_free()frees an unregistered object allocated via*_alloc().*_register()registers a DRM device and*_unregister()obviously unregisters a DRM device. A*_free()is still needed after calling*_unregister()(same as for "struct device"). No ref-counting is added as it is not required by any driver.
Quoted 8 lines
Note that the bus drivers are modified to use the new helpers directly. However, I didn't modify the drivers to use
*_unregister()and*_free()directly. Instead, thedrm_put_dev()helper was modified to use these. Reason for that is that I have pending patches to make device hotplugging safer regarding mmaps. But these aren't ready, yet. Hopefully I can get them ready for rc5 or rc6.Tested on nouveau.
Okay I've merged this series, a follow-on to fix the AGP bits like Daniel suggested would be good.
Dave.
Dave Airlie
maintainerQuoted 21 lines · Dave Airlie
Quoted 20 lines · David Herrmann
Hi
This cleans up the bus drivers in DRM. Instead of copying the device alloc/free semantics into each bus driver (drm_{pci,platform,usb}.c) we now have a central place in
drm_stub.c.This introduces drm_dev_{alloc,free,register,unregister}(). They have the same semantics as most other kernel subsystems.
*_alloc()allocates a new device and populates the static fields and sub-objects.*_free()frees an unregistered object allocated via*_alloc().*_register()registers a DRM device and*_unregister()obviously unregisters a DRM device. A*_free()is still needed after calling*_unregister()(same as for "struct device"). No ref-counting is added as it is not required by any driver.Note that the bus drivers are modified to use the new helpers directly. However, I didn't modify the drivers to use
*_unregister()and*_free()directly. Instead, thedrm_put_dev()helper was modified to use these. Reason for that is that I have pending patches to make device hotplugging safer regarding mmaps. But these aren't ready, yet. Hopefully I can get them ready for rc5 or rc6.
Quoted 5 lines
Quoted 2 lines
Tested on nouveau.
Okay I've merged this series, a follow-on to fix the AGP bits like Daniel suggested would be good.
Actually this oopses i915 on startup, I fixed up the lack of passing flags into drm_dev_register,
so it can be passed to load, and it seems to work now, I've squashed my fix into the series in my tree
please read/review the series for your learning pleasure.
Dave.
Quoted 28 lines · Dave Airlie
Quoted 21 lines · Dave Airlie
Quoted 20 lines · David Herrmann
Hi
This cleans up the bus drivers in DRM. Instead of copying the device alloc/free semantics into each bus driver (drm_{pci,platform,usb}.c) we now have a central place in
drm_stub.c.This introduces drm_dev_{alloc,free,register,unregister}(). They have the same semantics as most other kernel subsystems.
*_alloc()allocates a new device and populates the static fields and sub-objects.*_free()frees an unregistered object allocated via*_alloc().*_register()registers a DRM device and*_unregister()obviously unregisters a DRM device. A*_free()is still needed after calling*_unregister()(same as for "struct device"). No ref-counting is added as it is not required by any driver.Note that the bus drivers are modified to use the new helpers directly. However, I didn't modify the drivers to use
*_unregister()and*_free()directly. Instead, thedrm_put_dev()helper was modified to use these. Reason for that is that I have pending patches to make device hotplugging safer regarding mmaps. But these aren't ready, yet. Hopefully I can get them ready for rc5 or rc6.Quoted 5 lines
Quoted 2 lines
Tested on nouveau.
Okay I've merged this series, a follow-on to fix the AGP bits like Daniel suggested would be good.
Quoted 6 lines
Actually this oopses i915 on startup, I fixed up the lack of passing flags into
drm_dev_register,
so it can be passed to load, and it seems to work now, I've squashed my fix into the series in my treeplease read/review the series for your learning pleasure.
Oops, shame on me for failing to spot the unconditional 0 passed for flags. i915.ko really doesn't like that ;-)
-Daniel
Signature · 3 lines
Daniel Vetter Software Engineer, Intel Corporation +41 (0) 79 365 57 48 - http://blog.ffwll.ch