Subversion Repositories Kolibri OS

Rev

Rev 4075 | Rev 4539 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 4075 Rev 4104
1
/**
1
/**
2
 * \file drm_irq.c
2
 * \file drm_irq.c
3
 * IRQ support
3
 * IRQ support
4
 *
4
 *
5
 * \author Rickard E. (Rik) Faith 
5
 * \author Rickard E. (Rik) Faith 
6
 * \author Gareth Hughes 
6
 * \author Gareth Hughes 
7
 */
7
 */
8
 
8
 
9
/*
9
/*
10
 * Created: Fri Mar 19 14:30:16 1999 by faith@valinux.com
10
 * Created: Fri Mar 19 14:30:16 1999 by faith@valinux.com
11
 *
11
 *
12
 * Copyright 1999, 2000 Precision Insight, Inc., Cedar Park, Texas.
12
 * Copyright 1999, 2000 Precision Insight, Inc., Cedar Park, Texas.
13
 * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
13
 * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
14
 * All Rights Reserved.
14
 * All Rights Reserved.
15
 *
15
 *
16
 * Permission is hereby granted, free of charge, to any person obtaining a
16
 * Permission is hereby granted, free of charge, to any person obtaining a
17
 * copy of this software and associated documentation files (the "Software"),
17
 * copy of this software and associated documentation files (the "Software"),
18
 * to deal in the Software without restriction, including without limitation
18
 * to deal in the Software without restriction, including without limitation
19
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
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
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:
21
 * Software is furnished to do so, subject to the following conditions:
22
 *
22
 *
23
 * The above copyright notice and this permission notice (including the next
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
24
 * paragraph) shall be included in all copies or substantial portions of the
25
 * Software.
25
 * Software.
26
 *
26
 *
27
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
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,
28
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
29
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
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
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,
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
32
 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
33
 * OTHER DEALINGS IN THE SOFTWARE.
33
 * OTHER DEALINGS IN THE SOFTWARE.
34
 */
34
 */
35
 
35
 
36
#include 
36
#include 
37
#include 
37
#include 
38
//#include "drm_trace.h"
38
//#include "drm_trace.h"
39
 
39
 
40
//#include    /* For task queue support */
40
//#include    /* For task queue support */
41
#include 
41
#include 
42
 
42
 
43
//#include 
43
//#include 
44
#include 
44
#include 
45
 
45
 
46
/* Access macro for slots in vblank timestamp ringbuffer. */
46
/* Access macro for slots in vblank timestamp ringbuffer. */
47
#define vblanktimestamp(dev, crtc, count) ( \
47
#define vblanktimestamp(dev, crtc, count) ( \
48
	(dev)->_vblank_time[(crtc) * DRM_VBLANKTIME_RBSIZE + \
48
	(dev)->_vblank_time[(crtc) * DRM_VBLANKTIME_RBSIZE + \
49
	((count) % DRM_VBLANKTIME_RBSIZE)])
49
	((count) % DRM_VBLANKTIME_RBSIZE)])
50
 
50
 
51
/* Retry timestamp calculation up to 3 times to satisfy
51
/* Retry timestamp calculation up to 3 times to satisfy
52
 * drm_timestamp_precision before giving up.
52
 * drm_timestamp_precision before giving up.
53
 */
53
 */
54
#define DRM_TIMESTAMP_MAXRETRIES 3
54
#define DRM_TIMESTAMP_MAXRETRIES 3
55
 
55
 
56
/* Threshold in nanoseconds for detection of redundant
56
/* Threshold in nanoseconds for detection of redundant
57
 * vblank irq in drm_handle_vblank(). 1 msec should be ok.
57
 * vblank irq in drm_handle_vblank(). 1 msec should be ok.
58
 */
58
 */
59
#define DRM_REDUNDANT_VBLIRQ_THRESH_NS 1000000
59
#define DRM_REDUNDANT_VBLIRQ_THRESH_NS 1000000
60
 
60
 
61
 
61
 
