Lines Matching refs:dev

47 	drm_device_t *dev = (void *)arg;
50 mutex_enter(&dev->irq_lock);
51 ret = dev->driver->irq_handler(arg);
52 mutex_exit(&dev->irq_lock);
60 drm_device_t *dev = (void *)arg1;
63 mutex_enter(&dev->irq_lock);
64 ret = dev->driver->irq_handler(arg1);
65 mutex_exit(&dev->irq_lock);
70 static int __install_irq_handler(struct drm_device *dev)
72 struct pci_dev *pdev = dev->pdev;
79 __irq_handler_wrap_msi, (caddr_t)dev, NULL);
96 if (ddi_add_intr(dev->devinfo, 0, &pdev->intr_block,
98 (caddr_t)dev) != DDI_SUCCESS) {
107 static void __uninstall_irq_handler(struct drm_device *dev)
109 struct pci_dev *pdev = dev->pdev;
112 ASSERT(dev->devinfo);
129 ddi_remove_intr(dev->devinfo, 0, pdev->intr_block);
136 struct drm_device *dev = pdev->dev;
137 dev_info_t *devinfo = dev->devinfo;
143 if (ddi_intr_get_supported_types(dev->devinfo, &types) != DDI_SUCCESS) {
221 #define vblanktimestamp(dev, crtc, count) ( \
222 (dev)->_vblank_time[(crtc) * DRM_VBLANKTIME_RBSIZE + \
253 if (!drm_core_check_feature(dev, DRIVER_HAVE_IRQ))
256 if ((p->busnum >> 8) != dev->pdev->domain ||
257 (p->busnum & 0xff) != dev->pdev->bus ||
258 p->devnum != dev->pdev->slot || p->funcnum != dev->pdev->func)
261 p->irq = dev->pdev->irq;
272 static void clear_vblank_timestamps(struct drm_device *dev, int crtc)
274 (void) memset(&dev->_vblank_time[crtc * DRM_VBLANKTIME_RBSIZE], -1,
284 static void vblank_disable_and_save(struct drm_device *dev, int crtc)
297 spin_lock_irqsave(&dev->vblank_time_lock, irqflags);
299 dev->driver->disable_vblank(dev, crtc);
300 dev->vblank_enabled[crtc] = 0;
315 dev->last_vblank[crtc] = dev->driver->get_vblank_counter(dev, crtc);
316 vblrc = drm_get_last_vbltimestamp(dev, crtc, &tvblank, 0);
317 } while (dev->last_vblank[crtc] != dev->driver->get_vblank_counter(dev, crtc) && (--count) && vblrc);
325 vblcount = atomic_read(&dev->_vblank_count[crtc]);
327 timeval_to_ns(&vblanktimestamp(dev, crtc, vblcount));
342 atomic_inc(&dev->_vblank_count[crtc]);
346 clear_vblank_timestamps(dev, crtc);
348 spin_unlock_irqrestore(&dev->vblank_time_lock, irqflags);
353 struct drm_device *dev = (struct drm_device *)arg;
357 if (!dev->vblank_disable_allowed)
360 for (i = 0; i < dev->num_crtcs; i++) {
361 spin_lock_irqsave(&dev->vbl_lock, irqflags);
362 if (atomic_read(&dev->vblank_refcount[i]) == 0 &&
363 dev->vblank_enabled[i]) {
365 vblank_disable_and_save(dev, i);
367 spin_unlock_irqrestore(&dev->vbl_lock, irqflags);
371 void drm_vblank_cleanup(struct drm_device *dev)
374 if (dev->num_crtcs == 0)
377 del_timer(&dev->vblank_disable_timer);
378 destroy_timer(&dev->vblank_disable_timer);
380 vblank_disable_fn((void *)dev);
382 kfree(dev->vbl_queue, sizeof (wait_queue_head_t) * dev->num_crtcs);
383 kfree(dev->_vblank_count, sizeof (atomic_t) * dev->num_crtcs);
384 kfree(dev->vblank_refcount, sizeof (atomic_t) * dev->num_crtcs);
385 kfree(dev->vblank_enabled, sizeof (int) * dev->num_crtcs);
386 kfree(dev->last_vblank, sizeof (u32) * dev->num_crtcs);
387 kfree(dev->last_vblank_wait, sizeof (u32) * dev->num_crtcs);
388 kfree(dev->vblank_inmodeset, sizeof (*dev->vblank_inmodeset) * dev->num_crtcs);
389 kfree(dev->_vblank_time, sizeof (*dev->_vblank_time) * dev->num_crtcs * DRM_VBLANKTIME_RBSIZE);
391 dev->num_crtcs = 0;
393 mutex_destroy(&dev->vbl_lock);
396 int drm_vblank_init(struct drm_device *dev, int num_crtcs)
400 init_timer(&dev->vblank_disable_timer);
401 setup_timer(&dev->vblank_disable_timer, vblank_disable_fn,
402 dev);
403 mutex_init(&dev->vbl_lock, NULL, MUTEX_DRIVER, (void *)dev->pdev->intr_block);
404 spin_lock_init(&dev->vblank_time_lock);
406 dev->num_crtcs = num_crtcs;
408 dev->vbl_queue = kmalloc(sizeof(wait_queue_head_t) * num_crtcs,
410 if (!dev->vbl_queue)
413 dev->_vblank_count = kmalloc(sizeof(atomic_t) * num_crtcs, GFP_KERNEL);
414 if (!dev->_vblank_count)
417 dev->vblank_refcount = kmalloc(sizeof(atomic_t) * num_crtcs,
419 if (!dev->vblank_refcount)
422 dev->vblank_enabled = kcalloc(num_crtcs, sizeof(int), GFP_KERNEL);
423 if (!dev->vblank_enabled)
426 dev->last_vblank = kcalloc(num_crtcs, sizeof(u32), GFP_KERNEL);
427 if (!dev->last_vblank)
430 dev->last_vblank_wait = kcalloc(num_crtcs, sizeof(u32), GFP_KERNEL);
431 if (!dev->last_vblank_wait)
434 dev->vblank_inmodeset = kcalloc(num_crtcs, sizeof(int), GFP_KERNEL);
435 if (!dev->vblank_inmodeset)
438 dev->_vblank_time = kcalloc(num_crtcs * DRM_VBLANKTIME_RBSIZE,
440 if (!dev->_vblank_time)
446 if (dev->driver->get_vblank_timestamp)
453 DRM_INIT_WAITQUEUE(&dev->vbl_queue[i], DRM_INTR_PRI(dev));
454 atomic_set(&dev->_vblank_count[i], 0);
455 atomic_set(&dev->vblank_refcount[i], 0);
458 dev->vblank_disable_allowed = 0;
463 drm_vblank_cleanup(dev);
470 struct drm_device *dev = cookie;
472 if (dev->driver->vgaarb_irq) {
473 dev->driver->vgaarb_irq(dev, state);
477 if (!dev->irq_enabled)
481 if (dev->driver->irq_uninstall)
482 dev->driver->irq_uninstall(dev);
484 if (dev->driver->irq_preinstall)
485 dev->driver->irq_preinstall(dev);
486 if (dev->driver->irq_postinstall)
487 dev->driver->irq_postinstall(dev);
494 * \param dev DRM device.
500 int drm_irq_install(struct drm_device *dev)
504 if (!drm_core_check_feature(dev, DRIVER_HAVE_IRQ))
507 if (dev->pdev->irq == 0)
510 mutex_lock(&dev->struct_mutex);
513 if (!dev->dev_private) {
514 mutex_unlock(&dev->struct_mutex);
518 if (dev->irq_enabled) {
519 mutex_unlock(&dev->struct_mutex);
522 dev->irq_enabled = 1;
523 mutex_unlock(&dev->struct_mutex);
525 DRM_DEBUG("irq=%d\n", dev->pdev->irq);
528 if (dev->driver->irq_preinstall)
529 dev->driver->irq_preinstall(dev);
532 ret = __install_irq_handler(dev);
535 mutex_lock(&dev->struct_mutex);
536 dev->irq_enabled = 0;
537 mutex_unlock(&dev->struct_mutex);
542 if (dev->driver->irq_postinstall)
543 ret = dev->driver->irq_postinstall(dev);
545 mutex_lock(&dev->struct_mutex);
546 dev->irq_enabled = 0;
547 mutex_unlock(&dev->struct_mutex);
551 dev->context_flag = 0;
558 * \param dev DRM device.
562 int drm_irq_uninstall(struct drm_device * dev)
567 if (!drm_core_check_feature(dev, DRIVER_HAVE_IRQ))
570 mutex_lock(&dev->struct_mutex);
571 irq_enabled = dev->irq_enabled;
572 dev->irq_enabled = 0;
573 mutex_unlock(&dev->struct_mutex);
578 if (dev->num_crtcs) {
579 spin_lock_irqsave(&dev->vbl_lock, irqflags);
580 for (i = 0; i < dev->num_crtcs; i++) {
581 DRM_WAKEUP(&dev->vbl_queue[i]);
582 dev->vblank_enabled[i] = 0;
583 dev->last_vblank[i] =
584 dev->driver->get_vblank_counter(dev, i);
586 spin_unlock_irqrestore(&dev->vbl_lock, irqflags);
592 DRM_DEBUG("irq=%d\n", dev->pdev->irq);
594 if (dev->driver->irq_uninstall)
595 dev->driver->irq_uninstall(dev);
597 __uninstall_irq_handler(dev);
623 if (!drm_core_check_feature(dev, DRIVER_HAVE_IRQ))
625 if (drm_core_check_feature(dev, DRIVER_MODESET))
627 if (dev->if_version < DRM_IF_VERSION(1, 2) &&
628 ctl->irq != dev->pdev->irq)
630 return drm_irq_install(dev);
632 if (!drm_core_check_feature(dev, DRIVER_HAVE_IRQ))
634 if (drm_core_check_feature(dev, DRIVER_MODESET))
636 return drm_irq_uninstall(dev);
710 * Requires support for optional dev->driver->get_scanout_position()
718 * @dev: DRM device.
742 int drm_calc_vbltimestamp_from_scanoutpos(struct drm_device *dev, int crtc,
755 if (crtc < 0 || crtc >= dev->num_crtcs) {
761 if (!dev->driver->get_scanout_position) {
799 vbl_status = dev->driver->get_scanout_position(dev, crtc, &vpos, &hpos);
879 * @dev: DRM device
895 u32 drm_get_last_vbltimestamp(struct drm_device *dev, int crtc,
904 if (dev->driver->get_vblank_timestamp && (max_error > 0)) {
905 ret = dev->driver->get_vblank_timestamp(dev, crtc, &max_error,
921 * @dev: DRM device
928 u32 drm_vblank_count(struct drm_device *dev, int crtc)
930 return atomic_read(&dev->_vblank_count[crtc]);
937 * @dev: DRM device
947 u32 drm_vblank_count_and_time(struct drm_device *dev, int crtc,
958 cur_vblank = atomic_read(&dev->_vblank_count[crtc]);
959 *vblanktime = vblanktimestamp(dev, crtc, cur_vblank);
960 } while (cur_vblank != atomic_read(&dev->_vblank_count[crtc]));
966 static void send_vblank_event(struct drm_device *dev,
980 * @dev: DRM device
987 void drm_send_vblank_event(struct drm_device *dev, int crtc,
993 seq = drm_vblank_count_and_time(dev, crtc, &now);
1000 send_vblank_event(dev, e, seq, &now);
1005 * @dev: DRM device
1016 * Note: caller must hold dev->vbl_lock since this reads & writes
1019 static void drm_update_vblank_count(struct drm_device *dev, int crtc)
1027 * NOTE! It's possible we lost a full dev->max_vblank_count events
1037 cur_vblank = dev->driver->get_vblank_counter(dev, crtc);
1038 rc = drm_get_last_vbltimestamp(dev, crtc, &t_vblank, 0);
1039 } while (cur_vblank != dev->driver->get_vblank_counter(dev, crtc));
1042 diff = cur_vblank - dev->last_vblank[crtc];
1043 if (cur_vblank < dev->last_vblank[crtc]) {
1044 diff += dev->max_vblank_count;
1047 crtc, dev->last_vblank[crtc], cur_vblank, diff);
1058 tslot = atomic_read(&dev->_vblank_count[crtc]) + diff;
1059 vblanktimestamp(dev, crtc, tslot) = t_vblank;
1062 atomic_add(diff, &dev->_vblank_count[crtc]);
1067 * @dev: DRM device
1076 int drm_vblank_get(struct drm_device *dev, int crtc)
1081 spin_lock_irqsave(&dev->vbl_lock, irqflags);
1083 if (atomic_add_return(1, &dev->vblank_refcount[crtc]) == 1) {
1084 spin_lock_irqsave(&dev->vblank_time_lock, irqflags2);
1085 if (!dev->vblank_enabled[crtc]) {
1086 ret = dev->driver->enable_vblank(dev, crtc);
1090 atomic_dec(&dev->vblank_refcount[crtc]);
1092 dev->vblank_enabled[crtc] = 1;
1093 drm_update_vblank_count(dev, crtc);
1096 spin_unlock_irqrestore(&dev->vblank_time_lock, irqflags2);
1098 if (!dev->vblank_enabled[crtc]) {
1099 atomic_dec(&dev->vblank_refcount[crtc]);
1103 spin_unlock_irqrestore(&dev->vbl_lock, irqflags);
1110 * @dev: DRM device
1116 void drm_vblank_put(struct drm_device *dev, int crtc)
1118 BUG_ON (atomic_read (&dev->vblank_refcount[crtc]) == 0);
1121 if (atomic_dec_and_test(&dev->vblank_refcount[crtc]) &&
1123 mod_timer(&dev->vblank_disable_timer,
1129 * @dev: DRM device
1134 void drm_vblank_off(struct drm_device *dev, int crtc)
1141 spin_lock_irqsave(&dev->vbl_lock, irqflags);
1142 vblank_disable_and_save(dev, crtc);
1143 DRM_WAKEUP(&dev->vbl_queue[crtc]);
1146 seq = drm_vblank_count_and_time(dev, crtc, &now);
1148 spin_lock(&dev->event_lock);
1150 &dev->vblank_event_list, base.link) {
1157 drm_vblank_put(dev, e->pipe);
1158 send_vblank_event(dev, e, seq, &now);
1160 spin_unlock(&dev->event_lock);
1162 spin_unlock_irqrestore(&dev->vbl_lock, irqflags);
1167 * @dev: DRM device
1174 void drm_vblank_pre_modeset(struct drm_device *dev, int crtc)
1177 if (!dev->num_crtcs)
1186 if (!dev->vblank_inmodeset[crtc]) {
1187 dev->vblank_inmodeset[crtc] = 0x1;
1188 if (drm_vblank_get(dev, crtc) == 0)
1189 dev->vblank_inmodeset[crtc] |= 0x2;
1193 void drm_vblank_post_modeset(struct drm_device *dev, int crtc)
1198 if (!dev->num_crtcs)
1201 if (dev->vblank_inmodeset[crtc]) {
1202 spin_lock_irqsave(&dev->vbl_lock, irqflags);
1203 dev->vblank_disable_allowed = 1;
1204 spin_unlock_irqrestore(&dev->vbl_lock, irqflags);
1206 if (dev->vblank_inmodeset[crtc] & 0x2)
1207 drm_vblank_put(dev, crtc);
1209 dev->vblank_inmodeset[crtc] = 0;
1231 if (!dev->num_crtcs)
1235 if (drm_core_check_feature(dev, DRIVER_MODESET))
1239 if (crtc >= dev->num_crtcs)
1244 drm_vblank_pre_modeset(dev, crtc);
1247 drm_vblank_post_modeset(dev, crtc);
1256 static int drm_queue_vblank_event(struct drm_device *dev, int pipe,
1281 spin_lock_irqsave(&dev->event_lock, flags);
1289 seq = drm_vblank_count_and_time(dev, pipe, &now);
1302 drm_vblank_put(dev, pipe);
1303 send_vblank_event(dev, e, seq, &now);
1308 list_add_tail(&e->base.link, &dev->vblank_event_list, (caddr_t)&e->base);
1312 spin_unlock_irqrestore(&dev->event_lock, flags);
1316 spin_unlock_irqrestore(&dev->event_lock, flags);
1319 drm_vblank_put(dev, pipe);
1344 if ((!dev->pdev->irq) || (!dev->irq_enabled))
1366 if (crtc >= dev->num_crtcs)
1369 ret = drm_vblank_get(dev, crtc);
1374 seq = drm_vblank_count(dev, crtc);
1392 return drm_queue_vblank_event(dev, crtc, vblwait, file);
1402 dev->last_vblank_wait[crtc] = vblwait->request.sequence;
1403 DRM_WAIT_ON(ret, &dev->vbl_queue[crtc], 3 * DRM_HZ,
1404 (((drm_vblank_count(dev, crtc) -
1406 !dev->irq_enabled));
1411 vblwait->reply.sequence = drm_vblank_count_and_time(dev, crtc, &now);
1422 drm_vblank_put(dev, crtc);
1426 static void drm_handle_vblank_events(struct drm_device *dev, int crtc)
1433 seq = drm_vblank_count_and_time(dev, crtc, &now);
1435 spin_lock_irqsave(&dev->event_lock, flags);
1438 &dev->vblank_event_list, base.link) {
1448 drm_vblank_put(dev, e->pipe);
1449 send_vblank_event(dev, e, seq, &now);
1453 spin_unlock_irqrestore(&dev->event_lock, flags);
1458 * @dev: DRM device
1464 bool drm_handle_vblank(struct drm_device *dev, int crtc)
1471 if (!dev->num_crtcs)
1478 spin_lock_irqsave(&dev->vblank_time_lock, irqflags);
1481 if (!dev->vblank_enabled[crtc]) {
1482 spin_unlock_irqrestore(&dev->vblank_time_lock, irqflags);
1491 vblcount = atomic_read(&dev->_vblank_count[crtc]);
1492 (void) drm_get_last_vbltimestamp(dev, crtc, &tvblank, DRM_CALLED_FROM_VBLIRQ);
1496 timeval_to_ns(&vblanktimestamp(dev, crtc, vblcount));
1509 vblanktimestamp(dev, crtc, vblcount + 1) = tvblank;
1514 atomic_inc(&dev->_vblank_count[crtc]);
1520 DRM_WAKEUP(&dev->vbl_queue[crtc]);
1521 drm_handle_vblank_events(dev, crtc);
1523 spin_unlock_irqrestore(&dev->vblank_time_lock, irqflags);