Subversion Repositories Kolibri OS

Rev

Rev 3031 | Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1963 serge 1
/**
2
 * \file drm_irq.c
3
 * IRQ support
4
 *
5
 * \author Rickard E. (Rik) Faith 
6
 * \author Gareth Hughes 
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 "drmP.h"
37
#include 
38
//#include "drm_trace.h"
39
 
40
//#include    /* For task queue support */
41
#include 
42
 
43
//#include 
44
 
45
/* Access macro for slots in vblank timestamp ringbuffer. */
46
#define vblanktimestamp(dev, crtc, count) ( \
47
	(dev)->_vblank_time[(crtc) * DRM_VBLANKTIME_RBSIZE + \
48
	((count) % DRM_VBLANKTIME_RBSIZE)])
49
 
50
/* Retry timestamp calculation up to 3 times to satisfy
51
 * drm_timestamp_precision before giving up.
52
 */
53
#define DRM_TIMESTAMP_MAXRETRIES 3
54
 
55
/* Threshold in nanoseconds for detection of redundant
56
 * vblank irq in drm_handle_vblank(). 1 msec should be ok.
57
 */
58
#define DRM_REDUNDANT_VBLIRQ_THRESH_NS 1000000
59
 
60
 
61
static inline u64 div_u64(u64 dividend, u32 divisor)
62
{
63
        u32 remainder;
64
        return div_u64_rem(dividend, divisor, &remainder);
65
}
66
 
67
 
68
u64 div64_u64(u64 dividend, u64 divisor)
69
{
70
        u32 high, d;
71
 
72
        high = divisor >> 32;
73
        if (high) {
74
                unsigned int shift = fls(high);
75
 
76
                d = divisor >> shift;
77
                dividend >>= shift;
78
        } else
79
                d = divisor;
80
 
81
        return div_u64(dividend, d);
82
}
83
 
84
 
85
/**
86
 * drm_calc_timestamping_constants - Calculate and
87
 * store various constants which are later needed by
88
 * vblank and swap-completion timestamping, e.g, by
89
 * drm_calc_vbltimestamp_from_scanoutpos().
90
 * They are derived from crtc's true scanout timing,
91
 * so they take things like panel scaling or other
92
 * adjustments into account.
93
 *
94
 * @crtc drm_crtc whose timestamp constants should be updated.
95
 *
96
 */
97
void drm_calc_timestamping_constants(struct drm_crtc *crtc)
98
{
99
	s64 linedur_ns = 0, pixeldur_ns = 0, framedur_ns = 0;
100
	u64 dotclock;
101
 
102
	/* Dot clock in Hz: */
103
	dotclock = (u64) crtc->hwmode.clock * 1000;
104
 
105
	/* Fields of interlaced scanout modes are only halve a frame duration.
106
	 * Double the dotclock to get halve the frame-/line-/pixelduration.
107
	 */
108
	if (crtc->hwmode.flags & DRM_MODE_FLAG_INTERLACE)
109
		dotclock *= 2;
110
 
111
	/* Valid dotclock? */
112
	if (dotclock > 0) {
113
		/* Convert scanline length in pixels and video dot clock to
114
		 * line duration, frame duration and pixel duration in
115
		 * nanoseconds:
116
		 */
117
		pixeldur_ns = (s64) div64_u64(1000000000, dotclock);
118
		linedur_ns  = (s64) div64_u64(((u64) crtc->hwmode.crtc_htotal *
119
					      1000000000), dotclock);
120
		framedur_ns = (s64) crtc->hwmode.crtc_vtotal * linedur_ns;
121
	} else
122
		DRM_ERROR("crtc %d: Can't calculate constants, dotclock = 0!\n",
123
			  crtc->base.id);
124
 
125
	crtc->pixeldur_ns = pixeldur_ns;
126
	crtc->linedur_ns  = linedur_ns;
127
	crtc->framedur_ns = framedur_ns;
128
 
129
	DRM_DEBUG("crtc %d: hwmode: htotal %d, vtotal %d, vdisplay %d\n",
130
		  crtc->base.id, crtc->hwmode.crtc_htotal,
131
		  crtc->hwmode.crtc_vtotal, crtc->hwmode.crtc_vdisplay);
132
	DRM_DEBUG("crtc %d: clock %d kHz framedur %d linedur %d, pixeldur %d\n",
133
		  crtc->base.id, (int) dotclock/1000, (int) framedur_ns,
134
		  (int) linedur_ns, (int) pixeldur_ns);
135
}
136