drm/i915: Update to Linux 4.7.10
[dragonfly.git] / sys / dev / drm / drm_fops.c
1 /**
2  * \file drm_fops.c
3  * File operations for DRM
4  *
5  * \author Rickard E. (Rik) Faith <faith@valinux.com>
6  * \author Daryll Strauss <daryll@valinux.com>
7  * \author Gareth Hughes <gareth@valinux.com>
8  */
9
10 /*
11  * Created: Mon Jan  4 08:58:31 1999 by faith@valinux.com
12  *
13  * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
14  * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
15  * All Rights Reserved.
16  *
17  * Permission is hereby granted, free of charge, to any person obtaining a
18  * copy of this software and associated documentation files (the "Software"),
19  * to deal in the Software without restriction, including without limitation
20  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
21  * and/or sell copies of the Software, and to permit persons to whom the
22  * Software is furnished to do so, subject to the following conditions:
23  *
24  * The above copyright notice and this permission notice (including the next
25  * paragraph) shall be included in all copies or substantial portions of the
26  * Software.
27  *
28  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
29  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
30  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
31  * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
32  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
33  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
34  * OTHER DEALINGS IN THE SOFTWARE.
35  */
36
37 #include <sys/types.h>
38 #include <sys/conf.h>
39 #include <sys/devfs.h>
40
41 #include <drm/drmP.h>
42 #include <linux/module.h>
43 #include "drm_legacy.h"
44 #include "drm_internal.h"
45
46 /* from BKL pushdown */
47 DEFINE_MUTEX(drm_global_mutex);
48
49 /**
50  * DOC: file operations
51  *
52  * Drivers must define the file operations structure that forms the DRM
53  * userspace API entry point, even though most of those operations are
54  * implemented in the DRM core. The mandatory functions are drm_open(),
55  * drm_read(), drm_ioctl() and drm_compat_ioctl if CONFIG_COMPAT is enabled.
56  * Drivers which implement private ioctls that require 32/64 bit compatibility
57  * support must provided their onw .compat_ioctl() handler that processes
58  * private ioctls and calls drm_compat_ioctl() for core ioctls.
59  *
60  * In addition drm_read() and drm_poll() provide support for DRM events. DRM
61  * events are a generic and extensible means to send asynchronous events to
62  * userspace through the file descriptor. They are used to send vblank event and
63  * page flip completions by the KMS API. But drivers can also use it for their
64  * own needs, e.g. to signal completion of rendering.
65  *
66  * The memory mapping implementation will vary depending on how the driver
67  * manages memory. Legacy drivers will use the deprecated drm_legacy_mmap()
68  * function, modern drivers should use one of the provided memory-manager
69  * specific implementations. For GEM-based drivers this is drm_gem_mmap().
70  *
71  * No other file operations are supported by the DRM userspace API. Overall the
72  * following is an example #file_operations structure:
73  *
74  *     static const example_drm_fops = {
75  *             .owner = THIS_MODULE,
76  *             .open = drm_open,
77  *             .release = drm_release,
78  *             .unlocked_ioctl = drm_ioctl,
79  *     #ifdef CONFIG_COMPAT
80  *             .compat_ioctl = drm_compat_ioctl,
81  *     #endif
82  *             .poll = drm_poll,
83  *             .read = drm_read,
84  *             .llseek = no_llseek,
85  *             .mmap = drm_gem_mmap,
86  *     };
87  */
88
89 extern drm_pci_id_list_t *drm_find_description(int vendor, int device,
90     drm_pci_id_list_t *idlist);
91 extern devclass_t drm_devclass;
92
93 static int drm_setup(struct drm_device *dev)
94 {
95         drm_local_map_t *map;
96         int i;
97
98         DRM_LOCK_ASSERT(dev);
99
100         /* prebuild the SAREA */
101         i = drm_legacy_addmap(dev, 0, SAREA_MAX, _DRM_SHM,
102             _DRM_CONTAINS_LOCK, &map);
103         if (i != 0)
104                 return i;
105
106         if (dev->driver->firstopen)
107                 dev->driver->firstopen(dev);
108
109         dev->buf_use = 0;
110
111         if (drm_core_check_feature(dev, DRIVER_HAVE_DMA)) {
112                 i = drm_legacy_dma_setup(dev);
113                 if (i != 0)
114                         return i;
115         }
116
117         drm_ht_create(&dev->magiclist, DRM_MAGIC_HASH_ORDER);
118         INIT_LIST_HEAD(&dev->magicfree);
119
120         init_waitqueue_head(&dev->lock.lock_queue);
121         if (!drm_core_check_feature(dev, DRIVER_MODESET))
122                 dev->irq_enabled = 0;
123         dev->context_flag = 0;
124         dev->last_context = 0;
125         dev->if_version = 0;
126
127         dev->buf_sigio = NULL;
128
129         DRM_DEBUG("\n");
130
131         return 0;
132 }
133
134 #define DRIVER_SOFTC(unit) \
135         ((struct drm_device *)devclass_get_softc(drm_devclass, unit))
136
137 /**
138  * drm_open - open method for DRM file
139  * @inode: device inode
140  * @filp: file pointer.
141  *
142  * This function must be used by drivers as their .open() #file_operations
143  * method. It looks up the correct DRM device and instantiates all the per-file
144  * resources for it.
145  *
146  * RETURNS:
147  *
148  * 0 on success or negative errno value on falure.
149  */
150 int drm_open(struct dev_open_args *ap)
151 {
152         struct cdev *kdev = ap->a_head.a_dev;
153         int flags = ap->a_oflags;
154         int fmt = 0;
155         struct thread *p = curthread;
156         struct drm_device *dev;
157         int retcode;
158
159         dev = DRIVER_SOFTC(minor(kdev));
160         if (dev == NULL)
161                 return (ENXIO);
162
163         DRM_DEBUG("open_count = %d\n", dev->open_count);
164
165         retcode = drm_open_helper(kdev, flags, fmt, p, dev, ap->a_fp);
166
167         if (retcode == 0) {
168                 atomic_inc(&dev->counts[_DRM_STAT_OPENS]);
169                 DRM_LOCK(dev);
170                 device_busy(dev->dev->bsddev);
171                 if (!dev->open_count++)
172                         retcode = drm_setup(dev);
173                 DRM_UNLOCK(dev);
174         }
175
176         DRM_DEBUG("return %d\n", retcode);
177
178         return (retcode);
179 }
180 EXPORT_SYMBOL(drm_open);
181
182 /*
183  * Check whether DRI will run on this CPU.
184  *
185  * \return non-zero if the DRI will run on this CPU, or zero otherwise.
186  */
187
188 /*
189  * drm_new_set_master - Allocate a new master object and become master for the
190  * associated master realm.
191  *
192  * @dev: The associated device.
193  * @fpriv: File private identifying the client.
194  *
195  * This function must be called with dev::struct_mutex held.
196  * Returns negative error code on failure. Zero on success.
197  */
198
199 /*
200  * Called whenever a process opens /dev/drm.
201  *
202  * \param filp file pointer.
203  * \param minor acquired minor-object.
204  * \return zero on success or a negative number on failure.
205  *
206  * Creates and initializes a drm_file structure for the file private data in \p
207  * filp and add it into the double linked list in \p dev.
208  */
209 int drm_open_helper(struct cdev *kdev, int flags, int fmt, DRM_STRUCTPROC *p,
210                     struct drm_device *dev, struct file *fp)
211 {
212         struct drm_file *priv;
213         int retcode;
214
215         if (flags & O_EXCL)
216                 return EBUSY; /* No exclusive opens */
217         dev->flags = flags;
218
219         DRM_DEBUG("pid = %d, device = %s\n", DRM_CURRENTPID, devtoname(kdev));
220
221         priv = kmalloc(sizeof(*priv), M_DRM, M_WAITOK | M_NULLOK | M_ZERO);
222         if (priv == NULL) {
223                 return ENOMEM;
224         }
225         
226         DRM_LOCK(dev);
227         priv->dev               = dev;
228         priv->uid               = p->td_proc->p_ucred->cr_svuid;
229         priv->pid               = p->td_proc->p_pid;
230
231         /* for compatibility root is always authenticated */
232         priv->authenticated = capable(CAP_SYS_ADMIN);
233
234         INIT_LIST_HEAD(&priv->lhead);
235         INIT_LIST_HEAD(&priv->fbs);
236         lockinit(&priv->fbs_lock, "dpfl", 0, LK_CANRECURSE);
237         INIT_LIST_HEAD(&priv->blobs);
238         INIT_LIST_HEAD(&priv->pending_event_list);
239         INIT_LIST_HEAD(&priv->event_list);
240         init_waitqueue_head(&priv->event_wait);
241         priv->event_space = 4096; /* set aside 4k for event buffer */
242
243         if (drm_core_check_feature(dev, DRIVER_GEM))
244                 drm_gem_open(dev, priv);
245
246         if (dev->driver->open) {
247                 /* shared code returns -errno */
248                 retcode = -dev->driver->open(dev, priv);
249                 if (retcode != 0) {
250                         kfree(priv);
251                         DRM_UNLOCK(dev);
252                         return retcode;
253                 }
254         }
255
256         /* first opener automatically becomes master */
257         priv->master = list_empty(&dev->filelist);
258
259         list_add(&priv->lhead, &dev->filelist);
260         DRM_UNLOCK(dev);
261         kdev->si_drv1 = dev;
262
263         retcode = devfs_set_cdevpriv(fp, priv, &drm_cdevpriv_dtor);
264         if (retcode != 0)
265                 drm_cdevpriv_dtor(priv);
266
267         return retcode;
268 }
269
270 /*
271  * drm_legacy_dev_reinit
272  *
273  * Reinitializes a legacy/ums drm device in it's lastclose function.
274  */
275
276 /*
277  * Take down the DRM device.
278  *
279  * \param dev DRM device structure.
280  *
281  * Frees every resource in \p dev.
282  *
283  * \sa drm_device
284  */
285 void drm_lastclose(struct drm_device * dev)
286 {
287         DRM_DEBUG("\n");
288
289         if (dev->driver->lastclose)
290                 dev->driver->lastclose(dev);
291         DRM_DEBUG("driver lastclose completed\n");
292
293         if (dev->irq_enabled && !drm_core_check_feature(dev, DRIVER_MODESET))
294                 drm_irq_uninstall(dev);
295
296         mutex_lock(&dev->struct_mutex);
297
298         if (dev->unique) {
299                 kfree(dev->unique);
300                 dev->unique = NULL;
301                 dev->unique_len = 0;
302         }
303
304         drm_legacy_agp_clear(dev);
305
306         drm_legacy_sg_cleanup(dev);
307         drm_legacy_dma_takedown(dev);
308
309         if (dev->lock.hw_lock) {
310                 dev->lock.hw_lock = NULL; /* SHM removed */
311                 dev->lock.file_priv = NULL;
312                 wakeup(&dev->lock.lock_queue);
313         }
314
315         mutex_unlock(&dev->struct_mutex);
316
317         DRM_DEBUG("lastclose completed\n");
318 }
319
320 /**
321  * drm_release - release method for DRM file
322  * @inode: device inode
323  * @filp: file pointer.
324  *
325  * This function must be used by drivers as their .release() #file_operations
326  * method. It frees any resources associated with the open file, and if this is
327  * the last open file for the DRM device also proceeds to call drm_lastclose().
328  *
329  * RETURNS:
330  *
331  * Always succeeds and returns 0.
332  */
333 int drm_release(device_t kdev)
334 {
335         struct drm_device *dev = device_get_softc(kdev);
336         struct drm_magic_entry *pt, *next;
337         int i;
338
339         mutex_lock(&drm_global_mutex);
340
341         /* Clear pid list */
342         if (dev->magicfree.next) {
343                 list_for_each_entry_safe(pt, next, &dev->magicfree, head) {
344                         list_del(&pt->head);
345                         drm_ht_remove_item(&dev->magiclist, &pt->hash_item);
346                         kfree(pt);
347                 }
348                 drm_ht_remove(&dev->magiclist);
349         }
350
351         /* ========================================================
352          * Begin inline drm_release
353          */
354
355         DRM_DEBUG("\n");
356
357         drm_sysctl_cleanup(dev);
358         if (dev->devnode != NULL)
359                 destroy_dev(dev->devnode);
360
361         if (drm_core_check_feature(dev, DRIVER_GEM))
362                 drm_gem_destroy(dev);
363
364         drm_vblank_cleanup(dev);
365
366         DRM_LOCK(dev);
367         drm_lastclose(dev);
368         DRM_UNLOCK(dev);
369
370         /* Clean up PCI resources allocated by drm_bufs.c.  We're not really
371          * worried about resource consumption while the DRM is inactive (between
372          * lastclose and firstopen or unload) because these aren't actually
373          * taking up KVA, just keeping the PCI resource allocated.
374          */
375         for (i = 0; i < DRM_MAX_PCI_RESOURCE; i++) {
376                 if (dev->pcir[i] == NULL)
377                         continue;
378                 bus_release_resource(dev->dev->bsddev, SYS_RES_MEMORY,
379                     dev->pcirid[i], dev->pcir[i]);
380                 dev->pcir[i] = NULL;
381         }
382
383         if (dev->agp) {
384                 kfree(dev->agp);
385                 dev->agp = NULL;
386         }
387
388         if (dev->driver->unload != NULL) {
389                 DRM_LOCK(dev);
390                 dev->driver->unload(dev);
391                 DRM_UNLOCK(dev);
392         }
393
394         if (pci_disable_busmaster(dev->dev->bsddev))
395                 DRM_ERROR("Request to disable bus-master failed.\n");
396
397         lockuninit(&dev->vbl_lock);
398         lockuninit(&dev->dev_lock);
399         lockuninit(&dev->event_lock);
400         lockuninit(&dev->struct_mutex);
401
402         /* ========================================================
403          * End inline drm_release
404          */
405
406         if (dev->irqr) {
407                 bus_release_resource(dev->dev->bsddev, SYS_RES_IRQ, dev->irqrid,
408                     dev->irqr);
409                 if (dev->irq_type == PCI_INTR_TYPE_MSI) {
410                         pci_release_msi(dev->dev->bsddev);
411                         DRM_INFO("MSI released\n");
412                 }
413         }
414
415         mutex_unlock(&drm_global_mutex);
416
417         return (0);
418 }
419 EXPORT_SYMBOL(drm_release);
420
421 static bool
422 drm_dequeue_event(struct drm_device *dev, struct drm_file *file_priv,
423     struct uio *uio, struct drm_pending_event **out)
424 {
425         struct drm_pending_event *e;
426         bool ret = false;
427
428         lockmgr(&dev->event_lock, LK_EXCLUSIVE);
429
430         *out = NULL;
431         if (list_empty(&file_priv->event_list))
432                 goto out;
433         e = list_first_entry(&file_priv->event_list,
434             struct drm_pending_event, link);
435         if (e->event->length > uio->uio_resid)
436                 goto out;
437
438         file_priv->event_space += e->event->length;
439         list_del(&e->link);
440         *out = e;
441         ret = true;
442
443 out:
444         lockmgr(&dev->event_lock, LK_RELEASE);
445         return ret;
446 }
447
448 /**
449  * drm_read - read method for DRM file
450  * @filp: file pointer
451  * @buffer: userspace destination pointer for the read
452  * @count: count in bytes to read
453  * @offset: offset to read
454  *
455  * This function must be used by drivers as their .read() #file_operations
456  * method iff they use DRM events for asynchronous signalling to userspace.
457  * Since events are used by the KMS API for vblank and page flip completion this
458  * means all modern display drivers must use it.
459  *
460  * @offset is ignore, DRM events are read like a pipe. Therefore drivers also
461  * must set the .llseek() #file_operation to no_llseek(). Polling support is
462  * provided by drm_poll().
463  *
464  * This function will only ever read a full event. Therefore userspace must
465  * supply a big enough buffer to fit any event to ensure forward progress. Since
466  * the maximum event space is currently 4K it's recommended to just use that for
467  * safety.
468  *
469  * RETURNS:
470  *
471  * Number of bytes read (always aligned to full events, and can be 0) or a
472  * negative error code on failure.
473  */
474 int drm_read(struct dev_read_args *ap)
475 {
476         struct cdev *kdev = ap->a_head.a_dev;
477         struct uio *uio = ap->a_uio;
478         struct drm_file *file_priv;
479         struct drm_device *dev = drm_get_device_from_kdev(kdev);
480         struct drm_pending_event *e;
481         int error;
482         int ret;
483
484         error = devfs_get_cdevpriv(ap->a_fp, (void **)&file_priv);
485         if (error != 0) {
486                 DRM_ERROR("can't find authenticator\n");
487                 return (EINVAL);
488         }
489
490         ret = wait_event_interruptible(file_priv->event_wait,
491                                        !list_empty(&file_priv->event_list));
492         if (ret == -ERESTARTSYS)
493                 ret = -EINTR;
494         if (ret < 0)
495                 return -ret;
496
497         while (drm_dequeue_event(dev, file_priv, uio, &e)) {
498                 error = uiomove((caddr_t)e->event, e->event->length, uio);
499                 e->destroy(e);
500                 if (error != 0)
501                         return (error);
502         }
503
504         return (error);
505 }
506
507 /**
508  * drm_poll - poll method for DRM file
509  * @filp: file pointer
510  * @wait: poll waiter table
511  *
512  * This function must be used by drivers as their .read() #file_operations
513  * method iff they use DRM events for asynchronous signalling to userspace.
514  * Since events are used by the KMS API for vblank and page flip completion this
515  * means all modern display drivers must use it.
516  *
517  * See also drm_read().
518  *
519  * RETURNS:
520  *
521  * Mask of POLL flags indicating the current status of the file.
522  */
523
524 static int
525 drmfilt(struct knote *kn, long hint)
526 {
527         struct drm_file *file_priv;
528         struct drm_device *dev;
529         int ready = 0;
530
531         file_priv = (struct drm_file *)kn->kn_hook;
532         dev = file_priv->dev;
533         lockmgr(&dev->event_lock, LK_EXCLUSIVE);
534         if (!list_empty(&file_priv->event_list))
535                 ready = 1;
536         lockmgr(&dev->event_lock, LK_RELEASE);
537
538         return (ready);
539 }
540
541 static void
542 drmfilt_detach(struct knote *kn)
543 {
544         struct drm_file *file_priv;
545         struct drm_device *dev;
546         struct klist *klist;
547
548         file_priv = (struct drm_file *)kn->kn_hook;
549         dev = file_priv->dev;
550
551         klist = &file_priv->dkq.ki_note;
552         knote_remove(klist, kn);
553 }
554
555 static struct filterops drmfiltops =
556         { FILTEROP_MPSAFE | FILTEROP_ISFD, NULL, drmfilt_detach, drmfilt };
557
558 int
559 drm_kqfilter(struct dev_kqfilter_args *ap)
560 {
561         struct cdev *kdev = ap->a_head.a_dev;
562         struct drm_file *file_priv;
563         struct drm_device *dev;
564         struct knote *kn = ap->a_kn;
565         struct klist *klist;
566         int error;
567
568         error = devfs_get_cdevpriv(ap->a_fp, (void **)&file_priv);
569         if (error != 0) {
570                 DRM_ERROR("can't find authenticator\n");
571                 return (EINVAL);
572         }
573         dev = drm_get_device_from_kdev(kdev);
574
575         ap->a_result = 0;
576
577         switch (kn->kn_filter) {
578         case EVFILT_READ:
579         case EVFILT_WRITE:
580                 kn->kn_fop = &drmfiltops;
581                 kn->kn_hook = (caddr_t)file_priv;
582                 break;
583         default:
584                 ap->a_result = EOPNOTSUPP;
585                 return (0);
586         }
587
588         klist = &file_priv->dkq.ki_note;
589         knote_insert(klist, kn);
590
591         return (0);
592 }
593
594 #ifdef __DragonFly__
595 /*
596  * The Linux layer version of kfree() is a macro and can't be called
597  * directly via a function pointer
598  */
599 static void
600 drm_event_destroy(struct drm_pending_event *e)
601 {
602         kfree(e);
603 }
604 #endif
605
606 /**
607  * drm_event_reserve_init_locked - init a DRM event and reserve space for it
608  * @dev: DRM device
609  * @file_priv: DRM file private data
610  * @p: tracking structure for the pending event
611  * @e: actual event data to deliver to userspace
612  *
613  * This function prepares the passed in event for eventual delivery. If the event
614  * doesn't get delivered (because the IOCTL fails later on, before queuing up
615  * anything) then the even must be cancelled and freed using
616  * drm_event_cancel_free(). Successfully initialized events should be sent out
617  * using drm_send_event() or drm_send_event_locked() to signal completion of the
618  * asynchronous event to userspace.
619  *
620  * If callers embedded @p into a larger structure it must be allocated with
621  * kmalloc and @p must be the first member element.
622  *
623  * This is the locked version of drm_event_reserve_init() for callers which
624  * already hold dev->event_lock.
625  *
626  * RETURNS:
627  *
628  * 0 on success or a negative error code on failure.
629  */
630 int drm_event_reserve_init_locked(struct drm_device *dev,
631                                   struct drm_file *file_priv,
632                                   struct drm_pending_event *p,
633                                   struct drm_event *e)
634 {
635         if (file_priv->event_space < e->length)
636                 return -ENOMEM;
637
638         file_priv->event_space -= e->length;
639
640         p->event = e;
641         p->file_priv = file_priv;
642
643         /* we *could* pass this in as arg, but everyone uses kfree: */
644 #ifdef __DragonFly__
645         p->destroy = drm_event_destroy;
646 #else
647         p->destroy = (void (*) (struct drm_pending_event *)) kfree;
648 #endif
649
650         return 0;
651 }
652 EXPORT_SYMBOL(drm_event_reserve_init_locked);
653
654 /**
655  * drm_event_reserve_init - init a DRM event and reserve space for it
656  * @dev: DRM device
657  * @file_priv: DRM file private data
658  * @p: tracking structure for the pending event
659  * @e: actual event data to deliver to userspace
660  *
661  * This function prepares the passed in event for eventual delivery. If the event
662  * doesn't get delivered (because the IOCTL fails later on, before queuing up
663  * anything) then the even must be cancelled and freed using
664  * drm_event_cancel_free(). Successfully initialized events should be sent out
665  * using drm_send_event() or drm_send_event_locked() to signal completion of the
666  * asynchronous event to userspace.
667  *
668  * If callers embedded @p into a larger structure it must be allocated with
669  * kmalloc and @p must be the first member element.
670  *
671  * Callers which already hold dev->event_lock should use
672  * drm_event_reserve_init() instead.
673  *
674  * RETURNS:
675  *
676  * 0 on success or a negative error code on failure.
677  */
678 int drm_event_reserve_init(struct drm_device *dev,
679                            struct drm_file *file_priv,
680                            struct drm_pending_event *p,
681                            struct drm_event *e)
682 {
683         unsigned long flags;
684         int ret;
685
686         spin_lock_irqsave(&dev->event_lock, flags);
687         ret = drm_event_reserve_init_locked(dev, file_priv, p, e);
688         spin_unlock_irqrestore(&dev->event_lock, flags);
689
690         return ret;
691 }
692 EXPORT_SYMBOL(drm_event_reserve_init);
693
694 /**
695  * drm_event_cancel_free - free a DRM event and release it's space
696  * @dev: DRM device
697  * @p: tracking structure for the pending event
698  *
699  * This function frees the event @p initialized with drm_event_reserve_init()
700  * and releases any allocated space.
701  */
702 void drm_event_cancel_free(struct drm_device *dev,
703                            struct drm_pending_event *p)
704 {
705         unsigned long flags;
706         spin_lock_irqsave(&dev->event_lock, flags);
707         p->file_priv->event_space += p->event->length;
708         spin_unlock_irqrestore(&dev->event_lock, flags);
709         p->destroy(p);
710 }
711 EXPORT_SYMBOL(drm_event_cancel_free);
712
713 /**
714  * drm_send_event_locked - send DRM event to file descriptor
715  * @dev: DRM device
716  * @e: DRM event to deliver
717  *
718  * This function sends the event @e, initialized with drm_event_reserve_init(),
719  * to its associated userspace DRM file. Callers must already hold
720  * dev->event_lock, see drm_send_event() for the unlocked version.
721  */
722 void drm_send_event_locked(struct drm_device *dev, struct drm_pending_event *e)
723 {
724         assert_spin_locked(&dev->event_lock);
725
726         list_add_tail(&e->link,
727                       &e->file_priv->event_list);
728         wake_up_interruptible(&e->file_priv->event_wait);
729 #ifdef __DragonFly__
730         KNOTE(&e->file_priv->dkq.ki_note, 0);
731 #endif
732
733 }
734 EXPORT_SYMBOL(drm_send_event_locked);
735
736 /**
737  * drm_send_event - send DRM event to file descriptor
738  * @dev: DRM device
739  * @e: DRM event to deliver
740  *
741  * This function sends the event @e, initialized with drm_event_reserve_init(),
742  * to its associated userspace DRM file. This function acquires dev->event_lock,
743  * see drm_send_event_locked() for callers which already hold this lock.
744  */
745 void drm_send_event(struct drm_device *dev, struct drm_pending_event *e)
746 {
747         unsigned long irqflags;
748
749         spin_lock_irqsave(&dev->event_lock, irqflags);
750         drm_send_event_locked(dev, e);
751         spin_unlock_irqrestore(&dev->event_lock, irqflags);
752 }
753 EXPORT_SYMBOL(drm_send_event);