drm/i915: Update to Linux 4.6
[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 int 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_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         return 0;
319 }
320
321 /**
322  * drm_release - release method for DRM file
323  * @inode: device inode
324  * @filp: file pointer.
325  *
326  * This function must be used by drivers as their .release() #file_operations
327  * method. It frees any resources associated with the open file, and if this is
328  * the last open file for the DRM device also proceeds to call drm_lastclose().
329  *
330  * RETURNS:
331  *
332  * Always succeeds and returns 0.
333  */
334 int drm_release(device_t kdev)
335 {
336         struct drm_device *dev = device_get_softc(kdev);
337         struct drm_magic_entry *pt, *next;
338         int i;
339
340         mutex_lock(&drm_global_mutex);
341
342         /* Clear pid list */
343         if (dev->magicfree.next) {
344                 list_for_each_entry_safe(pt, next, &dev->magicfree, head) {
345                         list_del(&pt->head);
346                         drm_ht_remove_item(&dev->magiclist, &pt->hash_item);
347                         kfree(pt);
348                 }
349                 drm_ht_remove(&dev->magiclist);
350         }
351
352         /* ========================================================
353          * Begin inline drm_release
354          */
355
356         DRM_DEBUG("\n");
357
358         drm_sysctl_cleanup(dev);
359         if (dev->devnode != NULL)
360                 destroy_dev(dev->devnode);
361
362         if (drm_core_check_feature(dev, DRIVER_GEM))
363                 drm_gem_destroy(dev);
364
365         drm_vblank_cleanup(dev);
366
367         DRM_LOCK(dev);
368         drm_lastclose(dev);
369         DRM_UNLOCK(dev);
370
371         /* Clean up PCI resources allocated by drm_bufs.c.  We're not really
372          * worried about resource consumption while the DRM is inactive (between
373          * lastclose and firstopen or unload) because these aren't actually
374          * taking up KVA, just keeping the PCI resource allocated.
375          */
376         for (i = 0; i < DRM_MAX_PCI_RESOURCE; i++) {
377                 if (dev->pcir[i] == NULL)
378                         continue;
379                 bus_release_resource(dev->dev->bsddev, SYS_RES_MEMORY,
380                     dev->pcirid[i], dev->pcir[i]);
381                 dev->pcir[i] = NULL;
382         }
383
384         if (dev->agp) {
385                 kfree(dev->agp);
386                 dev->agp = NULL;
387         }
388
389         if (dev->driver->unload != NULL) {
390                 DRM_LOCK(dev);
391                 dev->driver->unload(dev);
392                 DRM_UNLOCK(dev);
393         }
394
395         if (pci_disable_busmaster(dev->dev->bsddev))
396                 DRM_ERROR("Request to disable bus-master failed.\n");
397
398         lockuninit(&dev->vbl_lock);
399         lockuninit(&dev->dev_lock);
400         lockuninit(&dev->event_lock);
401         lockuninit(&dev->struct_mutex);
402
403         /* ========================================================
404          * End inline drm_release
405          */
406
407         if (dev->irqr) {
408                 bus_release_resource(dev->dev->bsddev, SYS_RES_IRQ, dev->irqrid,
409                     dev->irqr);
410                 if (dev->irq_type == PCI_INTR_TYPE_MSI) {
411                         pci_release_msi(dev->dev->bsddev);
412                         DRM_INFO("MSI released\n");
413                 }
414         }
415
416         mutex_unlock(&drm_global_mutex);
417
418         return (0);
419 }
420 EXPORT_SYMBOL(drm_release);
421
422 static bool
423 drm_dequeue_event(struct drm_device *dev, struct drm_file *file_priv,
424     struct uio *uio, struct drm_pending_event **out)
425 {
426         struct drm_pending_event *e;
427         bool ret = false;
428
429         lockmgr(&dev->event_lock, LK_EXCLUSIVE);
430
431         *out = NULL;
432         if (list_empty(&file_priv->event_list))
433                 goto out;
434         e = list_first_entry(&file_priv->event_list,
435             struct drm_pending_event, link);
436         if (e->event->length > uio->uio_resid)
437                 goto out;
438
439         file_priv->event_space += e->event->length;
440         list_del(&e->link);
441         *out = e;
442         ret = true;
443
444 out:
445         lockmgr(&dev->event_lock, LK_RELEASE);
446         return ret;
447 }
448
449 /**
450  * drm_read - read method for DRM file
451  * @filp: file pointer
452  * @buffer: userspace destination pointer for the read
453  * @count: count in bytes to read
454  * @offset: offset to read
455  *
456  * This function must be used by drivers as their .read() #file_operations
457  * method iff they use DRM events for asynchronous signalling to userspace.
458  * Since events are used by the KMS API for vblank and page flip completion this
459  * means all modern display drivers must use it.
460  *
461  * @offset is ignore, DRM events are read like a pipe. Therefore drivers also
462  * must set the .llseek() #file_operation to no_llseek(). Polling support is
463  * provided by drm_poll().
464  *
465  * This function will only ever read a full event. Therefore userspace must
466  * supply a big enough buffer to fit any event to ensure forward progress. Since
467  * the maximum event space is currently 4K it's recommended to just use that for
468  * safety.
469  *
470  * RETURNS:
471  *
472  * Number of bytes read (always aligned to full events, and can be 0) or a
473  * negative error code on failure.
474  */
475 int drm_read(struct dev_read_args *ap)
476 {
477         struct cdev *kdev = ap->a_head.a_dev;
478         struct uio *uio = ap->a_uio;
479         struct drm_file *file_priv;
480         struct drm_device *dev = drm_get_device_from_kdev(kdev);
481         struct drm_pending_event *e;
482         int error;
483         int ret;
484
485         error = devfs_get_cdevpriv(ap->a_fp, (void **)&file_priv);
486         if (error != 0) {
487                 DRM_ERROR("can't find authenticator\n");
488                 return (EINVAL);
489         }
490
491         ret = wait_event_interruptible(file_priv->event_wait,
492                                        !list_empty(&file_priv->event_list));
493         if (ret == -ERESTARTSYS)
494                 ret = -EINTR;
495         if (ret < 0)
496                 return -ret;
497
498         while (drm_dequeue_event(dev, file_priv, uio, &e)) {
499                 error = uiomove((caddr_t)e->event, e->event->length, uio);
500                 e->destroy(e);
501                 if (error != 0)
502                         return (error);
503         }
504
505         return (error);
506 }
507
508 /**
509  * drm_poll - poll method for DRM file
510  * @filp: file pointer
511  * @wait: poll waiter table
512  *
513  * This function must be used by drivers as their .read() #file_operations
514  * method iff they use DRM events for asynchronous signalling to userspace.
515  * Since events are used by the KMS API for vblank and page flip completion this
516  * means all modern display drivers must use it.
517  *
518  * See also drm_read().
519  *
520  * RETURNS:
521  *
522  * Mask of POLL flags indicating the current status of the file.
523  */
524
525 static int
526 drmfilt(struct knote *kn, long hint)
527 {
528         struct drm_file *file_priv;
529         struct drm_device *dev;
530         int ready = 0;
531
532         file_priv = (struct drm_file *)kn->kn_hook;
533         dev = file_priv->dev;
534         lockmgr(&dev->event_lock, LK_EXCLUSIVE);
535         if (!list_empty(&file_priv->event_list))
536                 ready = 1;
537         lockmgr(&dev->event_lock, LK_RELEASE);
538
539         return (ready);
540 }
541
542 static void
543 drmfilt_detach(struct knote *kn)
544 {
545         struct drm_file *file_priv;
546         struct drm_device *dev;
547         struct klist *klist;
548
549         file_priv = (struct drm_file *)kn->kn_hook;
550         dev = file_priv->dev;
551
552         klist = &file_priv->dkq.ki_note;
553         knote_remove(klist, kn);
554 }
555
556 static struct filterops drmfiltops =
557         { FILTEROP_MPSAFE | FILTEROP_ISFD, NULL, drmfilt_detach, drmfilt };
558
559 int
560 drm_kqfilter(struct dev_kqfilter_args *ap)
561 {
562         struct cdev *kdev = ap->a_head.a_dev;
563         struct drm_file *file_priv;
564         struct drm_device *dev;
565         struct knote *kn = ap->a_kn;
566         struct klist *klist;
567         int error;
568
569         error = devfs_get_cdevpriv(ap->a_fp, (void **)&file_priv);
570         if (error != 0) {
571                 DRM_ERROR("can't find authenticator\n");
572                 return (EINVAL);
573         }
574         dev = drm_get_device_from_kdev(kdev);
575
576         ap->a_result = 0;
577
578         switch (kn->kn_filter) {
579         case EVFILT_READ:
580         case EVFILT_WRITE:
581                 kn->kn_fop = &drmfiltops;
582                 kn->kn_hook = (caddr_t)file_priv;
583                 break;
584         default:
585                 ap->a_result = EOPNOTSUPP;
586                 return (0);
587         }
588
589         klist = &file_priv->dkq.ki_note;
590         knote_insert(klist, kn);
591
592         return (0);
593 }
594
595 #ifdef __DragonFly__
596 /*
597  * The Linux layer version of kfree() is a macro and can't be called
598  * directly via a function pointer
599  */
600 static void
601 drm_event_destroy(struct drm_pending_event *e)
602 {
603         kfree(e);
604 }
605 #endif
606
607 /**
608  * drm_event_reserve_init_locked - init a DRM event and reserve space for it
609  * @dev: DRM device
610  * @file_priv: DRM file private data
611  * @p: tracking structure for the pending event
612  * @e: actual event data to deliver to userspace
613  *
614  * This function prepares the passed in event for eventual delivery. If the event
615  * doesn't get delivered (because the IOCTL fails later on, before queuing up
616  * anything) then the even must be cancelled and freed using
617  * drm_event_cancel_free(). Successfully initialized events should be sent out
618  * using drm_send_event() or drm_send_event_locked() to signal completion of the
619  * asynchronous event to userspace.
620  *
621  * If callers embedded @p into a larger structure it must be allocated with
622  * kmalloc and @p must be the first member element.
623  *
624  * This is the locked version of drm_event_reserve_init() for callers which
625  * already hold dev->event_lock.
626  *
627  * RETURNS:
628  *
629  * 0 on success or a negative error code on failure.
630  */
631 int drm_event_reserve_init_locked(struct drm_device *dev,
632                                   struct drm_file *file_priv,
633                                   struct drm_pending_event *p,
634                                   struct drm_event *e)
635 {
636         if (file_priv->event_space < e->length)
637                 return -ENOMEM;
638
639         file_priv->event_space -= e->length;
640
641         p->event = e;
642         p->file_priv = file_priv;
643
644         /* we *could* pass this in as arg, but everyone uses kfree: */
645 #ifdef __DragonFly__
646         p->destroy = drm_event_destroy;
647 #else
648         p->destroy = (void (*) (struct drm_pending_event *)) kfree;
649 #endif
650
651         return 0;
652 }
653 EXPORT_SYMBOL(drm_event_reserve_init_locked);
654
655 /**
656  * drm_event_reserve_init - init a DRM event and reserve space for it
657  * @dev: DRM device
658  * @file_priv: DRM file private data
659  * @p: tracking structure for the pending event
660  * @e: actual event data to deliver to userspace
661  *
662  * This function prepares the passed in event for eventual delivery. If the event
663  * doesn't get delivered (because the IOCTL fails later on, before queuing up
664  * anything) then the even must be cancelled and freed using
665  * drm_event_cancel_free(). Successfully initialized events should be sent out
666  * using drm_send_event() or drm_send_event_locked() to signal completion of the
667  * asynchronous event to userspace.
668  *
669  * If callers embedded @p into a larger structure it must be allocated with
670  * kmalloc and @p must be the first member element.
671  *
672  * Callers which already hold dev->event_lock should use
673  * drm_event_reserve_init() instead.
674  *
675  * RETURNS:
676  *
677  * 0 on success or a negative error code on failure.
678  */
679 int drm_event_reserve_init(struct drm_device *dev,
680                            struct drm_file *file_priv,
681                            struct drm_pending_event *p,
682                            struct drm_event *e)
683 {
684         unsigned long flags;
685         int ret;
686
687         spin_lock_irqsave(&dev->event_lock, flags);
688         ret = drm_event_reserve_init_locked(dev, file_priv, p, e);
689         spin_unlock_irqrestore(&dev->event_lock, flags);
690
691         return ret;
692 }
693 EXPORT_SYMBOL(drm_event_reserve_init);
694
695 /**
696  * drm_event_cancel_free - free a DRM event and release it's space
697  * @dev: DRM device
698  * @p: tracking structure for the pending event
699  *
700  * This function frees the event @p initialized with drm_event_reserve_init()
701  * and releases any allocated space.
702  */
703 void drm_event_cancel_free(struct drm_device *dev,
704                            struct drm_pending_event *p)
705 {
706         unsigned long flags;
707         spin_lock_irqsave(&dev->event_lock, flags);
708         p->file_priv->event_space += p->event->length;
709         spin_unlock_irqrestore(&dev->event_lock, flags);
710         p->destroy(p);
711 }
712 EXPORT_SYMBOL(drm_event_cancel_free);
713
714 /**
715  * drm_send_event_locked - send DRM event to file descriptor
716  * @dev: DRM device
717  * @e: DRM event to deliver
718  *
719  * This function sends the event @e, initialized with drm_event_reserve_init(),
720  * to its associated userspace DRM file. Callers must already hold
721  * dev->event_lock, see drm_send_event() for the unlocked version.
722  */
723 void drm_send_event_locked(struct drm_device *dev, struct drm_pending_event *e)
724 {
725         assert_spin_locked(&dev->event_lock);
726
727         list_add_tail(&e->link,
728                       &e->file_priv->event_list);
729         wake_up_interruptible(&e->file_priv->event_wait);
730 #ifdef __DragonFly__
731         KNOTE(&e->file_priv->dkq.ki_note, 0);
732 #endif
733
734 }
735 EXPORT_SYMBOL(drm_send_event_locked);
736
737 /**
738  * drm_send_event - send DRM event to file descriptor
739  * @dev: DRM device
740  * @e: DRM event to deliver
741  *
742  * This function sends the event @e, initialized with drm_event_reserve_init(),
743  * to its associated userspace DRM file. This function acquires dev->event_lock,
744  * see drm_send_event_locked() for callers which already hold this lock.
745  */
746 void drm_send_event(struct drm_device *dev, struct drm_pending_event *e)
747 {
748         unsigned long irqflags;
749
750         spin_lock_irqsave(&dev->event_lock, irqflags);
751         drm_send_event_locked(dev, e);
752         spin_unlock_irqrestore(&dev->event_lock, irqflags);
753 }
754 EXPORT_SYMBOL(drm_send_event);