Subversion Repositories Kolibri OS

Rev

Rev 1963 | Rev 3480 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. /**
  2.  * \file drm_irq.c
  3.  * IRQ support
  4.  *
  5.  * \author Rickard E. (Rik) Faith <faith@valinux.com>
  6.  * \author Gareth Hughes <gareth@valinux.com>
  7.  */
  8.  
  9. /*
  10.  * Created: Fri Mar 19 14:30:16 1999 by faith@valinux.com
  11.  *
  12.  * Copyright 1999, 2000 Precision Insight, Inc., Cedar Park, Texas.
  13.  * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
  14.  * All Rights Reserved.
  15.  *
  16.  * Permission is hereby granted, free of charge, to any person obtaining a
  17.  * copy of this software and associated documentation files (the "Software"),
  18.  * to deal in the Software without restriction, including without limitation
  19.  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  20.  * and/or sell copies of the Software, and to permit persons to whom the
  21.  * Software is furnished to do so, subject to the following conditions:
  22.  *
  23.  * The above copyright notice and this permission notice (including the next
  24.  * paragraph) shall be included in all copies or substantial portions of the
  25.  * Software.
  26.  *
  27.  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  28.  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  29.  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
  30.  * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
  31.  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  32.  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  33.  * OTHER DEALINGS IN THE SOFTWARE.
  34.  */
  35.  
  36. #include <drm/drmP.h>
  37. #include <asm/div64.h>
  38. //#include "drm_trace.h"
  39.  
  40. //#include <linux/interrupt.h>   /* For task queue support */
  41. #include <linux/slab.h>
  42.  
  43. //#include <linux/vgaarb.h>
  44. #include <linux/export.h>
  45.  
  46. /* Access macro for slots in vblank timestamp ringbuffer. */
  47. #define vblanktimestamp(dev, crtc, count) ( \
  48.         (dev)->_vblank_time[(crtc) * DRM_VBLANKTIME_RBSIZE + \
  49.         ((count) % DRM_VBLANKTIME_RBSIZE)])
  50.  
  51. /* Retry timestamp calculation up to 3 times to satisfy
  52.  * drm_timestamp_precision before giving up.
  53.  */
  54. #define DRM_TIMESTAMP_MAXRETRIES 3
  55.  
  56. /* Threshold in nanoseconds for detection of redundant
  57.  * vblank irq in drm_handle_vblank(). 1 msec should be ok.
  58.  */
  59. #define DRM_REDUNDANT_VBLIRQ_THRESH_NS 1000000
  60.  
  61.  
  62. static inline u64 div_u64(u64 dividend, u32 divisor)
  63. {
  64.         u32 remainder;
  65.         return div_u64_rem(dividend, divisor, &remainder);
  66. }
  67.  
  68.  
  69. u64 div64_u64(u64 dividend, u64 divisor)
  70. {
  71.         u32 high, d;
  72.  
  73.         high = divisor >> 32;
  74.         if (high) {
  75.                 unsigned int shift = fls(high);
  76.  
  77.                 d = divisor >> shift;
  78.                 dividend >>= shift;
  79.         } else
  80.                 d = divisor;
  81.  
  82.         return div_u64(dividend, d);
  83. }
  84.  
  85.  
  86. /**
  87.  * drm_calc_timestamping_constants - Calculate and
  88.  * store various constants which are later needed by
  89.  * vblank and swap-completion timestamping, e.g, by
  90.  * drm_calc_vbltimestamp_from_scanoutpos().
  91.  * They are derived from crtc's true scanout timing,
  92.  * so they take things like panel scaling or other
  93.  * adjustments into account.
  94.  *
  95.  * @crtc drm_crtc whose timestamp constants should be updated.
  96.  *
  97.  */
  98. void drm_calc_timestamping_constants(struct drm_crtc *crtc)
  99. {
  100.         s64 linedur_ns = 0, pixeldur_ns = 0, framedur_ns = 0;
  101.         u64 dotclock;
  102.  
  103.         /* Dot clock in Hz: */
  104.         dotclock = (u64) crtc->hwmode.clock * 1000;
  105.  
  106.         /* Fields of interlaced scanout modes are only halve a frame duration.
  107.          * Double the dotclock to get halve the frame-/line-/pixelduration.
  108.          */
  109.         if (crtc->hwmode.flags & DRM_MODE_FLAG_INTERLACE)
  110.                 dotclock *= 2;
  111.  
  112.         /* Valid dotclock? */
  113.         if (dotclock > 0) {
  114.                 /* Convert scanline length in pixels and video dot clock to
  115.                  * line duration, frame duration and pixel duration in
  116.                  * nanoseconds:
  117.                  */
  118.                 pixeldur_ns = (s64) div64_u64(1000000000, dotclock);
  119.                 linedur_ns  = (s64) div64_u64(((u64) crtc->hwmode.crtc_htotal *
  120.                                               1000000000), dotclock);
  121.                 framedur_ns = (s64) crtc->hwmode.crtc_vtotal * linedur_ns;
  122.         } else
  123.                 DRM_ERROR("crtc %d: Can't calculate constants, dotclock = 0!\n",
  124.                           crtc->base.id);
  125.  
  126.         crtc->pixeldur_ns = pixeldur_ns;
  127.         crtc->linedur_ns  = linedur_ns;
  128.         crtc->framedur_ns = framedur_ns;
  129.  
  130.         DRM_DEBUG("crtc %d: hwmode: htotal %d, vtotal %d, vdisplay %d\n",
  131.                   crtc->base.id, crtc->hwmode.crtc_htotal,
  132.                   crtc->hwmode.crtc_vtotal, crtc->hwmode.crtc_vdisplay);
  133.         DRM_DEBUG("crtc %d: clock %d kHz framedur %d linedur %d, pixeldur %d\n",
  134.                   crtc->base.id, (int) dotclock/1000, (int) framedur_ns,
  135.                   (int) linedur_ns, (int) pixeldur_ns);
  136. }
  137.  
  138.  
  139. /**
  140.  * drm_vblank_pre_modeset - account for vblanks across mode sets
  141.  * @dev: DRM device
  142.  * @crtc: CRTC in question
  143.  *
  144.  * Account for vblank events across mode setting events, which will likely
  145.  * reset the hardware frame counter.
  146.  */
  147. void drm_vblank_pre_modeset(struct drm_device *dev, int crtc)
  148. {
  149. #if 0
  150.     /* vblank is not initialized (IRQ not installed ?) */
  151.     if (!dev->num_crtcs)
  152.         return;
  153.     /*
  154.      * To avoid all the problems that might happen if interrupts
  155.      * were enabled/disabled around or between these calls, we just
  156.      * have the kernel take a reference on the CRTC (just once though
  157.      * to avoid corrupting the count if multiple, mismatch calls occur),
  158.      * so that interrupts remain enabled in the interim.
  159.      */
  160.     if (!dev->vblank_inmodeset[crtc]) {
  161.         dev->vblank_inmodeset[crtc] = 0x1;
  162.         if (drm_vblank_get(dev, crtc) == 0)
  163.             dev->vblank_inmodeset[crtc] |= 0x2;
  164.     }
  165. #endif
  166. }
  167. EXPORT_SYMBOL(drm_vblank_pre_modeset);
  168.  
  169. void drm_vblank_post_modeset(struct drm_device *dev, int crtc)
  170. {
  171. #if 0
  172.     unsigned long irqflags;
  173.  
  174.     if (dev->vblank_inmodeset[crtc]) {
  175.         spin_lock_irqsave(&dev->vbl_lock, irqflags);
  176.         dev->vblank_disable_allowed = 1;
  177.         spin_unlock_irqrestore(&dev->vbl_lock, irqflags);
  178.  
  179.         if (dev->vblank_inmodeset[crtc] & 0x2)
  180.             drm_vblank_put(dev, crtc);
  181.  
  182.         dev->vblank_inmodeset[crtc] = 0;
  183.     }
  184. #endif
  185. }
  186. EXPORT_SYMBOL(drm_vblank_post_modeset);
  187.