62
irqreturn_t device_irq_handler(struct drm_device *dev)
62
irqreturn_t device_irq_handler(struct drm_device *dev)
63
{
63
{
64
 
64
 
65
    printf("video irq\n");
65
//    printf("video irq\n");
66
 
66
 
67
//    printf("device %p driver %p handler %p\n", dev, dev->driver, dev->driver->irq_handler) ;
67
//    printf("device %p driver %p handler %p\n", dev, dev->driver, dev->driver->irq_handler) ;
68
 
68
 
69
    return dev->driver->irq_handler(0, dev);
69
    return dev->driver->irq_handler(0, dev);
70
}
70
}
71
 
71
 
72
/**
72
/**
73
 * Install IRQ handler.
73
 * Install IRQ handler.
74
 *
74
 *
75
 * \param dev DRM device.
75
 * \param dev DRM device.
76
 *
76
 *
77
 * Initializes the IRQ related data. Installs the handler, calling the driver
77
 * Initializes the IRQ related data. Installs the handler, calling the driver
78
 * \c irq_preinstall() and \c irq_postinstall() functions
78
 * \c irq_preinstall() and \c irq_postinstall() functions
79
 * before and after the installation.
79
 * before and after the installation.
80
 */
80
 */
81
int drm_irq_install(struct drm_device *dev)
81
int drm_irq_install(struct drm_device *dev)
82
{
82
{
83
	int ret;
83
	int ret;
84
    unsigned long sh_flags = 0;
84
    unsigned long sh_flags = 0;
85
	char *irqname;
85
	char *irqname;
86
 
86
 
87
 
87
 
88
	if (drm_dev_to_irq(dev) == 0)
88
	if (drm_dev_to_irq(dev) == 0)
89
		return -EINVAL;
89
		return -EINVAL;
90
 
90
 
91
    mutex_lock(&dev->struct_mutex);
91
    mutex_lock(&dev->struct_mutex);
92
 
92
 
93
    /* Driver must have been initialized */
93
    /* Driver must have been initialized */
94
    if (!dev->dev_private) {
94
    if (!dev->dev_private) {
95
            mutex_unlock(&dev->struct_mutex);
95
            mutex_unlock(&dev->struct_mutex);
96
            return -EINVAL;
96
            return -EINVAL;
97
    }
97
    }
98
 
98
 
99
    if (dev->irq_enabled) {
99
    if (dev->irq_enabled) {
100
            mutex_unlock(&dev->struct_mutex);
100
            mutex_unlock(&dev->struct_mutex);
101
            return -EBUSY;
101
            return -EBUSY;
102
    }
102
    }
103
    dev->irq_enabled = 1;
103
    dev->irq_enabled = 1;
104
    mutex_unlock(&dev->struct_mutex);
104
    mutex_unlock(&dev->struct_mutex);
105
 
105
 
106
    DRM_DEBUG("irq=%d\n", drm_dev_to_irq(dev));
106
    DRM_DEBUG("irq=%d\n", drm_dev_to_irq(dev));
107
 
107
 
108
    /* Before installing handler */
108
    /* Before installing handler */
109
    if (dev->driver->irq_preinstall)
109
    if (dev->driver->irq_preinstall)
110
            dev->driver->irq_preinstall(dev);
110
            dev->driver->irq_preinstall(dev);
111
 
111
 
112
    ret = !AttachIntHandler(drm_dev_to_irq(dev), device_irq_handler, (u32)dev);
112
    ret = !AttachIntHandler(drm_dev_to_irq(dev), device_irq_handler, (u32)dev);
113
 
113
 
114
    /* After installing handler */
114
    /* After installing handler */
115
    if (dev->driver->irq_postinstall)
115
    if (dev->driver->irq_postinstall)
116
            ret = dev->driver->irq_postinstall(dev);
116
            ret = dev->driver->irq_postinstall(dev);
117
 
117
 
118
    if (ret < 0) {
118
    if (ret < 0) {
-
 
119
		dev->irq_enabled = 0;
119
            DRM_ERROR(__FUNCTION__);
120
            DRM_ERROR(__FUNCTION__);
120
    }
121
    }
121
 
122
 
122
    u16_t cmd = PciRead16(dev->pdev->busnr, dev->pdev->devfn, 4);
123
    u16_t cmd = PciRead16(dev->pdev->busnr, dev->pdev->devfn, 4);
123
    cmd&= ~(1<<10);
124
    cmd&= ~(1<<10);
124
    PciWrite16(dev->pdev->busnr, dev->pdev->devfn, 4, cmd);
125
    PciWrite16(dev->pdev->busnr, dev->pdev->devfn, 4, cmd);
125
 
126
 
126
    return ret;
127
    return ret;
127
}
128
}
128
EXPORT_SYMBOL(drm_irq_install);
129
EXPORT_SYMBOL(drm_irq_install);
129
 
