First import
[xorg_rtime.git] / xorg-server-1.4 / hw / kdrive / smi / smidraw.c
blobba4e3904d4efffbf27d5eb25b34d34a5b0349e5a
1 /*
2 * Copyright © 1999 Keith Packard
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 Keith Packard not be used in
9 * advertising or publicity pertaining to distribution of the software without
10 * specific, written prior permission. Keith Packard 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 * KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
15 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
16 * EVENT SHALL KEITH PACKARD 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.
23 #ifdef HAVE_CONFIG_H
24 #include <kdrive-config.h>
25 #endif
26 #include "smi.h"
27 #include "smidraw.h"
29 #include <X11/Xmd.h>
30 #include "gcstruct.h"
31 #include "scrnintstr.h"
32 #include "pixmapstr.h"
33 #include "regionstr.h"
34 #include "mistruct.h"
35 #include "dixfontstr.h"
36 #include "fb.h"
37 #include "migc.h"
38 #include "miline.h"
39 #include "picturestr.h"
40 #include "kaa.h"
42 CARD8 smiBltRop[16] = {
43 /* GXclear */ 0x00, /* 0 */
44 /* GXand */ 0x88, /* src AND dst */
45 /* GXandReverse */ 0x44, /* src AND NOT dst */
46 /* GXcopy */ 0xcc, /* src */
47 /* GXandInverted*/ 0x22, /* NOT src AND dst */
48 /* GXnoop */ 0xaa, /* dst */
49 /* GXxor */ 0x66, /* src XOR dst */
50 /* GXor */ 0xee, /* src OR dst */
51 /* GXnor */ 0x11, /* NOT src AND NOT dst */
52 /* GXequiv */ 0x99, /* NOT src XOR dst */
53 /* GXinvert */ 0x55, /* NOT dst */
54 /* GXorReverse */ 0xdd, /* src OR NOT dst */
55 /* GXcopyInverted*/ 0x33, /* NOT src */
56 /* GXorInverted */ 0xbb, /* NOT src OR dst */
57 /* GXnand */ 0x77, /* NOT src OR NOT dst */
58 /* GXset */ 0xff, /* 1 */
61 CARD8 smiSolidRop[16] = {
62 /* GXclear */ 0x00, /* 0 */
63 /* GXand */ 0xa0, /* src AND dst */
64 /* GXandReverse */ 0x50, /* src AND NOT dst */
65 /* GXcopy */ 0xf0, /* src */
66 /* GXandInverted*/ 0x0a, /* NOT src AND dst */
67 /* GXnoop */ 0xaa, /* dst */
68 /* GXxor */ 0x5a, /* src XOR dst */
69 /* GXor */ 0xfa, /* src OR dst */
70 /* GXnor */ 0x05, /* NOT src AND NOT dst */
71 /* GXequiv */ 0xa5, /* NOT src XOR dst */
72 /* GXinvert */ 0x55, /* NOT dst */
73 /* GXorReverse */ 0xf5, /* src OR NOT dst */
74 /* GXcopyInverted*/ 0x0f, /* NOT src */
75 /* GXorInverted */ 0xaf, /* NOT src OR dst */
76 /* GXnand */ 0x5f, /* NOT src OR NOT dst */
77 /* GXset */ 0xff, /* 1 */
81 #define GET_STATUS(smic) smiGetIndex (smic, VGA_SEQ_INDEX, VGA_SEQ_DATA, 0x16)
83 #define ENGINE_IDLE_EMPTY(smic) ((GET_STATUS(smic) & 0x18) == 0x10)
84 #define FIFO_EMPTY(smic) ((GET_STATUS(smic) & 0x10) == 0x10)
86 #define MAX_FIFO 16
88 void
89 smiWaitAvail(SmiCardInfo *smic, int n)
91 if (smic->avail < n)
93 while (!FIFO_EMPTY (smic))
95 smic->avail = MAX_FIFO;
97 smic->avail -= n;
100 void
101 smiWaitIdle (SmiCardInfo *smic)
103 while (!ENGINE_IDLE_EMPTY (smic))
105 smic->avail = MAX_FIFO;
108 static SmiCardInfo *smic;
109 static SmiScreenInfo *smis;
110 static DPR *dpr;
111 static CARD32 accel_cmd;
113 static Bool
114 smiSetup (ScreenPtr pScreen, int wait)
116 KdScreenPriv(pScreen);
118 smis = getSmiScreenInfo (pScreenPriv);
119 smic = getSmiCardInfo(pScreenPriv);
120 dpr = smic->dpr;
122 if (!dpr)
123 return FALSE;
125 /* enable DPR/VPR registers */
126 smiSetIndex (smic, VGA_SEQ_INDEX, VGA_SEQ_DATA, 0x21,
127 smis->dpr_vpr_enable);
129 smiWaitAvail (smic, wait + 9);
130 dpr->src_stride = (smis->stride << 16) | smis->stride;
131 dpr->data_format = smis->data_format;
132 dpr->mask1 = 0xffffffff;
133 dpr->mask2 = 0xffffffff;
134 dpr->dst_stride = (smis->stride << 16) | smis->stride;
135 dpr->unknown_40 = 0x0;
136 dpr->unknown_44 = 0x0;
137 dpr->scissors_ul = 0x0;
138 dpr->scissors_lr = SMI_XY(4095,4095);
140 return TRUE;
143 static void
144 smiWaitMarker (ScreenPtr pScreen, int marker)
146 KdScreenPriv(pScreen);
147 smic = getSmiCardInfo(pScreenPriv);
149 smiWaitIdle (smic);
152 static Bool
153 smiPrepareSolid (PixmapPtr pPixmap,
154 int alu,
155 Pixel pm,
156 Pixel fg)
158 if (~pm & FbFullMask(pPixmap->drawable.depth))
159 return FALSE;
161 if (!smiSetup (pPixmap->drawable.pScreen, 3))
162 return FALSE;
164 accel_cmd = smiSolidRop[alu] | SMI_BITBLT | SMI_START_ENGINE;
165 dpr->fg = fg;
166 dpr->mask3 = 0xffffffff;
167 dpr->mask4 = 0xffffffff;
168 return TRUE;
171 static void
172 smiSolid (int x1, int y1, int x2, int y2)
174 smiWaitAvail(smic,3);
175 dpr->dst_xy = SMI_XY(x1,y1);
176 dpr->dst_wh = SMI_XY(x2-x1,y2-y1);
177 dpr->accel_cmd = accel_cmd;
180 static void
181 smiDoneSolid (void)
185 static int copyDx;
186 static int copyDy;
188 static Bool
189 smiPrepareCopy (PixmapPtr pSrcPixmap,
190 PixmapPtr pDstPixmap,
191 int dx,
192 int dy,
193 int alu,
194 Pixel pm)
196 if (~pm & FbFullMask(pSrcPixmap->drawable.depth))
197 return FALSE;
199 if (!smiSetup (pSrcPixmap->drawable.pScreen, 0))
200 return FALSE;
202 accel_cmd = smiBltRop[alu] | SMI_BITBLT | SMI_START_ENGINE;
204 copyDx = dx;
205 copyDy = dy;
206 if (dy < 0 || (dy == 0 && dx < 0))
207 accel_cmd |= SMI_RIGHT_TO_LEFT;
208 return TRUE;
211 static void
212 smiCopy (int srcX,
213 int srcY,
214 int dstX,
215 int dstY,
216 int w,
217 int h)
219 if (accel_cmd & SMI_RIGHT_TO_LEFT)
221 srcX += w - 1;
222 dstX += w - 1;
223 srcY += h - 1;
224 dstY += h - 1;
226 smiWaitAvail (smic, 4);
227 dpr->src_xy = SMI_XY (srcX, srcY);
228 dpr->dst_xy = SMI_XY (dstX, dstY);
229 dpr->dst_wh = SMI_XY (w, h);
230 dpr->accel_cmd = accel_cmd;
233 static void
234 smiDoneCopy (void)
239 Bool
240 smiDrawInit (ScreenPtr pScreen)
242 KdScreenPriv(pScreen);
243 smiCardInfo (pScreenPriv);
245 ENTER ();
246 if (pScreenPriv->screen->fb[0].depth == 4)
248 LEAVE ();
249 return FALSE;
252 if (!smic->dpr)
254 LEAVE ();
255 return FALSE;
258 memset(&smis->kaa, 0, sizeof(KaaScreenInfoRec));
259 smis->kaa.PrepareSolid = smiPrepareSolid;
260 smis->kaa.Solid = smiSolid;
261 smis->kaa.DoneSolid = smiDoneSolid;
262 smis->kaa.PrepareCopy = smiPrepareCopy;
263 smis->kaa.Copy = smiCopy;
264 smis->kaa.DoneCopy = smiDoneCopy;
265 smis->kaa.waitMarker = smiWaitMarker;
267 if (!kaaDrawInit (pScreen, &smis->kaa))
269 LEAVE ();
270 return FALSE;
273 LEAVE ();
274 return TRUE;
277 void
278 smiDrawEnable (ScreenPtr pScreen)
280 KdScreenPriv(pScreen);
281 int i;
282 static const int xyAddress[] = { 320, 400, 512, 640, 800, 1024, 1280, 1600, 2048 };
284 ENTER ();
285 smis = getSmiScreenInfo (pScreenPriv);
286 smic = getSmiCardInfo(pScreenPriv);
287 dpr = smic->dpr;
289 smis->stride = pScreenPriv->screen->fb[0].byteStride;
290 smis->dpr_vpr_enable = smiGetIndex (smic, VGA_SEQ_INDEX,
291 VGA_SEQ_DATA, 0x21) & ~0x03;
293 switch (pScreenPriv->screen->fb[0].depth) {
294 case 8:
295 smis->data_format = 0x00000000;
296 break;
297 case 15:
298 case 16:
299 smis->data_format = 0x00100000;
300 smis->stride >>= 1;
301 break;
302 case 24:
303 smis->data_format = 0x00300000;
304 break;
305 case 32:
306 smis->data_format = 0x00200000;
307 smis->stride >>= 2;
308 break;
310 for (i = 0; i < sizeof(xyAddress) / sizeof(xyAddress[0]); i++)
312 if (xyAddress[i] == pScreenPriv->screen->fb[0].pixelStride)
314 smis->data_format |= i << 16;
315 break;
319 smiSetup (pScreen, 0);
320 kaaMarkSync (pScreen);
321 LEAVE ();
324 void
325 smiDrawDisable (ScreenPtr pScreen)
327 ENTER ();
328 smic = 0;
329 smis = 0;
330 dpr = 0;
331 accel_cmd = 0;
332 LEAVE ();
335 void
336 smiDrawFini (ScreenPtr pScreen)
338 ENTER ();
339 LEAVE ();