drm: disallow legacy dma ioctls for modesetting drivers
[deliverable/linux.git] / drivers / gpu / drm / drm_fops.c
CommitLineData
1da177e4 1/**
b5e89ed5 2 * \file drm_fops.c
1da177e4 3 * File operations for DRM
b5e89ed5 4 *
1da177e4
LT
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
760285e7 37#include <drm/drmP.h>
1da177e4 38#include <linux/poll.h>
5a0e3ad6 39#include <linux/slab.h>
e0cd3608 40#include <linux/module.h>
1da177e4 41
58374713
AB
42/* from BKL pushdown: note that nothing else serializes idr_find() */
43DEFINE_MUTEX(drm_global_mutex);
e3461a2b 44EXPORT_SYMBOL(drm_global_mutex);
58374713 45
b5e89ed5 46static int drm_open_helper(struct inode *inode, struct file *filp,
84b1fd10 47 struct drm_device * dev);
c94f7029 48
84b1fd10 49static int drm_setup(struct drm_device * dev)
1da177e4
LT
50{
51 int i;
52 int ret;
53
22eae947
DA
54 if (dev->driver->firstopen) {
55 ret = dev->driver->firstopen(dev);
b5e89ed5 56 if (ret != 0)
1da177e4
LT
57 return ret;
58 }
59
b5e89ed5
DA
60 atomic_set(&dev->ioctl_count, 0);
61 atomic_set(&dev->vma_count, 0);
1da177e4 62
e2e99a82
DV
63 i = drm_legacy_dma_setup(dev);
64 if (i < 0)
65 return i;
1da177e4 66
3d77461e 67 for (i = 0; i < ARRAY_SIZE(dev->counts); i++)
b5e89ed5 68 atomic_set(&dev->counts[i], 0);
1da177e4 69
11d9c2fd 70 dev->sigdata.lock = NULL;
7c1c2871 71
1da177e4 72 dev->context_flag = 0;
1da177e4 73 dev->last_context = 0;
1da177e4
LT
74 dev->if_version = 0;
75
1da177e4 76 dev->buf_async = NULL;
1da177e4 77
b5e89ed5 78 DRM_DEBUG("\n");
1da177e4
LT
79
80 /*
81 * The kernel's context could be created here, but is now created
b5e89ed5 82 * in drm_dma_enqueue. This is more resource-efficient for
1da177e4
LT
83 * hardware that does not do DMA, but may mean that
84 * drm_select_queue fails between the time the interrupt is
85 * initialized and the time the queues are initialized.
86 */
1da177e4
LT
87
88 return 0;
89}
90
91/**
92 * Open file.
b5e89ed5 93 *
1da177e4
LT
94 * \param inode device inode
95 * \param filp file pointer.
96 * \return zero on success or a negative number on failure.
97 *
98 * Searches the DRM device with the same minor number, calls open_helper(), and
99 * increments the device open count. If the open count was previous at zero,
100 * i.e., it's the first that the device is open, then calls setup().
101 */
b5e89ed5 102int drm_open(struct inode *inode, struct file *filp)
1da177e4 103{
84b1fd10 104 struct drm_device *dev = NULL;
2c14f28b
DA
105 int minor_id = iminor(inode);
106 struct drm_minor *minor;
1da177e4 107 int retcode = 0;
fdb40a08
IH
108 int need_setup = 0;
109 struct address_space *old_mapping;
a8ec3a66 110 struct address_space *old_imapping;
1da177e4 111
2c14f28b
DA
112 minor = idr_find(&drm_minors_idr, minor_id);
113 if (!minor)
1da177e4 114 return -ENODEV;
b5e89ed5 115
2c14f28b 116 if (!(dev = minor->dev))
1da177e4 117 return -ENODEV;
b5e89ed5 118
2c07a21d
DA
119 if (drm_device_is_unplugged(dev))
120 return -ENODEV;
121
fdb40a08
IH
122 if (!dev->open_count++)
123 need_setup = 1;
124 mutex_lock(&dev->struct_mutex);
a8ec3a66 125 old_imapping = inode->i_mapping;
fdb40a08
IH
126 old_mapping = dev->dev_mapping;
127 if (old_mapping == NULL)
128 dev->dev_mapping = &inode->i_data;
129 /* ihold ensures nobody can remove inode with our i_data */
130 ihold(container_of(dev->dev_mapping, struct inode, i_data));
131 inode->i_mapping = dev->dev_mapping;
132 filp->f_mapping = dev->dev_mapping;
133 mutex_unlock(&dev->struct_mutex);
134
b5e89ed5 135 retcode = drm_open_helper(inode, filp, dev);
fdb40a08
IH
136 if (retcode)
137 goto err_undo;
138 atomic_inc(&dev->counts[_DRM_STAT_OPENS]);
139 if (need_setup) {
140 retcode = drm_setup(dev);
141 if (retcode)
142 goto err_undo;
f453ba04 143 }
fdb40a08 144 return 0;
a2c0a97b 145
fdb40a08
IH
146err_undo:
147 mutex_lock(&dev->struct_mutex);
a8ec3a66
IH
148 filp->f_mapping = old_imapping;
149 inode->i_mapping = old_imapping;
fdb40a08
IH
150 iput(container_of(dev->dev_mapping, struct inode, i_data));
151 dev->dev_mapping = old_mapping;
152 mutex_unlock(&dev->struct_mutex);
153 dev->open_count--;
1da177e4
LT
154 return retcode;
155}
156EXPORT_SYMBOL(drm_open);
157
d985c108
DA
158/**
159 * File \c open operation.
160 *
161 * \param inode device inode.
162 * \param filp file pointer.
163 *
164 * Puts the dev->fops corresponding to the device minor number into
165 * \p filp, call the \c open method, and restore the file operations.
166 */
167int drm_stub_open(struct inode *inode, struct file *filp)
168{
84b1fd10 169 struct drm_device *dev = NULL;
2c14f28b
DA
170 struct drm_minor *minor;
171 int minor_id = iminor(inode);
d985c108 172 int err = -ENODEV;
99ac48f5 173 const struct file_operations *old_fops;
d985c108
DA
174
175 DRM_DEBUG("\n");
176
58374713 177 mutex_lock(&drm_global_mutex);
2c14f28b
DA
178 minor = idr_find(&drm_minors_idr, minor_id);
179 if (!minor)
70ffa16e 180 goto out;
d985c108 181
2c14f28b 182 if (!(dev = minor->dev))
70ffa16e 183 goto out;
d985c108 184
2c07a21d
DA
185 if (drm_device_is_unplugged(dev))
186 goto out;
187
d985c108 188 old_fops = filp->f_op;
e08e96de 189 filp->f_op = fops_get(dev->driver->fops);
f41ced8f
LP
190 if (filp->f_op == NULL) {
191 filp->f_op = old_fops;
192 goto out;
193 }
d985c108
DA
194 if (filp->f_op->open && (err = filp->f_op->open(inode, filp))) {
195 fops_put(filp->f_op);
196 filp->f_op = fops_get(old_fops);
197 }
198 fops_put(old_fops);
199
70ffa16e 200out:
58374713 201 mutex_unlock(&drm_global_mutex);
d985c108
DA
202 return err;
203}
204
205/**
206 * Check whether DRI will run on this CPU.
207 *
208 * \return non-zero if the DRI will run on this CPU, or zero otherwise.
209 */
210static int drm_cpu_valid(void)
211{
212#if defined(__i386__)
213 if (boot_cpu_data.x86 == 3)
214 return 0; /* No cmpxchg on a 386 */
215#endif
216#if defined(__sparc__) && !defined(__sparc_v9__)
217 return 0; /* No cmpxchg before v9 sparc. */
218#endif
219 return 1;
220}
221
222/**
223 * Called whenever a process opens /dev/drm.
224 *
225 * \param inode device inode.
226 * \param filp file pointer.
227 * \param dev device.
228 * \return zero on success or a negative number on failure.
229 *
230 * Creates and initializes a drm_file structure for the file private data in \p
231 * filp and add it into the double linked list in \p dev.
232 */
233static int drm_open_helper(struct inode *inode, struct file *filp,
84b1fd10 234 struct drm_device * dev)
d985c108 235{
2c14f28b 236 int minor_id = iminor(inode);
84b1fd10 237 struct drm_file *priv;
d985c108
DA
238 int ret;
239
240 if (filp->f_flags & O_EXCL)
241 return -EBUSY; /* No exclusive opens */
242 if (!drm_cpu_valid())
243 return -EINVAL;
5bcf719b
DA
244 if (dev->switch_power_state != DRM_SWITCH_POWER_ON)
245 return -EINVAL;
d985c108 246
2c14f28b 247 DRM_DEBUG("pid = %d, minor = %d\n", task_pid_nr(current), minor_id);
d985c108 248
6ebc22e6 249 priv = kzalloc(sizeof(*priv), GFP_KERNEL);
d985c108
DA
250 if (!priv)
251 return -ENOMEM;
252
d985c108 253 filp->private_data = priv;
6c340eac 254 priv->filp = filp;
2df68b43 255 priv->uid = current_euid();
5fce5e0b 256 priv->pid = get_pid(task_pid(current));
2c14f28b 257 priv->minor = idr_find(&drm_minors_idr, minor_id);
df9b6a9c
SWK
258 if (!priv->minor) {
259 ret = -ENODEV;
260 goto out_put_pid;
261 }
262
d985c108
DA
263 priv->ioctl_count = 0;
264 /* for compatibility root is always authenticated */
265 priv->authenticated = capable(CAP_SYS_ADMIN);
266 priv->lock_count = 0;
267
bd1b331f 268 INIT_LIST_HEAD(&priv->lhead);
f453ba04 269 INIT_LIST_HEAD(&priv->fbs);
4b096ac1 270 mutex_init(&priv->fbs_lock);
c9a9c5e0
KH
271 INIT_LIST_HEAD(&priv->event_list);
272 init_waitqueue_head(&priv->event_wait);
273 priv->event_space = 4096; /* set aside 4k for event buffer */
bd1b331f 274
673a394b
EA
275 if (dev->driver->driver_features & DRIVER_GEM)
276 drm_gem_open(dev, priv);
277
3248877e
DA
278 if (drm_core_check_feature(dev, DRIVER_PRIME))
279 drm_prime_init_file_private(&priv->prime);
280
d985c108
DA
281 if (dev->driver->open) {
282 ret = dev->driver->open(dev, priv);
283 if (ret < 0)
df9b6a9c 284 goto out_prime_destroy;
d985c108
DA
285 }
286
7c1c2871
DA
287
288 /* if there is no current master make this fd it */
30e2fb18 289 mutex_lock(&dev->struct_mutex);
7c1c2871
DA
290 if (!priv->minor->master) {
291 /* create a new master */
292 priv->minor->master = drm_master_create(priv->minor);
293 if (!priv->minor->master) {
dba5ed0c 294 mutex_unlock(&dev->struct_mutex);
7c1c2871 295 ret = -ENOMEM;
df9b6a9c 296 goto out_close;
7c1c2871
DA
297 }
298
299 priv->is_master = 1;
300 /* take another reference for the copy in the local file priv */
301 priv->master = drm_master_get(priv->minor->master);
302
303 priv->authenticated = 1;
304
305 mutex_unlock(&dev->struct_mutex);
306 if (dev->driver->master_create) {
307 ret = dev->driver->master_create(dev, priv->master);
308 if (ret) {
309 mutex_lock(&dev->struct_mutex);
310 /* drop both references if this fails */
311 drm_master_put(&priv->minor->master);
312 drm_master_put(&priv->master);
313 mutex_unlock(&dev->struct_mutex);
df9b6a9c 314 goto out_close;
7c1c2871
DA
315 }
316 }
862302ff
TH
317 mutex_lock(&dev->struct_mutex);
318 if (dev->driver->master_set) {
319 ret = dev->driver->master_set(dev, priv, true);
320 if (ret) {
321 /* drop both references if this fails */
322 drm_master_put(&priv->minor->master);
323 drm_master_put(&priv->master);
324 mutex_unlock(&dev->struct_mutex);
df9b6a9c 325 goto out_close;
862302ff
TH
326 }
327 }
328 mutex_unlock(&dev->struct_mutex);
7c1c2871
DA
329 } else {
330 /* get a reference to the master */
331 priv->master = drm_master_get(priv->minor->master);
332 mutex_unlock(&dev->struct_mutex);
333 }
bd1b331f 334
7c1c2871 335 mutex_lock(&dev->struct_mutex);
bd1b331f 336 list_add(&priv->lhead, &dev->filelist);
30e2fb18 337 mutex_unlock(&dev->struct_mutex);
d985c108
DA
338
339#ifdef __alpha__
340 /*
341 * Default the hose
342 */
343 if (!dev->hose) {
344 struct pci_dev *pci_dev;
345 pci_dev = pci_get_class(PCI_CLASS_DISPLAY_VGA << 8, NULL);
346 if (pci_dev) {
347 dev->hose = pci_dev->sysdata;
348 pci_dev_put(pci_dev);
349 }
350 if (!dev->hose) {
351 struct pci_bus *b = pci_bus_b(pci_root_buses.next);
352 if (b)
353 dev->hose = b->sysdata;
354 }
355 }
356#endif
357
358 return 0;
df9b6a9c
SWK
359
360out_close:
361 if (dev->driver->postclose)
362 dev->driver->postclose(dev, priv);
363out_prime_destroy:
364 if (drm_core_check_feature(dev, DRIVER_PRIME))
365 drm_prime_destroy_file_private(&priv->prime);
366 if (dev->driver->driver_features & DRIVER_GEM)
367 drm_gem_release(dev, priv);
368out_put_pid:
369 put_pid(priv->pid);
9a298b2a 370 kfree(priv);
d985c108
DA
371 filp->private_data = NULL;
372 return ret;
373}
374
375/** No-op. */
376int drm_fasync(int fd, struct file *filp, int on)
377{
84b1fd10 378 struct drm_file *priv = filp->private_data;
2c14f28b 379 struct drm_device *dev = priv->minor->dev;
d985c108
DA
380
381 DRM_DEBUG("fd = %d, device = 0x%lx\n", fd,
2c14f28b 382 (long)old_encode_dev(priv->minor->device));
60aa4924 383 return fasync_helper(fd, filp, on, &dev->buf_async);
d985c108
DA
384}
385EXPORT_SYMBOL(drm_fasync);
386
7c1c2871
DA
387static void drm_master_release(struct drm_device *dev, struct file *filp)
388{
389 struct drm_file *file_priv = filp->private_data;
390
7c1c2871
DA
391 if (drm_i_have_hw_lock(dev, file_priv)) {
392 DRM_DEBUG("File %p released, freeing lock for context %d\n",
393 filp, _DRM_LOCKING_CONTEXT(file_priv->master->lock.hw_lock->lock));
394 drm_lock_free(&file_priv->master->lock,
395 _DRM_LOCKING_CONTEXT(file_priv->master->lock.hw_lock->lock));
396 }
7c1c2871
DA
397}
398
c9a9c5e0
KH
399static void drm_events_release(struct drm_file *file_priv)
400{
401 struct drm_device *dev = file_priv->minor->dev;
402 struct drm_pending_event *e, *et;
403 struct drm_pending_vblank_event *v, *vt;
404 unsigned long flags;
405
406 spin_lock_irqsave(&dev->event_lock, flags);
407
408 /* Remove pending flips */
409 list_for_each_entry_safe(v, vt, &dev->vblank_event_list, base.link)
410 if (v->base.file_priv == file_priv) {
411 list_del(&v->base.link);
412 drm_vblank_put(dev, v->pipe);
413 v->base.destroy(&v->base);
414 }
415
416 /* Remove unconsumed events */
417 list_for_each_entry_safe(e, et, &file_priv->event_list, link)
418 e->destroy(e);
419
420 spin_unlock_irqrestore(&dev->event_lock, flags);
421}
422
1da177e4
LT
423/**
424 * Release file.
425 *
426 * \param inode device inode
6c340eac 427 * \param file_priv DRM file private.
1da177e4
LT
428 * \return zero on success or a negative number on failure.
429 *
430 * If the hardware lock is held then free it, and take it again for the kernel
431 * context since it's necessary to reclaim buffers. Unlink the file private
432 * data from its list and free it. Decreases the open count and if it reaches
22eae947 433 * zero calls drm_lastclose().
1da177e4 434 */
b5e89ed5 435int drm_release(struct inode *inode, struct file *filp)
1da177e4 436{
6c340eac 437 struct drm_file *file_priv = filp->private_data;
2c14f28b 438 struct drm_device *dev = file_priv->minor->dev;
1da177e4
LT
439 int retcode = 0;
440
58374713 441 mutex_lock(&drm_global_mutex);
1da177e4 442
b5e89ed5 443 DRM_DEBUG("open_count = %d\n", dev->open_count);
1da177e4 444
22eae947 445 if (dev->driver->preclose)
6c340eac 446 dev->driver->preclose(dev, file_priv);
1da177e4
LT
447
448 /* ========================================================
449 * Begin inline drm_release
450 */
451
b5e89ed5 452 DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %d\n",
ba25f9dc 453 task_pid_nr(current),
2c14f28b 454 (long)old_encode_dev(file_priv->minor->device),
b5e89ed5
DA
455 dev->open_count);
456
598781d7
TH
457 /* Release any auth tokens that might point to this file_priv,
458 (do that under the drm_global_mutex) */
459 if (file_priv->magic)
460 (void) drm_remove_magic(file_priv->master, file_priv->magic);
461
7c1c2871
DA
462 /* if the master has gone away we can't do anything with the lock */
463 if (file_priv->minor->master)
464 drm_master_release(dev, filp);
1da177e4 465
67cb4b4d
DV
466 if (drm_core_check_feature(dev, DRIVER_HAVE_DMA))
467 drm_core_reclaim_buffers(dev, file_priv);
468
c9a9c5e0
KH
469 drm_events_release(file_priv);
470
ea39f835
KH
471 if (dev->driver->driver_features & DRIVER_MODESET)
472 drm_fb_release(file_priv);
473
4e47e02d
P
474 if (dev->driver->driver_features & DRIVER_GEM)
475 drm_gem_release(dev, file_priv);
476
30e2fb18 477 mutex_lock(&dev->ctxlist_mutex);
bd1b331f 478 if (!list_empty(&dev->ctxlist)) {
55910517 479 struct drm_ctx_list *pos, *n;
1da177e4 480
bd1b331f 481 list_for_each_entry_safe(pos, n, &dev->ctxlist, head) {
6c340eac 482 if (pos->tag == file_priv &&
b5e89ed5 483 pos->handle != DRM_KERNEL_CONTEXT) {
1da177e4 484 if (dev->driver->context_dtor)
b5e89ed5
DA
485 dev->driver->context_dtor(dev,
486 pos->handle);
1da177e4 487
b5e89ed5 488 drm_ctxbitmap_free(dev, pos->handle);
1da177e4 489
b5e89ed5 490 list_del(&pos->head);
9a298b2a 491 kfree(pos);
1da177e4
LT
492 --dev->ctx_count;
493 }
494 }
495 }
30e2fb18 496 mutex_unlock(&dev->ctxlist_mutex);
1da177e4 497
30e2fb18 498 mutex_lock(&dev->struct_mutex);
7c1c2871
DA
499
500 if (file_priv->is_master) {
fda714c2 501 struct drm_master *master = file_priv->master;
84b1fd10 502 struct drm_file *temp;
7c1c2871
DA
503 list_for_each_entry(temp, &dev->filelist, lhead) {
504 if ((temp->master == file_priv->master) &&
505 (temp != file_priv))
506 temp->authenticated = 0;
507 }
bd1b331f 508
fda714c2
TH
509 /**
510 * Since the master is disappearing, so is the
511 * possibility to lock.
512 */
513
514 if (master->lock.hw_lock) {
515 if (dev->sigdata.lock == master->lock.hw_lock)
516 dev->sigdata.lock = NULL;
517 master->lock.hw_lock = NULL;
518 master->lock.file_priv = NULL;
519 wake_up_interruptible_all(&master->lock.lock_queue);
520 }
521
7c1c2871
DA
522 if (file_priv->minor->master == file_priv->master) {
523 /* drop the reference held my the minor */
862302ff
TH
524 if (dev->driver->master_drop)
525 dev->driver->master_drop(dev, file_priv, true);
7c1c2871
DA
526 drm_master_put(&file_priv->minor->master);
527 }
1da177e4 528 }
7c1c2871 529
949c4a34
IH
530 BUG_ON(dev->dev_mapping == NULL);
531 iput(container_of(dev->dev_mapping, struct inode, i_data));
532
7c1c2871
DA
533 /* drop the reference held my the file priv */
534 drm_master_put(&file_priv->master);
535 file_priv->is_master = 0;
6c340eac 536 list_del(&file_priv->lhead);
30e2fb18 537 mutex_unlock(&dev->struct_mutex);
b5e89ed5 538
22eae947 539 if (dev->driver->postclose)
6c340eac 540 dev->driver->postclose(dev, file_priv);
3248877e
DA
541
542 if (drm_core_check_feature(dev, DRIVER_PRIME))
543 drm_prime_destroy_file_private(&file_priv->prime);
544
5fce5e0b 545 put_pid(file_priv->pid);
9a298b2a 546 kfree(file_priv);
1da177e4
LT
547
548 /* ========================================================
549 * End inline drm_release
550 */
551
b5e89ed5 552 atomic_inc(&dev->counts[_DRM_STAT_CLOSES]);
b5e89ed5 553 if (!--dev->open_count) {
7c1c2871
DA
554 if (atomic_read(&dev->ioctl_count)) {
555 DRM_ERROR("Device busy: %d\n",
556 atomic_read(&dev->ioctl_count));
58374713 557 retcode = -EBUSY;
1a72d65d
CW
558 } else
559 retcode = drm_lastclose(dev);
2c07a21d
DA
560 if (drm_device_is_unplugged(dev))
561 drm_put_dev(dev);
1da177e4 562 }
58374713 563 mutex_unlock(&drm_global_mutex);
1da177e4
LT
564
565 return retcode;
566}
567EXPORT_SYMBOL(drm_release);
568
c9a9c5e0
KH
569static bool
570drm_dequeue_event(struct drm_file *file_priv,
571 size_t total, size_t max, struct drm_pending_event **out)
572{
573 struct drm_device *dev = file_priv->minor->dev;
574 struct drm_pending_event *e;
575 unsigned long flags;
576 bool ret = false;
577
578 spin_lock_irqsave(&dev->event_lock, flags);
579
580 *out = NULL;
581 if (list_empty(&file_priv->event_list))
582 goto out;
583 e = list_first_entry(&file_priv->event_list,
584 struct drm_pending_event, link);
585 if (e->event->length + total > max)
586 goto out;
587
588 file_priv->event_space += e->event->length;
589 list_del(&e->link);
590 *out = e;
591 ret = true;
592
593out:
594 spin_unlock_irqrestore(&dev->event_lock, flags);
595 return ret;
596}
597
598ssize_t drm_read(struct file *filp, char __user *buffer,
599 size_t count, loff_t *offset)
600{
601 struct drm_file *file_priv = filp->private_data;
602 struct drm_pending_event *e;
603 size_t total;
604 ssize_t ret;
605
606 ret = wait_event_interruptible(file_priv->event_wait,
607 !list_empty(&file_priv->event_list));
608 if (ret < 0)
609 return ret;
610
611 total = 0;
612 while (drm_dequeue_event(file_priv, total, count, &e)) {
613 if (copy_to_user(buffer + total,
614 e->event, e->event->length)) {
615 total = -EFAULT;
616 break;
617 }
618
619 total += e->event->length;
620 e->destroy(e);
621 }
622
623 return total;
624}
625EXPORT_SYMBOL(drm_read);
626
1da177e4
LT
627unsigned int drm_poll(struct file *filp, struct poll_table_struct *wait)
628{
c9a9c5e0
KH
629 struct drm_file *file_priv = filp->private_data;
630 unsigned int mask = 0;
631
632 poll_wait(filp, &file_priv->event_wait, wait);
633
634 if (!list_empty(&file_priv->event_list))
635 mask |= POLLIN | POLLRDNORM;
636
637 return mask;
1da177e4 638}
b5e89ed5 639EXPORT_SYMBOL(drm_poll);
This page took 0.646898 seconds and 5 git commands to generate.