diff options
| author | Dave Airlie <airlied@redhat.com> | 2014-03-16 22:29:29 -0400 |
|---|---|---|
| committer | Dave Airlie <airlied@redhat.com> | 2014-03-16 22:29:29 -0400 |
| commit | e40d641099213145a034981e646dc2180a488152 (patch) | |
| tree | 49b892d13877e2ff7bc6cf1875bfc190500d4437 | |
| parent | 28b90a9e7fda90846b5257d7dce6311997c930f1 (diff) | |
| parent | 0d639883ee26359e1bf38195df1dbca0f879e239 (diff) | |
Merge branch 'drm-minor' of git://people.freedesktop.org/~dvdhrm/linux into drm-next
This series contains several cleanups for the DRM-minor handling. All but the
last one reviewed by Daniel and tested by Thierry. Initially, the series
included patches to convert minor-handling to a common base-ID, but have
been NACKed by Daniel so I dropped them and only included the main part in the
last patch. With this in place, drm_global_mutex is no longer needed for
minor-handling (but still for device unregistration..).
There are some pending patches that try to remove the global mutex entirely, but
they need some more reviews and thus are not included.
* 'drm-minor' of git://people.freedesktop.org/~dvdhrm/linux:
drm: make minors independent of global lock
drm: inline drm_minor_get_id()
drm: coding-style fixes in minor handling
drm: remove redundant minor->device field
drm: remove unneeded #ifdef CONFIG_DEBUGFS
drm: rename drm_unplug/get_minor() to drm_minor_register/unregister()
drm: move drm_put_minor() to drm_minor_free()
drm: allocate minors early
drm: add minor-lookup/release helpers
drm: provide device-refcount
drm: turn DRM_MINOR_* into enum
drm: remove unused DRM_MINOR_UNASSIGNED
drm: skip redundant minor-lookup in open path
drm: group dev-lifetime related members
| -rw-r--r-- | drivers/gpu/drm/drm_drv.c | 4 | ||||
| -rw-r--r-- | drivers/gpu/drm/drm_fops.c | 70 | ||||
| -rw-r--r-- | drivers/gpu/drm/drm_pci.c | 2 | ||||
| -rw-r--r-- | drivers/gpu/drm/drm_platform.c | 2 | ||||
| -rw-r--r-- | drivers/gpu/drm/drm_stub.c | 348 | ||||
| -rw-r--r-- | drivers/gpu/drm/drm_usb.c | 2 | ||||
| -rw-r--r-- | drivers/gpu/drm/tegra/bus.c | 2 | ||||
| -rw-r--r-- | include/drm/drmP.h | 41 |
8 files changed, 278 insertions, 193 deletions
diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c index 345be03c23db..ec651be2f3cb 100644 --- a/drivers/gpu/drm/drm_drv.c +++ b/drivers/gpu/drm/drm_drv.c | |||
| @@ -344,7 +344,7 @@ long drm_ioctl(struct file *filp, | |||
| 344 | 344 | ||
| 345 | DRM_DEBUG("pid=%d, dev=0x%lx, auth=%d, %s\n", | 345 | DRM_DEBUG("pid=%d, dev=0x%lx, auth=%d, %s\n", |
| 346 | task_pid_nr(current), | 346 | task_pid_nr(current), |
| 347 | (long)old_encode_dev(file_priv->minor->device), | 347 | (long)old_encode_dev(file_priv->minor->kdev->devt), |
| 348 | file_priv->authenticated, ioctl->name); | 348 | file_priv->authenticated, ioctl->name); |
| 349 | 349 | ||
| 350 | /* Do not trust userspace, use our own definition */ | 350 | /* Do not trust userspace, use our own definition */ |
| @@ -402,7 +402,7 @@ long drm_ioctl(struct file *filp, | |||
| 402 | if (!ioctl) | 402 | if (!ioctl) |
| 403 | DRM_DEBUG("invalid ioctl: pid=%d, dev=0x%lx, auth=%d, cmd=0x%02x, nr=0x%02x\n", | 403 | DRM_DEBUG("invalid ioctl: pid=%d, dev=0x%lx, auth=%d, cmd=0x%02x, nr=0x%02x\n", |
| 404 | task_pid_nr(current), | 404 | task_pid_nr(current), |
| 405 | (long)old_encode_dev(file_priv->minor->device), | 405 | (long)old_encode_dev(file_priv->minor->kdev->devt), |
| 406 | file_priv->authenticated, cmd, nr); | 406 | file_priv->authenticated, cmd, nr); |
| 407 | 407 | ||
| 408 | if (kdata != stack_kdata) | 408 | if (kdata != stack_kdata) |
diff --git a/drivers/gpu/drm/drm_fops.c b/drivers/gpu/drm/drm_fops.c index 7f2af9aca038..8f46fe273ba3 100644 --- a/drivers/gpu/drm/drm_fops.c +++ b/drivers/gpu/drm/drm_fops.c | |||
| @@ -39,12 +39,12 @@ | |||
| 39 | #include <linux/slab.h> | 39 | #include <linux/slab.h> |
| 40 | #include <linux/module.h> | 40 | #include <linux/module.h> |
| 41 | 41 | ||
| 42 | /* from BKL pushdown: note that nothing else serializes idr_find() */ | 42 | /* from BKL pushdown */ |
| 43 | DEFINE_MUTEX(drm_global_mutex); | 43 | DEFINE_MUTEX(drm_global_mutex); |
| 44 | EXPORT_SYMBOL(drm_global_mutex); | 44 | EXPORT_SYMBOL(drm_global_mutex); |
| 45 | 45 | ||
| 46 | static int drm_open_helper(struct inode *inode, struct file *filp, | 46 | static int drm_open_helper(struct inode *inode, struct file *filp, |
| 47 | struct drm_device * dev); | 47 | struct drm_minor *minor); |
| 48 | 48 | ||
| 49 | static int drm_setup(struct drm_device * dev) | 49 | static int drm_setup(struct drm_device * dev) |
| 50 | { | 50 | { |
| @@ -79,24 +79,18 @@ static int drm_setup(struct drm_device * dev) | |||
| 79 | */ | 79 | */ |
| 80 | int drm_open(struct inode *inode, struct file *filp) | 80 | int drm_open(struct inode *inode, struct file *filp) |
| 81 | { | 81 | { |
| 82 | struct drm_device *dev = NULL; | 82 | struct drm_device *dev; |
| 83 | int minor_id = iminor(inode); | ||
| 84 | struct drm_minor *minor; | 83 | struct drm_minor *minor; |
| 85 | int retcode = 0; | 84 | int retcode; |
| 86 | int need_setup = 0; | 85 | int need_setup = 0; |
| 87 | struct address_space *old_mapping; | 86 | struct address_space *old_mapping; |
| 88 | struct address_space *old_imapping; | 87 | struct address_space *old_imapping; |
| 89 | 88 | ||
| 90 | minor = idr_find(&drm_minors_idr, minor_id); | 89 | minor = drm_minor_acquire(iminor(inode)); |
| 91 | if (!minor) | 90 | if (IS_ERR(minor)) |
| 92 | return -ENODEV; | 91 | return PTR_ERR(minor); |
| 93 | |||
| 94 | if (!(dev = minor->dev)) | ||
| 95 | return -ENODEV; | ||
| 96 | |||
| 97 | if (drm_device_is_unplugged(dev)) | ||
| 98 | return -ENODEV; | ||
| 99 | 92 | ||
| 93 | dev = minor->dev; | ||
| 100 | if (!dev->open_count++) | 94 | if (!dev->open_count++) |
| 101 | need_setup = 1; | 95 | need_setup = 1; |
| 102 | mutex_lock(&dev->struct_mutex); | 96 | mutex_lock(&dev->struct_mutex); |
| @@ -110,7 +104,7 @@ int drm_open(struct inode *inode, struct file *filp) | |||
| 110 | filp->f_mapping = dev->dev_mapping; | 104 | filp->f_mapping = dev->dev_mapping; |
| 111 | mutex_unlock(&dev->struct_mutex); | 105 | mutex_unlock(&dev->struct_mutex); |
| 112 | 106 | ||
| 113 | retcode = drm_open_helper(inode, filp, dev); | 107 | retcode = drm_open_helper(inode, filp, minor); |
| 114 | if (retcode) | 108 | if (retcode) |
| 115 | goto err_undo; | 109 | goto err_undo; |
| 116 | if (need_setup) { | 110 | if (need_setup) { |
| @@ -128,6 +122,7 @@ err_undo: | |||
| 128 | dev->dev_mapping = old_mapping; | 122 | dev->dev_mapping = old_mapping; |
| 129 | mutex_unlock(&dev->struct_mutex); | 123 | mutex_unlock(&dev->struct_mutex); |
| 130 | dev->open_count--; | 124 | dev->open_count--; |
| 125 | drm_minor_release(minor); | ||
| 131 | return retcode; | 126 | return retcode; |
| 132 | } | 127 | } |
| 133 | EXPORT_SYMBOL(drm_open); | 128 | EXPORT_SYMBOL(drm_open); |
| @@ -143,33 +138,30 @@ EXPORT_SYMBOL(drm_open); | |||
| 143 | */ | 138 | */ |
| 144 | int drm_stub_open(struct inode *inode, struct file *filp) | 139 | int drm_stub_open(struct inode *inode, struct file *filp) |
| 145 | { | 140 | { |
| 146 | struct drm_device *dev = NULL; | 141 | struct drm_device *dev; |
| 147 | struct drm_minor *minor; | 142 | struct drm_minor *minor; |
| 148 | int minor_id = iminor(inode); | ||
| 149 | int err = -ENODEV; | 143 | int err = -ENODEV; |
| 150 | const struct file_operations *new_fops; | 144 | const struct file_operations *new_fops; |
| 151 | 145 | ||
| 152 | DRM_DEBUG("\n"); | 146 | DRM_DEBUG("\n"); |
| 153 | 147 | ||
| 154 | mutex_lock(&drm_global_mutex); | 148 | mutex_lock(&drm_global_mutex); |
| 155 | minor = idr_find(&drm_minors_idr, minor_id); | 149 | minor = drm_minor_acquire(iminor(inode)); |
| 156 | if (!minor) | 150 | if (IS_ERR(minor)) |
| 157 | goto out; | 151 | goto out_unlock; |
| 158 | |||
| 159 | if (!(dev = minor->dev)) | ||
| 160 | goto out; | ||
| 161 | |||
| 162 | if (drm_device_is_unplugged(dev)) | ||
| 163 | goto out; | ||
| 164 | 152 | ||
| 153 | dev = minor->dev; | ||
| 165 | new_fops = fops_get(dev->driver->fops); | 154 | new_fops = fops_get(dev->driver->fops); |
| 166 | if (!new_fops) | 155 | if (!new_fops) |
| 167 | goto out; | 156 | goto out_release; |
| 168 | 157 | ||
| 169 | replace_fops(filp, new_fops); | 158 | replace_fops(filp, new_fops); |
| 170 | if (filp->f_op->open) | 159 | if (filp->f_op->open) |
| 171 | err = filp->f_op->open(inode, filp); | 160 | err = filp->f_op->open(inode, filp); |
| 172 | out: | 161 | |
| 162 | out_release: | ||
| 163 | drm_minor_release(minor); | ||
| 164 | out_unlock: | ||
| 173 | mutex_unlock(&drm_global_mutex); | 165 | mutex_unlock(&drm_global_mutex); |
| 174 | return err; | 166 | return err; |
| 175 | } | 167 | } |
| @@ -196,16 +188,16 @@ static int drm_cpu_valid(void) | |||
| 196 | * | 188 | * |
| 197 | * \param inode device inode. | 189 | * \param inode device inode. |
| 198 | * \param filp file pointer. | 190 | * \param filp file pointer. |
| 199 | * \param dev device. | 191 | * \param minor acquired minor-object. |
| 200 | * \return zero on success or a negative number on failure. | 192 | * \return zero on success or a negative number on failure. |
| 201 | * | 193 | * |
| 202 | * Creates and initializes a drm_file structure for the file private data in \p | 194 | * Creates and initializes a drm_file structure for the file private data in \p |
| 203 | * filp and add it into the double linked list in \p dev. | 195 | * filp and add it into the double linked list in \p dev. |
| 204 | */ | 196 | */ |
| 205 | static int drm_open_helper(struct inode *inode, struct file *filp, | 197 | static int drm_open_helper(struct inode *inode, struct file *filp, |
| 206 | struct drm_device * dev) | 198 | struct drm_minor *minor) |
| 207 | { | 199 | { |
| 208 | int minor_id = iminor(inode); | 200 | struct drm_device *dev = minor->dev; |
| 209 | struct drm_file *priv; | 201 | struct drm_file *priv; |
| 210 | int ret; | ||
