Commit b209aca3 authored by Chris Wilson's avatar Chris Wilson Committed by Daniel Vetter

drm: Export drm_dev_init() for subclassing

In order to allow drivers to pack their privates and drm_device into one
struct (e.g. for subclassing), export the initialisation routines for
struct drm_device.

v2: Missed return ret. That error path had only one job to do!
v3: Cross-referencing drm_dev_init/drm_dev_alloc in kerneldoc, fix
missed error code for goto err_minors.
Signed-off-by: default avatarChris Wilson <chris@chris-wilson.co.uk>
Cc: Dave Airlie <airlied@redhat.com>
Cc: Daniel Vetter <daniel.vetter@ffwll.ch>
Cc: dri-devel@lists.freedesktop.org
Reviewed-by: default avatarDaniel Vetter <daniel.vetter@ffwll.ch>
Signed-off-by: default avatarDaniel Vetter <daniel.vetter@ffwll.ch>
Link: http://patchwork.freedesktop.org/patch/msgid/1465993109-19523-2-git-send-email-chris@chris-wilson.co.uk
parent 2a6ae85a
...@@ -441,11 +441,12 @@ static void drm_fs_inode_free(struct inode *inode) ...@@ -441,11 +441,12 @@ static void drm_fs_inode_free(struct inode *inode)
} }
/** /**
* drm_dev_alloc - Allocate new DRM device * drm_dev_init - Initialise new DRM device
* @driver: DRM driver to allocate device for * @dev: DRM device
* @driver: DRM driver
* @parent: Parent device object * @parent: Parent device object
* *
* Allocate and initialize a new DRM device. No device registration is done. * Initialize a new DRM device. No device registration is done.
* Call drm_dev_register() to advertice the device to user space and register it * Call drm_dev_register() to advertice the device to user space and register it
* with other core subsystems. This should be done last in the device * with other core subsystems. This should be done last in the device
* initialization sequence to make sure userspace can't access an inconsistent * initialization sequence to make sure userspace can't access an inconsistent
...@@ -456,19 +457,18 @@ static void drm_fs_inode_free(struct inode *inode) ...@@ -456,19 +457,18 @@ static void drm_fs_inode_free(struct inode *inode)
* *
* Note that for purely virtual devices @parent can be NULL. * Note that for purely virtual devices @parent can be NULL.
* *
* Drivers that do not want to allocate their own device struct
* embedding struct &drm_device can call drm_dev_alloc() instead.
*
* RETURNS: * RETURNS:
* Pointer to new DRM device, or NULL if out of memory. * 0 on success, or error code on failure.
*/ */
struct drm_device *drm_dev_alloc(struct drm_driver *driver, int drm_dev_init(struct drm_device *dev,
struct drm_driver *driver,
struct device *parent) struct device *parent)
{ {
struct drm_device *dev;
int ret; int ret;
dev = kzalloc(sizeof(*dev), GFP_KERNEL);
if (!dev)
return NULL;
kref_init(&dev->ref); kref_init(&dev->ref);
dev->dev = parent; dev->dev = parent;
dev->driver = driver; dev->driver = driver;
...@@ -509,7 +509,8 @@ struct drm_device *drm_dev_alloc(struct drm_driver *driver, ...@@ -509,7 +509,8 @@ struct drm_device *drm_dev_alloc(struct drm_driver *driver,
if (ret) if (ret)
goto err_minors; goto err_minors;
if (drm_ht_create(&dev->map_hash, 12)) ret = drm_ht_create(&dev->map_hash, 12);
if (ret)
goto err_minors; goto err_minors;
drm_legacy_ctxbitmap_init(dev); drm_legacy_ctxbitmap_init(dev);
...@@ -528,7 +529,7 @@ struct drm_device *drm_dev_alloc(struct drm_driver *driver, ...@@ -528,7 +529,7 @@ struct drm_device *drm_dev_alloc(struct drm_driver *driver,
goto err_setunique; goto err_setunique;
} }
return dev; return 0;
err_setunique: err_setunique:
if (drm_core_check_feature(dev, DRIVER_GEM)) if (drm_core_check_feature(dev, DRIVER_GEM))
...@@ -543,8 +544,49 @@ struct drm_device *drm_dev_alloc(struct drm_driver *driver, ...@@ -543,8 +544,49 @@ struct drm_device *drm_dev_alloc(struct drm_driver *driver,
drm_fs_inode_free(dev->anon_inode); drm_fs_inode_free(dev->anon_inode);
err_free: err_free:
mutex_destroy(&dev->master_mutex); mutex_destroy(&dev->master_mutex);
return ret;
}
EXPORT_SYMBOL(drm_dev_init);
/**
* drm_dev_alloc - Allocate new DRM device
* @driver: DRM driver to allocate device for
* @parent: Parent device object
*
* Allocate and initialize a new DRM device. No device registration is done.
* Call drm_dev_register() to advertice the device to user space and register it
* with other core subsystems. This should be done last in the device
* initialization sequence to make sure userspace can't access an inconsistent
* state.
*
* The initial ref-count of the object is 1. Use drm_dev_ref() and
* drm_dev_unref() to take and drop further ref-counts.
*
* Note that for purely virtual devices @parent can be NULL.
*
* Drivers that wish to subclass or embed struct &drm_device into their
* own struct should look at using drm_dev_init() instead.
*
* RETURNS:
* Pointer to new DRM device, or NULL if out of memory.
*/
struct drm_device *drm_dev_alloc(struct drm_driver *driver,
struct device *parent)
{
struct drm_device *dev;
int ret;
dev = kzalloc(sizeof(*dev), GFP_KERNEL);
if (!dev)
return NULL;
ret = drm_dev_init(dev, driver, parent);
if (ret) {
kfree(dev); kfree(dev);
return NULL; return NULL;
}
return dev;
} }
EXPORT_SYMBOL(drm_dev_alloc); EXPORT_SYMBOL(drm_dev_alloc);
......
...@@ -1072,6 +1072,9 @@ extern void drm_sysfs_hotplug_event(struct drm_device *dev); ...@@ -1072,6 +1072,9 @@ extern void drm_sysfs_hotplug_event(struct drm_device *dev);
struct drm_device *drm_dev_alloc(struct drm_driver *driver, struct drm_device *drm_dev_alloc(struct drm_driver *driver,
struct device *parent); struct device *parent);
int drm_dev_init(struct drm_device *dev,
struct drm_driver *driver,
struct device *parent);
void drm_dev_ref(struct drm_device *dev); void drm_dev_ref(struct drm_device *dev);
void drm_dev_unref(struct drm_device *dev); void drm_dev_unref(struct drm_device *dev);
int drm_dev_register(struct drm_device *dev, unsigned long flags); int drm_dev_register(struct drm_device *dev, unsigned long flags);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment