Subversion Repositories Kolibri OS

Rev

Rev 3480 | Rev 4104 | Go to most recent revision | Details | Compare with Previous | 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
 
3031 serge 36
#include 
1963 serge 37
#include 
38
//#include "drm_trace.h"
39
 
40
//#include    /* For task queue support */
41
#include 
42
 
43
//#include 
3031 serge 44
#include 
1963 serge 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
 
4075 Serge 62
irqreturn_t device_irq_handler(struct drm_device *dev)
63
{
64
 
65
    printf("video irq\n");
66
 
67
//    printf("device %p driver %p handler %p\n", dev, dev->driver, dev->driver->irq_handler) ;
68
 
69
    return dev->driver->irq_handler(0, dev);
70
}
71
 
72
/**
73
 * Install IRQ handler.
74
 *
75
 * \param dev DRM device.
76
 *
77
 * Initializes the IRQ related data. Installs the handler, calling the driver
78
 * \c irq_preinstall() and \c irq_postinstall() functions
79
 * before and after the installation.
80
 */
81
int drm_irq_install(struct drm_device *dev)
82
{
83
	int ret;
84
    unsigned long sh_flags = 0;
85
	char *irqname;
86
 
87
 
88
	if (drm_dev_to_irq(dev) == 0)
89
		return -EINVAL;
90
 
91
    mutex_lock(&dev->struct_mutex);
92
 
93
    /* Driver must have been initialized */
94
    if (!dev->dev_private) {
95
            mutex_unlock(&dev->struct_mutex);
96
            return -EINVAL;
97
    }
98
 
99
    if (dev->irq_enabled) {
100
            mutex_unlock(&dev->struct_mutex);
101
            return -EBUSY;
102
    }
103
    dev->irq_enabled = 1;
104
    mutex_unlock(&dev->struct_mutex);
105
 
106
    DRM_DEBUG("irq=%d\n", drm_dev_to_irq(dev));
107
 
108
    /* Before installing handler */
109
    if (dev->driver->irq_preinstall)
110
            dev->driver->irq_preinstall(dev);
111
 
112
    ret = !AttachIntHandler(drm_dev_to_irq(dev), device_irq_handler, (u32)dev);
113
 
114
    /* After installing handler */
115
    if (dev->driver->irq_postinstall)
116
            ret = dev->driver->irq_postinstall(dev);
117
 
118
    if (ret < 0) {
119
            DRM_ERROR(__FUNCTION__);
120
    }
121
 
122
    u16_t cmd = PciRead16(dev->pdev->busnr, dev->pdev->devfn, 4);
123
    cmd&= ~(1<<10);
124
    PciWrite16(dev->pdev->busnr, dev->pdev->devfn, 4, cmd);
125
 
126
    return ret;
127
}
128
EXPORT_SYMBOL(drm_irq_install);
129
 
130
 
1963 serge 131
static inline u64 div_u64(u64 dividend, u32 divisor)
132
{
133
        u32 remainder;
134
        return div_u64_rem(dividend, divisor, &remainder);
135
}
136
 
137
 
138
u64 div64_u64(u64 dividend, u64 divisor)
139
{
140
        u32 high, d;
141
 
142
        high = divisor >> 32;
143
        if (high) {
144
                unsigned int shift = fls(high);
145
 
146
                d = divisor >> shift;
147
                dividend >>= shift;
148
        } else
149
                d = divisor;
150
 
151
        return div_u64(dividend, d);
152
}
153
 
154
/**
155
 * drm_calc_timestamping_constants - Calculate and
156
 * store various constants which are later needed by
157
 * vblank and swap-completion timestamping, e.g, by
158
 * drm_calc_vbltimestamp_from_scanoutpos().
159
 * They are derived from crtc's true scanout timing,
160
 * so they take things like panel scaling or other
161
 * adjustments into account.
162
 *
163
 * @crtc drm_crtc whose timestamp constants should be updated.
164
 *
165
 */
