38 #include <linux/poll.h>
39 #include <linux/slab.h>
40 #include <linux/module.h>
54 if (dev->driver->firstopen) {
55 ret = dev->driver->firstopen(dev);
63 if (drm_core_check_feature(dev, DRIVER_HAVE_DMA) &&
64 !drm_core_check_feature(dev, DRIVER_MODESET)) {
76 dev->sigdata.lock =
NULL;
78 dev->context_flag = 0;
79 dev->interrupt_flag = 0;
81 dev->last_context = 0;
83 dev->last_checked = 0;
90 dev->buf_async =
NULL;
121 int minor_id = iminor(inode);
122 struct drm_minor *
minor;
131 if (!(dev = minor->dev))
134 if (drm_device_is_unplugged(dev))
137 if (!dev->open_count++)
140 old_mapping = dev->dev_mapping;
141 if (old_mapping ==
NULL)
142 dev->dev_mapping = &inode->
i_data;
149 retcode = drm_open_helper(inode, filp, dev);
154 retcode = drm_setup(dev);
165 dev->dev_mapping = old_mapping;
184 struct drm_minor *
minor;
185 int minor_id = iminor(inode);
196 if (!(dev = minor->dev))
199 if (drm_device_is_unplugged(dev))
202 old_fops = filp->
f_op;
205 filp->
f_op = old_fops;
208 if (filp->
f_op->open && (err = filp->
f_op->open(inode, filp))) {
224 static int drm_cpu_valid(
void)
226 #if defined(__i386__)
230 #if defined(__sparc__) && !defined(__sparc_v9__)
247 static int drm_open_helper(
struct inode *
inode,
struct file *filp,
250 int minor_id = iminor(inode);
251 struct drm_file *
priv;
256 if (!drm_cpu_valid())
258 if (dev->switch_power_state != DRM_SWITCH_POWER_ON)
261 DRM_DEBUG(
"pid = %d, minor = %d\n", task_pid_nr(
current), minor_id);
270 priv->pid = get_pid(task_pid(
current));
272 priv->ioctl_count = 0;
275 priv->lock_count = 0;
277 INIT_LIST_HEAD(&priv->lhead);
278 INIT_LIST_HEAD(&priv->fbs);
279 INIT_LIST_HEAD(&priv->event_list);
281 priv->event_space = 4096;
283 if (dev->driver->driver_features & DRIVER_GEM)
286 if (drm_core_check_feature(dev, DRIVER_PRIME))
289 if (dev->driver->open) {
290 ret = dev->driver->open(dev, priv);
298 if (!priv->minor->master) {
301 if (!priv->minor->master) {
311 priv->authenticated = 1;
314 if (dev->driver->master_create) {
315 ret = dev->driver->master_create(dev, priv->master);
326 if (dev->driver->master_set) {
327 ret = dev->driver->master_set(dev, priv,
true);
344 list_add(&priv->lhead, &dev->filelist);
379 DRM_DEBUG(
"fd = %d, device = 0x%lx\n", fd,
380 (
long)old_encode_dev(priv->minor->device));
385 static void drm_master_release(
struct drm_device *dev,
struct file *filp)
390 DRM_DEBUG(
"File %p released, freeing lock for context %d\n",
397 static void drm_events_release(
struct drm_file *file_priv)
399 struct drm_device *dev = file_priv->minor->dev;
400 struct drm_pending_event *
e, *
et;
401 struct drm_pending_vblank_event *
v, *vt;
408 if (v->base.file_priv == file_priv) {
411 v->base.destroy(&v->base);
418 spin_unlock_irqrestore(&dev->event_lock, flags);
435 struct drm_file *file_priv = filp->private_data;
436 struct drm_device *dev = file_priv->minor->dev;
441 DRM_DEBUG(
"open_count = %d\n", dev->open_count);
443 if (dev->driver->preclose)
444 dev->driver->preclose(dev, file_priv);
450 DRM_DEBUG(
"pid = %d, device = 0x%lx, open_count = %d\n",
452 (
long)old_encode_dev(file_priv->minor->device),
457 if (file_priv->magic)
461 if (file_priv->minor->master)
462 drm_master_release(dev, filp);
464 if (drm_core_check_feature(dev, DRIVER_HAVE_DMA))
467 drm_events_release(file_priv);
469 if (dev->driver->driver_features & DRIVER_MODESET)
472 if (dev->driver->driver_features & DRIVER_GEM)
476 if (!list_empty(&dev->ctxlist)) {
477 struct drm_ctx_list *
pos, *
n;
480 if (pos->tag == file_priv &&
481 pos->handle != DRM_KERNEL_CONTEXT) {
482 if (dev->driver->context_dtor)
483 dev->driver->context_dtor(dev,
498 if (file_priv->is_master) {
499 struct drm_master *master = file_priv->master;
500 struct drm_file *
temp;
502 if ((temp->master == file_priv->master) &&
504 temp->authenticated = 0;
512 if (master->lock.hw_lock) {
513 if (dev->sigdata.lock == master->lock.hw_lock)
514 dev->sigdata.lock =
NULL;
515 master->lock.hw_lock =
NULL;
516 master->lock.file_priv =
NULL;
520 if (file_priv->minor->master == file_priv->master) {
522 if (dev->driver->master_drop)
523 dev->driver->master_drop(dev, file_priv,
true);
533 file_priv->is_master = 0;
537 if (dev->driver->postclose)
538 dev->driver->postclose(dev, file_priv);
540 if (drm_core_check_feature(dev, DRIVER_PRIME))
551 if (!--dev->open_count) {
553 DRM_ERROR(
"Device busy: %d\n",
558 if (drm_device_is_unplugged(dev))
568 drm_dequeue_event(
struct drm_file *file_priv,
569 size_t total,
size_t max,
struct drm_pending_event **
out)
571 struct drm_device *dev = file_priv->minor->dev;
572 struct drm_pending_event *
e;
579 if (list_empty(&file_priv->event_list))
582 struct drm_pending_event,
link);
583 if (e->event->length + total > max)
586 file_priv->event_space += e->event->length;
592 spin_unlock_irqrestore(&dev->event_lock, flags);
600 struct drm_pending_event *
e;
605 !list_empty(&file_priv->event_list));
610 while (drm_dequeue_event(file_priv, total, count, &e)) {
612 e->event, e->event->length)) {
617 total += e->event->length;
628 unsigned int mask = 0;
630 poll_wait(filp, &file_priv->event_wait, wait);
632 if (!list_empty(&file_priv->event_list))