130
 
130
 
-
 
131
static inline u64 div_u64(u64 dividend, u32 divisor)
-
 
132
{
-
 
133
        u32 remainder;
-
 
134
        return div_u64_rem(dividend, divisor, &remainder);
-
 
135
}
131
 
136
 
132
 
137
 
133
 
138
u64 div64_u64(u64 dividend, u64 divisor)
134
u64 div64_u64(u64 dividend, u64 divisor)
139
{
135
{
140
        u32 high, d;
136
        u32 high, d;
141
 
137
 
142
        high = divisor >> 32;
138
        high = divisor >> 32;
143
        if (high) {
139
        if (high) {
144
                unsigned int shift = fls(high);
140
                unsigned int shift = fls(high);
145
 
141
 
146
                d = divisor >> shift;
142
                d = divisor >> shift;
147
                dividend >>= shift;
143
                dividend >>= shift;
148
        } else
144
        } else
149
                d = divisor;
145
                d = divisor;
150
 
146
 
151
        return div_u64(dividend, d);
147
        return div_u64(dividend, d);
152
}
148
}
153
 
149
 
154
/**
150
/**
155
 * drm_calc_timestamping_constants - Calculate and
151
 * drm_calc_timestamping_constants - Calculate and
156
 * store various constants which are later needed by
152
 * store various constants which are later needed by
157
 * vblank and swap-completion timestamping, e.g, by
153
 * vblank and swap-completion timestamping, e.g, by
158
 * drm_calc_vbltimestamp_from_scanoutpos().
154
 * drm_calc_vbltimestamp_from_scanoutpos().
159
 * They are derived from crtc's true scanout timing,
155
 * They are derived from crtc's true scanout timing,
160
 * so they take things like panel scaling or other
156
 * so they take things like panel scaling or other
161
 * adjustments into account.
157
 * adjustments into account.
162
 *
158
 *
163
 * @crtc drm_crtc whose timestamp constants should be updated.
159
 * @crtc drm_crtc whose timestamp constants should be updated.
164
 *
160
 *
165
 */
161
 */