166
void drm_calc_timestamping_constants(struct drm_crtc *crtc)
167
{
168
	s64 linedur_ns = 0, pixeldur_ns = 0, framedur_ns = 0;
169
	u64 dotclock;
170
 
171
	/* Dot clock in Hz: */
172
	dotclock = (u64) crtc->hwmode.clock * 1000;
173
 
174
	/* Fields of interlaced scanout modes are only halve a frame duration.
175
	 * Double the dotclock to get halve the frame-/line-/pixelduration.
176
	 */
177
	if (crtc->hwmode.flags & DRM_MODE_FLAG_INTERLACE)
178
		dotclock *= 2;
179
 
180
	/* Valid dotclock? */
181
	if (dotclock > 0) {
3480 Serge 182
		int frame_size;
1963 serge 183
		/* Convert scanline length in pixels and video dot clock to
184
		 * line duration, frame duration and pixel duration in
185
		 * nanoseconds:
186
		 */
187
		pixeldur_ns = (s64) div64_u64(1000000000, dotclock);
188
		linedur_ns  = (s64) div64_u64(((u64) crtc->hwmode.crtc_htotal *
189
					      1000000000), dotclock);
3480 Serge 190
		frame_size = crtc->hwmode.crtc_htotal *
191
				crtc->hwmode.crtc_vtotal;
192
		framedur_ns = (s64) div64_u64((u64) frame_size * 1000000000,
193
					      dotclock);
1963 serge 194
	} else
195
		DRM_ERROR("crtc %d: Can't calculate constants, dotclock = 0!\n",
196
			  crtc->base.id);
197
 
198
	crtc->pixeldur_ns = pixeldur_ns;
199
	crtc->linedur_ns  = linedur_ns;
200
	crtc->framedur_ns = framedur_ns;
201
 
202
	DRM_DEBUG("crtc %d: hwmode: htotal %d, vtotal %d, vdisplay %d\n",
203
		  crtc->base.id, crtc->hwmode.crtc_htotal,
204
		  crtc->hwmode.crtc_vtotal, crtc->hwmode.crtc_vdisplay);
205
	DRM_DEBUG("crtc %d: clock %d kHz framedur %d linedur %d, pixeldur %d\n",
206
		  crtc->base.id, (int) dotclock/1000, (int) framedur_ns,
207
		  (int) linedur_ns, (int) pixeldur_ns);
208
}
209
 
3031 serge 210
 
211
/**
212
 * drm_vblank_pre_modeset - account for vblanks across mode sets
213
 * @dev: DRM device
214
 * @crtc: CRTC in question
215
 *
216
 * Account for vblank events across mode setting events, which will likely
217
 * reset the hardware frame counter.
218
 */
219
void drm_vblank_pre_modeset(struct drm_device *dev, int crtc)
220
{
221
#if 0
222
    /* vblank is not initialized (IRQ not installed ?) */
223
    if (!dev->num_crtcs)
224
        return;
225
    /*
226
     * To avoid all the problems that might happen if interrupts
227
     * were enabled/disabled around or between these calls, we just
228
     * have the kernel take a reference on the CRTC (just once though
229
     * to avoid corrupting the count if multiple, mismatch calls occur),
230
     * so that interrupts remain enabled in the interim.
231
     */
232
    if (!dev->vblank_inmodeset[crtc]) {
233
        dev->vblank_inmodeset[crtc] = 0x1;
234
        if (drm_vblank_get(dev, crtc) == 0)
235
            dev->vblank_inmodeset[crtc] |= 0x2;
236
    }
237
#endif
238
}
239
EXPORT_SYMBOL(drm_vblank_pre_modeset);
240
 
241
void drm_vblank_post_modeset(struct drm_device *dev, int crtc)
242
{
243
#if 0
244
    unsigned long irqflags;
245
 
4075 Serge 246
	/* vblank is not initialized (IRQ not installed ?), or has been freed */
247
	if (!dev->num_crtcs)
248
		return;
249
 
3031 serge 250
    if (dev->vblank_inmodeset[crtc]) {
251
        spin_lock_irqsave(&dev->vbl_lock, irqflags);
252
        dev->vblank_disable_allowed = 1;
253
        spin_unlock_irqrestore(&dev->vbl_lock, irqflags);
254
 
255
        if (dev->vblank_inmodeset[crtc] & 0x2)
256
            drm_vblank_put(dev, crtc);
257
 
258
        dev->vblank_inmodeset[crtc] = 0;
259
    }
260
#endif
261
}
262
EXPORT_SYMBOL(drm_vblank_post_modeset);
4075 Serge 263
 
264
 
265