| .. | .. |
|---|
| 1 | | -/** |
|---|
| 1 | +/* |
|---|
| 2 | 2 | * \file drm_lock.c |
|---|
| 3 | 3 | * IOCTLs for locking |
|---|
| 4 | 4 | * |
|---|
| .. | .. |
|---|
| 36 | 36 | #include <linux/export.h> |
|---|
| 37 | 37 | #include <linux/sched/signal.h> |
|---|
| 38 | 38 | |
|---|
| 39 | | -#include <drm/drmP.h> |
|---|
| 40 | | -#include "drm_legacy.h" |
|---|
| 39 | +#include <drm/drm.h> |
|---|
| 40 | +#include <drm/drm_drv.h> |
|---|
| 41 | +#include <drm/drm_file.h> |
|---|
| 42 | +#include <drm/drm_print.h> |
|---|
| 43 | + |
|---|
| 41 | 44 | #include "drm_internal.h" |
|---|
| 45 | +#include "drm_legacy.h" |
|---|
| 42 | 46 | |
|---|
| 43 | 47 | static int drm_lock_take(struct drm_lock_data *lock_data, unsigned int context); |
|---|
| 44 | 48 | |
|---|
| 45 | | -/** |
|---|
| 49 | +/* |
|---|
| 46 | 50 | * Take the heavyweight lock. |
|---|
| 47 | 51 | * |
|---|
| 48 | 52 | * \param lock lock pointer. |
|---|
| .. | .. |
|---|
| 89 | 93 | return 0; |
|---|
| 90 | 94 | } |
|---|
| 91 | 95 | |
|---|
| 92 | | -/** |
|---|
| 96 | +/* |
|---|
| 93 | 97 | * This takes a lock forcibly and hands it to context. Should ONLY be used |
|---|
| 94 | 98 | * inside *_unlock to give lock to kernel before calling *_dma_schedule. |
|---|
| 95 | 99 | * |
|---|
| .. | .. |
|---|
| 146 | 150 | return 0; |
|---|
| 147 | 151 | } |
|---|
| 148 | 152 | |
|---|
| 149 | | -/** |
|---|
| 153 | +/* |
|---|
| 150 | 154 | * Lock ioctl. |
|---|
| 151 | 155 | * |
|---|
| 152 | 156 | * \param inode device inode. |
|---|
| .. | .. |
|---|
| 166 | 170 | int ret = 0; |
|---|
| 167 | 171 | |
|---|
| 168 | 172 | if (!drm_core_check_feature(dev, DRIVER_LEGACY)) |
|---|
| 169 | | - return -EINVAL; |
|---|
| 173 | + return -EOPNOTSUPP; |
|---|
| 170 | 174 | |
|---|
| 171 | 175 | ++file_priv->lock_count; |
|---|
| 172 | 176 | |
|---|
| .. | .. |
|---|
| 239 | 243 | return 0; |
|---|
| 240 | 244 | } |
|---|
| 241 | 245 | |
|---|
| 242 | | -/** |
|---|
| 246 | +/* |
|---|
| 243 | 247 | * Unlock ioctl. |
|---|
| 244 | 248 | * |
|---|
| 245 | 249 | * \param inode device inode. |
|---|
| .. | .. |
|---|
| 256 | 260 | struct drm_master *master = file_priv->master; |
|---|
| 257 | 261 | |
|---|
| 258 | 262 | if (!drm_core_check_feature(dev, DRIVER_LEGACY)) |
|---|
| 259 | | - return -EINVAL; |
|---|
| 263 | + return -EOPNOTSUPP; |
|---|
| 260 | 264 | |
|---|
| 261 | 265 | if (lock->context == DRM_KERNEL_CONTEXT) { |
|---|
| 262 | 266 | DRM_ERROR("Process %d using kernel context %d\n", |
|---|
| .. | .. |
|---|
| 271 | 275 | return 0; |
|---|
| 272 | 276 | } |
|---|
| 273 | 277 | |
|---|
| 274 | | -/** |
|---|
| 278 | +/* |
|---|
| 275 | 279 | * This function returns immediately and takes the hw lock |
|---|
| 276 | 280 | * with the kernel context if it is free, otherwise it gets the highest priority when and if |
|---|
| 277 | 281 | * it is eventually released. |
|---|
| .. | .. |
|---|
| 283 | 287 | * This should be sufficient to wait for GPU idle without |
|---|
| 284 | 288 | * having to worry about starvation. |
|---|
| 285 | 289 | */ |
|---|
| 286 | | - |
|---|
| 287 | 290 | void drm_legacy_idlelock_take(struct drm_lock_data *lock_data) |
|---|
| 288 | 291 | { |
|---|
| 289 | 292 | int ret; |
|---|
| .. | .. |
|---|
| 327 | 330 | struct drm_file *file_priv) |
|---|
| 328 | 331 | { |
|---|
| 329 | 332 | struct drm_master *master = file_priv->master; |
|---|
| 333 | + |
|---|
| 330 | 334 | return (file_priv->lock_count && master->lock.hw_lock && |
|---|
| 331 | 335 | _DRM_LOCK_IS_HELD(master->lock.hw_lock->lock) && |
|---|
| 332 | 336 | master->lock.file_priv == file_priv); |
|---|
| .. | .. |
|---|
| 347 | 351 | _DRM_LOCKING_CONTEXT(file_priv->master->lock.hw_lock->lock)); |
|---|
| 348 | 352 | } |
|---|
| 349 | 353 | } |
|---|
| 354 | + |
|---|
| 355 | +void drm_legacy_lock_master_cleanup(struct drm_device *dev, struct drm_master *master) |
|---|
| 356 | +{ |
|---|
| 357 | + if (!drm_core_check_feature(dev, DRIVER_LEGACY)) |
|---|
| 358 | + return; |
|---|
| 359 | + |
|---|
| 360 | + /* |
|---|
| 361 | + * Since the master is disappearing, so is the |
|---|
| 362 | + * possibility to lock. |
|---|
| 363 | + */ |
|---|
| 364 | + mutex_lock(&dev->struct_mutex); |
|---|
| 365 | + if (master->lock.hw_lock) { |
|---|
| 366 | + if (dev->sigdata.lock == master->lock.hw_lock) |
|---|
| 367 | + dev->sigdata.lock = NULL; |
|---|
| 368 | + master->lock.hw_lock = NULL; |
|---|
| 369 | + master->lock.file_priv = NULL; |
|---|
| 370 | + wake_up_interruptible_all(&master->lock.lock_queue); |
|---|
| 371 | + } |
|---|
| 372 | + mutex_unlock(&dev->struct_mutex); |
|---|
| 373 | +} |
|---|