166
void drm_calc_timestamping_constants(struct drm_crtc *crtc)
162
void drm_calc_timestamping_constants(struct drm_crtc *crtc)
167
{
163
{
168
	s64 linedur_ns = 0, pixeldur_ns = 0, framedur_ns = 0;
164
	s64 linedur_ns = 0, pixeldur_ns = 0, framedur_ns = 0;
169
	u64 dotclock;
165
	u64 dotclock;
170
 
166
 
171
	/* Dot clock in Hz: */
167
	/* Dot clock in Hz: */
172
	dotclock = (u64) crtc->hwmode.clock * 1000;
168
	dotclock = (u64) crtc->hwmode.clock * 1000;
173
 
169
 
174
	/* Fields of interlaced scanout modes are only halve a frame duration.
170
	/* Fields of interlaced scanout modes are only halve a frame duration.
175
	 * Double the dotclock to get halve the frame-/line-/pixelduration.
171
	 * Double the dotclock to get halve the frame-/line-/pixelduration.
176
	 */
172
	 */
177
	if (crtc->hwmode.flags & DRM_MODE_FLAG_INTERLACE)
173
	if (crtc->hwmode.flags & DRM_MODE_FLAG_INTERLACE)
178
		dotclock *= 2;
174
		dotclock *= 2;
179
 
175
 
180
	/* Valid dotclock? */
176
	/* Valid dotclock? */
181
	if (dotclock > 0) {
177
	if (dotclock > 0) {
182
		int frame_size;
178
		int frame_size;
183
		/* Convert scanline length in pixels and video dot clock to
179
		/* Convert scanline length in pixels and video dot clock to
184
		 * line duration, frame duration and pixel duration in
180
		 * line duration, frame duration and pixel duration in
185
		 * nanoseconds:
181
		 * nanoseconds:
186
		 */
182
		 */
187
		pixeldur_ns = (s64) div64_u64(1000000000, dotclock);
183
		pixeldur_ns = (s64) div64_u64(1000000000, dotclock);
188
		linedur_ns  = (s64) div64_u64(((u64) crtc->hwmode.crtc_htotal *
184
		linedur_ns  = (s64) div64_u64(((u64) crtc->hwmode.crtc_htotal *
189
					      1000000000), dotclock);
185
					      1000000000), dotclock);
190
		frame_size = crtc->hwmode.crtc_htotal *
186
		frame_size = crtc->hwmode.crtc_htotal *
191
				crtc->hwmode.crtc_vtotal;
187
				crtc->hwmode.crtc_vtotal;
192
		framedur_ns = (s64) div64_u64((u64) frame_size * 1000000000,
188
		framedur_ns = (s64) div64_u64((u64) frame_size * 1000000000,
193
					      dotclock);
189
					      dotclock);
194
	} else
190
	} else
195
		DRM_ERROR("crtc %d: Can't calculate constants, dotclock = 0!\n",
191
		DRM_ERROR("crtc %d: Can't calculate constants, dotclock = 0!\n",
196
			  crtc->base.id);
192
			  crtc->base.id);
197
 
193
 
198
	crtc->pixeldur_ns = pixeldur_ns;
194
	crtc->pixeldur_ns = pixeldur_ns;
199
	crtc->linedur_ns  = linedur_ns;
195
	crtc->linedur_ns  = linedur_ns;
200
	crtc->framedur_ns = framedur_ns;
196
	crtc->framedur_ns = framedur_ns;
201
 
197
 
202
	DRM_DEBUG("crtc %d: hwmode: htotal %d, vtotal %d, vdisplay %d\n",
198
	DRM_DEBUG("crtc %d: hwmode: htotal %d, vtotal %d, vdisplay %d\n",
203
		  crtc->base.id, crtc->hwmode.crtc_htotal,
199
		  crtc->base.id, crtc->hwmode.crtc_htotal,
204
		  crtc->hwmode.crtc_vtotal, crtc->hwmode.crtc_vdisplay);
200
		  crtc->hwmode.crtc_vtotal, crtc->hwmode.crtc_vdisplay);
205
	DRM_DEBUG("crtc %d: clock %d kHz framedur %d linedur %d, pixeldur %d\n",
201
	DRM_DEBUG("crtc %d: clock %d kHz framedur %d linedur %d, pixeldur %d\n",
206
		  crtc->base.id, (int) dotclock/1000, (int) framedur_ns,
202
		  crtc->base.id, (int) dotclock/1000, (int) framedur_ns,
207
		  (int) linedur_ns, (int) pixeldur_ns);
203
		  (int) linedur_ns, (int) pixeldur_ns);
208
}
204
}
209
 
205
 
210
 
206
 
211
/**
207
/**
212
 * drm_vblank_pre_modeset - account for vblanks across mode sets
208
 * drm_vblank_pre_modeset - account for vblanks across mode sets
213
 * @dev: DRM device
209
 * @dev: DRM device
214
 * @crtc: CRTC in question
210
 * @crtc: CRTC in question
215
 *
211
 *
216
 * Account for vblank events across mode setting events, which will likely
212
 * Account for vblank events across mode setting events, which will likely
217
 * reset the hardware frame counter.
213
 * reset the hardware frame counter.
218
 */
