mirror of
https://mirrors.bfsu.edu.cn/git/linux.git
synced 2024-12-18 08:35:08 +08:00
099d1c290e
Lets not trick ourselves into thinking "drm_device" objects are not ref-counted. That's just utterly stupid. We manage "drm_minor" objects on each drm-device and each minor can have an unlimited number of open handles. Each of these handles has the drm_minor (and thus the drm_device) as private-data in the file-handle. Therefore, we may not destroy "drm_device" until all these handles are closed. It is *not* possible to reset all these pointers atomically and restrict access to them, and this is *not* how this is done! Instead, we use ref-counts to make sure the object is valid and not freed. Note that we currently use "dev->open_count" for that, which is *exactly* the same as a reference-count, just open coded. So this patch doesn't change any semantics on DRM devices (well, this patch just introduces the ref-count, anyway. Follow-up patches will replace open_count by it). Also note that generic VFS revoke support could allow us to drop this ref-count again. We could then just synchronously disable any fops->xy() calls. However, this is not the case, yet, and no such patches are in sight (and I seriously question the idea of dropping the ref-cnt again). Signed-off-by: David Herrmann <dh.herrmann@gmail.com>
85 lines
1.6 KiB
C
85 lines
1.6 KiB
C
#include <drm/drmP.h>
|
|
#include <drm/drm_usb.h>
|
|
#include <linux/usb.h>
|
|
#include <linux/module.h>
|
|
|
|
int drm_get_usb_dev(struct usb_interface *interface,
|
|
const struct usb_device_id *id,
|
|
struct drm_driver *driver)
|
|
{
|
|
struct drm_device *dev;
|
|
int ret;
|
|
|
|
DRM_DEBUG("\n");
|
|
|
|
dev = drm_dev_alloc(driver, &interface->dev);
|
|
if (!dev)
|
|
return -ENOMEM;
|
|
|
|
dev->usbdev = interface_to_usbdev(interface);
|
|
usb_set_intfdata(interface, dev);
|
|
|
|
ret = drm_dev_register(dev, 0);
|
|
if (ret)
|
|
goto err_free;
|
|
|
|
DRM_INFO("Initialized %s %d.%d.%d %s on minor %d\n",
|
|
driver->name, driver->major, driver->minor, driver->patchlevel,
|
|
driver->date, dev->primary->index);
|
|
|
|
return 0;
|
|
|
|
err_free:
|
|
drm_dev_unref(dev);
|
|
return ret;
|
|
|
|
}
|
|
EXPORT_SYMBOL(drm_get_usb_dev);
|
|
|
|
static int drm_usb_get_irq(struct drm_device *dev)
|
|
{
|
|
return 0;
|
|
}
|
|
|
|
static const char *drm_usb_get_name(struct drm_device *dev)
|
|
{
|
|
return "USB";
|
|
}
|
|
|
|
static int drm_usb_set_busid(struct drm_device *dev,
|
|
struct drm_master *master)
|
|
{
|
|
return 0;
|
|
}
|
|
|
|
static struct drm_bus drm_usb_bus = {
|
|
.bus_type = DRIVER_BUS_USB,
|
|
.get_irq = drm_usb_get_irq,
|
|
.get_name = drm_usb_get_name,
|
|
.set_busid = drm_usb_set_busid,
|
|
};
|
|
|
|
int drm_usb_init(struct drm_driver *driver, struct usb_driver *udriver)
|
|
{
|
|
int res;
|
|
DRM_DEBUG("\n");
|
|
|
|
driver->kdriver.usb = udriver;
|
|
driver->bus = &drm_usb_bus;
|
|
|
|
res = usb_register(udriver);
|
|
return res;
|
|
}
|
|
EXPORT_SYMBOL(drm_usb_init);
|
|
|
|
void drm_usb_exit(struct drm_driver *driver,
|
|
struct usb_driver *udriver)
|
|
{
|
|
usb_deregister(udriver);
|
|
}
|
|
EXPORT_SYMBOL(drm_usb_exit);
|
|
|
|
MODULE_AUTHOR("David Airlie");
|
|
MODULE_DESCRIPTION("USB DRM support");
|
|
MODULE_LICENSE("GPL and additional rights");
|