OSDN Git Service

Merge branch 'ttm-vram-0-1-branch'
[android-x86/external-libdrm.git] / shared-core / mach64_irq.c
1 /* mach64_irq.c -- IRQ handling for ATI Mach64 -*- linux-c -*-
2  * Created: Tue Feb 25, 2003 by Leif Delgass, based on radeon_irq.c/r128_irq.c
3  */
4 /*-
5  * Copyright (C) The Weather Channel, Inc.  2002.
6  * Copyright 2003 Leif Delgass
7  * All Rights Reserved.
8  *
9  * The Weather Channel (TM) funded Tungsten Graphics to develop the
10  * initial release of the Radeon 8500 driver under the XFree86 license.
11  * This notice must be preserved.
12  *
13  * Permission is hereby granted, free of charge, to any person obtaining a
14  * copy of this software and associated documentation files (the "Software"),
15  * to deal in the Software without restriction, including without limitation
16  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
17  * and/or sell copies of the Software, and to permit persons to whom the
18  * Software is furnished to do so, subject to the following conditions:
19  *
20  * The above copyright notice and this permission notice (including the next
21  * paragraph) shall be included in all copies or substantial portions of the
22  * Software.
23  *
24  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
25  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
26  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
27  * THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
28  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
29  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
30  * DEALINGS IN THE SOFTWARE.
31  *
32  * Authors:
33  *    Keith Whitwell <keith@tungstengraphics.com>
34  *    Eric Anholt <anholt@FreeBSD.org>
35  *    Leif Delgass <ldelgass@retinalburn.net>
36  */
37
38 #include "drmP.h"
39 #include "drm.h"
40 #include "mach64_drm.h"
41 #include "mach64_drv.h"
42
43 irqreturn_t mach64_driver_irq_handler(DRM_IRQ_ARGS)
44 {
45         drm_device_t *dev = (drm_device_t *) arg;
46         drm_mach64_private_t *dev_priv =
47             (drm_mach64_private_t *) dev->dev_private;
48         int status;
49
50         status = MACH64_READ(MACH64_CRTC_INT_CNTL);
51
52         /* VBLANK interrupt */
53         if (status & MACH64_CRTC_VBLANK_INT) {
54                 /* Mask off all interrupt ack bits before setting the ack bit, since
55                  * there may be other handlers outside the DRM.
56                  *
57                  * NOTE: On mach64, you need to keep the enable bits set when doing
58                  * the ack, despite what the docs say about not acking and enabling
59                  * in a single write.
60                  */
61                 MACH64_WRITE(MACH64_CRTC_INT_CNTL,
62                              (status & ~MACH64_CRTC_INT_ACKS)
63                              | MACH64_CRTC_VBLANK_INT);
64
65                 atomic_inc(&dev->vbl_received);
66                 DRM_WAKEUP(&dev->vbl_queue);
67                 drm_vbl_send_signals(dev);
68                 return IRQ_HANDLED;
69         }
70         return IRQ_NONE;
71 }
72
73 int mach64_driver_vblank_wait(drm_device_t * dev, unsigned int *sequence)
74 {
75         unsigned int cur_vblank;
76         int ret = 0;
77
78         /* Assume that the user has missed the current sequence number
79          * by about a day rather than she wants to wait for years
80          * using vertical blanks...
81          */
82         DRM_WAIT_ON(ret, dev->vbl_queue, 3 * DRM_HZ,
83                     (((cur_vblank = atomic_read(&dev->vbl_received))
84                       - *sequence) <= (1 << 23)));
85
86         *sequence = cur_vblank;
87
88         return ret;
89 }
90
91 /* drm_dma.h hooks
92 */
93 void mach64_driver_irq_preinstall(drm_device_t * dev)
94 {
95         drm_mach64_private_t *dev_priv =
96             (drm_mach64_private_t *) dev->dev_private;
97
98         u32 status = MACH64_READ(MACH64_CRTC_INT_CNTL);
99
100         DRM_DEBUG("before install CRTC_INT_CTNL: 0x%08x\n", status);
101
102         /* Disable and clear VBLANK interrupt */
103         MACH64_WRITE(MACH64_CRTC_INT_CNTL, (status & ~MACH64_CRTC_VBLANK_INT_EN)
104                      | MACH64_CRTC_VBLANK_INT);
105 }
106
107 void mach64_driver_irq_postinstall(drm_device_t * dev)
108 {
109         drm_mach64_private_t *dev_priv =
110             (drm_mach64_private_t *) dev->dev_private;
111
112         /* Turn on VBLANK interrupt */
113         MACH64_WRITE(MACH64_CRTC_INT_CNTL, MACH64_READ(MACH64_CRTC_INT_CNTL)
114                      | MACH64_CRTC_VBLANK_INT_EN);
115
116         DRM_DEBUG("after install CRTC_INT_CTNL: 0x%08x\n",
117                   MACH64_READ(MACH64_CRTC_INT_CNTL));
118
119 }
120
121 void mach64_driver_irq_uninstall(drm_device_t * dev)
122 {
123         drm_mach64_private_t *dev_priv =
124             (drm_mach64_private_t *) dev->dev_private;
125         if (!dev_priv)
126                 return;
127
128         /* Disable and clear VBLANK interrupt */
129         MACH64_WRITE(MACH64_CRTC_INT_CNTL,
130                      (MACH64_READ(MACH64_CRTC_INT_CNTL) &
131                       ~MACH64_CRTC_VBLANK_INT_EN)
132                      | MACH64_CRTC_VBLANK_INT);
133
134         DRM_DEBUG("after uninstall CRTC_INT_CTNL: 0x%08x\n",
135                   MACH64_READ(MACH64_CRTC_INT_CNTL));
136 }