214
 */
219
void drm_vblank_pre_modeset(struct drm_device *dev, int crtc)
215
void drm_vblank_pre_modeset(struct drm_device *dev, int crtc)
220
{
216
{
221
#if 0
217
#if 0
222
    /* vblank is not initialized (IRQ not installed ?) */
218
    /* vblank is not initialized (IRQ not installed ?) */
223
    if (!dev->num_crtcs)
219
    if (!dev->num_crtcs)
224
        return;
220
        return;
225
    /*
221
    /*
226
     * To avoid all the problems that might happen if interrupts
222
     * To avoid all the problems that might happen if interrupts
227
     * were enabled/disabled around or between these calls, we just
223
     * were enabled/disabled around or between these calls, we just
228
     * have the kernel take a reference on the CRTC (just once though
224
     * have the kernel take a reference on the CRTC (just once though
229
     * to avoid corrupting the count if multiple, mismatch calls occur),
225
     * to avoid corrupting the count if multiple, mismatch calls occur),
230
     * so that interrupts remain enabled in the interim.
226
     * so that interrupts remain enabled in the interim.
231
     */
227
     */
232
    if (!dev->vblank_inmodeset[crtc]) {
228
    if (!dev->vblank_inmodeset[crtc]) {
233
        dev->vblank_inmodeset[crtc] = 0x1;
229
        dev->vblank_inmodeset[crtc] = 0x1;
234
        if (drm_vblank_get(dev, crtc) == 0)
230
        if (drm_vblank_get(dev, crtc) == 0)
235
            dev->vblank_inmodeset[crtc] |= 0x2;
231
            dev->vblank_inmodeset[crtc] |= 0x2;
236
    }
232
    }
237
#endif
233
#endif
238
}
234
}
239
EXPORT_SYMBOL(drm_vblank_pre_modeset);
235
EXPORT_SYMBOL(drm_vblank_pre_modeset);
240
 
236
 
241
void drm_vblank_post_modeset(struct drm_device *dev, int crtc)
237
void drm_vblank_post_modeset(struct drm_device *dev, int crtc)
242
{
238
{
243
#if 0
239
#if 0
244
    unsigned long irqflags;
240
    unsigned long irqflags;
245
 
241
 
246
	/* vblank is not initialized (IRQ not installed ?), or has been freed */
242
	/* vblank is not initialized (IRQ not installed ?), or has been freed */
247
	if (!dev->num_crtcs)
243
	if (!dev->num_crtcs)
248
		return;
244
		return;
249
 
245
 
250
    if (dev->vblank_inmodeset[crtc]) {
246
    if (dev->vblank_inmodeset[crtc]) {
251
        spin_lock_irqsave(&dev->vbl_lock, irqflags);
247
        spin_lock_irqsave(&dev->vbl_lock, irqflags);
252
        dev->vblank_disable_allowed = 1;
248
        dev->vblank_disable_allowed = 1;
253
        spin_unlock_irqrestore(&dev->vbl_lock, irqflags);
249
        spin_unlock_irqrestore(&dev->vbl_lock, irqflags);
254
 
250
 
255
        if (dev->vblank_inmodeset[crtc] & 0x2)
251
        if (dev->vblank_inmodeset[crtc] & 0x2)
256
            drm_vblank_put(dev, crtc);
252
            drm_vblank_put(dev, crtc);
257
 
253
 
258
        dev->vblank_inmodeset[crtc] = 0;
254
        dev->vblank_inmodeset[crtc] = 0;
259
    }
255
    }
260
#endif
256
#endif
261
}
257
}
262
EXPORT_SYMBOL(drm_vblank_post_modeset);
258
EXPORT_SYMBOL(drm_vblank_post_modeset);
263
>
-
 
264
>
-
 
265
-
 
266
-
 
-
 
259
>
-
 
260
>