Initial commit
[xorg_rtime.git] / xorg-server-1.4 / hw / kdrive / r128 / r128draw.c
blob142cc8b3e04e7f7b2f4d1d4c1a476c62266685f0
1 /*
2 * Copyright © 2003 Anders Carlsson
4 * Permission to use, copy, modify, distribute, and sell this software and its
5 * documentation for any purpose is hereby granted without fee, provided that
6 * the above copyright notice appear in all copies and that both that
7 * copyright notice and this permission notice appear in supporting
8 * documentation, and that the name of Anders Carlsson not be used in
9 * advertising or publicity pertaining to distribution of the software without
10 * specific, written prior permission. Anders Carlsson makes no
11 * representations about the suitability of this software for any purpose. It
12 * is provided "as is" without express or implied warranty.
14 * ANDERS CARLSSON DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
15 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
16 * EVENT SHALL ANDERS CARLSSON BE LIABLE FOR ANY SPECIAL, INDIRECT OR
17 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
18 * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
19 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
20 * PERFORMANCE OF THIS SOFTWARE.
22 #ifdef HAVE_CONFIG_H
23 #include <kdrive-config.h>
24 #endif
25 #include "r128.h"
26 #include "kaa.h"
28 CARD8 r128SolidRop[16] = {
29 /* GXclear */ 0x00, /* 0 */
30 /* GXand */ 0xa0, /* src AND dst */
31 /* GXandReverse */ 0x50, /* src AND NOT dst */
32 /* GXcopy */ 0xf0, /* src */
33 /* GXandInverted*/ 0x0a, /* NOT src AND dst */
34 /* GXnoop */ 0xaa, /* dst */
35 /* GXxor */ 0x5a, /* src XOR dst */
36 /* GXor */ 0xfa, /* src OR dst */
37 /* GXnor */ 0x05, /* NOT src AND NOT dst */
38 /* GXequiv */ 0xa5, /* NOT src XOR dst */
39 /* GXinvert */ 0x55, /* NOT dst */
40 /* GXorReverse */ 0xf5, /* src OR NOT dst */
41 /* GXcopyInverted*/ 0x0f, /* NOT src */
42 /* GXorInverted */ 0xaf, /* NOT src OR dst */
43 /* GXnand */ 0x5f, /* NOT src OR NOT dst */
44 /* GXset */ 0xff, /* 1 */
47 CARD8 r128BltRop[16] = {
48 /* GXclear */ 0x00, /* 0 */
49 /* GXand */ 0x88, /* src AND dst */
50 /* GXandReverse */ 0x44, /* src AND NOT dst */
51 /* GXcopy */ 0xcc, /* src */
52 /* GXandInverted*/ 0x22, /* NOT src AND dst */
53 /* GXnoop */ 0xaa, /* dst */
54 /* GXxor */ 0x66, /* src XOR dst */
55 /* GXor */ 0xee, /* src OR dst */
56 /* GXnor */ 0x11, /* NOT src AND NOT dst */
57 /* GXequiv */ 0x99, /* NOT src XOR dst */
58 /* GXinvert */ 0x55, /* NOT dst */
59 /* GXorReverse */ 0xdd, /* src OR NOT dst */
60 /* GXcopyInverted*/ 0x33, /* NOT src */
61 /* GXorInverted */ 0xbb, /* NOT src OR dst */
62 /* GXnand */ 0x77, /* NOT src OR NOT dst */
63 /* GXset */ 0xff, /* 1 */
66 int copydx, copydy;
67 int fifo_size;
68 char *mmio;
70 static void
71 r128WaitAvail (int n)
73 if (fifo_size < n)
75 while ((fifo_size = R128_IN32 (mmio, R128_REG_GUI_STAT) & 0xfff) < n)
79 fifo_size -= n;
82 static void
83 r128WaitIdle (void)
85 int tries;
87 r128WaitAvail (64);
89 tries = 1000000;
90 while (tries--)
92 if ((R128_IN32 (mmio, R128_REG_GUI_STAT) & R128_GUI_ACTIVE) == 0)
93 break;
96 R128_OUT32 (mmio, R128_REG_PC_NGUI_CTLSTAT,
97 R128_IN32 (mmio, R128_REG_PC_NGUI_CTLSTAT | 0xff));
99 tries = 1000000;
100 while (tries--)
102 if ((R128_IN32 (mmio, R128_REG_PC_NGUI_CTLSTAT) & R128_PC_BUSY) != R128_PC_BUSY)
103 break;
108 static void
109 r128WaitMarker (ScreenPtr pScreen, int marker)
111 KdScreenPriv (pScreen);
112 r128CardInfo (pScreenPriv);
114 mmio = r128c->reg_base;
116 r128WaitIdle ();
119 static Bool
120 r128Setup (ScreenPtr pScreen, int wait)
122 KdScreenPriv (pScreen);
123 r128ScreenInfo (pScreenPriv);
124 r128CardInfo (pScreenPriv);
126 fifo_size = 0;
128 mmio = r128c->reg_base;
130 if (!mmio)
131 return FALSE;
133 r128WaitAvail (2);
134 R128_OUT32 (mmio, R128_REG_DEFAULT_OFFSET, 0);
135 R128_OUT32 (mmio, R128_REG_DEFAULT_PITCH, r128s->pitch);
137 r128WaitAvail (4);
138 R128_OUT32 (mmio, R128_AUX_SC_CNTL, 0);
139 R128_OUT32 (mmio, R128_DEFAULT_SC_BOTTOM_RIGHT, (R128_DEFAULT_SC_RIGHT_MAX
140 | R128_DEFAULT_SC_BOTTOM_MAX));
141 R128_OUT32 (mmio, R128_SC_TOP_LEFT, 0);
142 R128_OUT32 (mmio, R128_SC_BOTTOM_RIGHT, (R128_DEFAULT_SC_RIGHT_MAX
143 | R128_DEFAULT_SC_BOTTOM_MAX));
144 r128WaitAvail (wait);
145 return TRUE;
148 static Bool
149 r128PrepareSolid (PixmapPtr pPixmap, int alu, Pixel pm, Pixel fg)
151 KdScreenPriv (pPixmap->drawable.pScreen);
152 r128ScreenInfo (pScreenPriv);
154 r128Setup (pPixmap->drawable.pScreen, 4);
155 R128_OUT32 (mmio, R128_REG_DP_GUI_MASTER_CNTL, r128s->dp_gui_master_cntl
156 | R128_GMC_BRUSH_SOLID_COLOR
157 | R128_GMC_SRC_DATATYPE_COLOR
158 | (r128SolidRop[alu] << R128_GMC_ROP3_SHIFT));
159 R128_OUT32 (mmio, R128_REG_DP_BRUSH_FRGD_CLR, fg);
160 R128_OUT32 (mmio, R128_REG_DP_WRITE_MASK, pm);
161 R128_OUT32 (mmio, R128_REG_DP_CNTL,
162 (R128_DST_X_LEFT_TO_RIGHT | R128_DST_Y_TOP_TO_BOTTOM));
164 return TRUE;
167 static void
168 r128Solid (int x1, int y1, int x2, int y2)
170 r128WaitAvail (2);
171 R128_OUT32 (mmio, R128_REG_DST_Y_X, (y1 << 16) | x1);
172 R128_OUT32 (mmio, R128_REG_DST_WIDTH_HEIGHT, ((x2 - x1) << 16) | (y2 - y1));
176 static void
177 r128DoneSolid (void)
181 static Bool
182 r128PrepareCopy (PixmapPtr pSrc, PixmapPtr pDst, int dx, int dy, int alu, Pixel pm)
184 KdScreenPriv (pSrc->drawable.pScreen);
185 r128ScreenInfo (pScreenPriv);
187 copydx = dx;
188 copydy = dy;
190 r128Setup (pSrc->drawable.pScreen, 3);
191 R128_OUT32 (mmio, R128_REG_DP_GUI_MASTER_CNTL, r128s->dp_gui_master_cntl
192 | R128_GMC_BRUSH_SOLID_COLOR
193 | R128_GMC_SRC_DATATYPE_COLOR
194 | (r128BltRop[alu] << R128_GMC_ROP3_SHIFT)
195 | R128_DP_SRC_SOURCE_MEMORY);
196 R128_OUT32 (mmio, R128_REG_DP_WRITE_MASK, pm);
197 R128_OUT32 (mmio, R128_REG_DP_CNTL,
198 ((dx >= 0 ? R128_DST_X_LEFT_TO_RIGHT : 0)
199 | (dy >= 0 ? R128_DST_Y_TOP_TO_BOTTOM : 0)));
202 return TRUE;
205 static void
206 r128Copy (int srcX, int srcY, int dstX, int dstY, int w, int h)
208 if (copydx < 0)
210 srcX += w - 1;
211 dstX += w - 1;
214 if (copydy < 0)
216 srcY += h - 1;
217 dstY += h - 1;
220 r128WaitAvail (3);
221 R128_OUT32 (mmio, R128_REG_SRC_Y_X, (srcY << 16) | srcX);
222 R128_OUT32 (mmio, R128_REG_DST_Y_X, (dstY << 16) | dstX);
223 R128_OUT32 (mmio, R128_REG_DST_HEIGHT_WIDTH, (h << 16) | w);
226 static void
227 r128DoneCopy (void)
232 Bool
233 r128DrawInit (ScreenPtr pScreen)
235 KdScreenPriv (pScreen);
236 r128ScreenInfo (pScreenPriv);
238 memset(&r128s->kaa, 0, sizeof(KaaScreenInfoRec));
239 r128s->kaa.waitMarker = r128WaitMarker;
240 r128s->kaa.PrepareSolid = r128PrepareSolid;
241 r128s->kaa.Solid = r128Solid;
242 r128s->kaa.DoneSolid = r128DoneSolid;
243 r128s->kaa.PrepareCopy = r128PrepareCopy;
244 r128s->kaa.Copy = r128Copy;
245 r128s->kaa.DoneCopy = r128DoneCopy;
247 if (!kaaDrawInit (pScreen, &r128s->kaa))
248 return FALSE;
250 return TRUE;
253 void
254 r128DrawEnable (ScreenPtr pScreen)
256 KdScreenPriv (pScreen);
257 r128ScreenInfo (pScreenPriv);
259 r128s->pitch = pScreenPriv->screen->width >> 3;
261 switch (pScreenPriv->screen->fb[0].depth) {
262 case 8:
263 r128s->datatype = 2;
264 break;
265 case 15:
266 r128s->datatype = 3;
267 break;
268 case 16:
269 r128s->datatype = 4;
270 break;
271 case 24:
272 r128s->datatype = 5;
273 break;
274 case 32:
275 r128s->datatype = 6;
276 break;
277 default:
278 FatalError ("unsupported pixel format");
281 r128s->dp_gui_master_cntl = ((r128s->datatype << R128_GMC_DST_DATATYPE_SHIFT)
282 | R128_GMC_CLR_CMP_CNTL_DIS
283 | R128_GMC_AUX_CLIP_DIS);
285 kaaMarkSync (pScreen);
288 void
289 r128DrawDisable (ScreenPtr pScreen)
293 void
294 r128DrawFini (ScreenPtr pScreen)