First import
[xorg_rtime.git] / xorg-server-1.4 / hw / kdrive / sis300 / sis_draw.c
blobbbc905e1d4e0d4a899c03c92437bad2c2b15e8b3
1 /*
2 * Copyright © 2003 Eric Anholt
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 Eric Anholt not be used in
9 * advertising or publicity pertaining to distribution of the software without
10 * specific, written prior permission. Eric Anholt 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 * ERIC ANHOLT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
15 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
16 * EVENT SHALL ERIC ANHOLT 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 #include <sys/io.h>
25 #ifdef HAVE_CONFIG_H
26 #include <kdrive-config.h>
27 #endif
29 #include "sis.h"
30 #include "sis_reg.h"
32 #if 0
33 #define SIS_FALLBACK(x) \
34 do { \
35 ErrorF x; \
36 return FALSE; \
37 } while (0)
38 #else
39 #define SIS_FALLBACK(x) return FALSE
40 #endif
42 CARD8 SiSSolidRop[16] = {
43 /* GXclear */ 0x00, /* 0 */
44 /* GXand */ 0xa0, /* src AND dst */
45 /* GXandReverse */ 0x50, /* src AND NOT dst */
46 /* GXcopy */ 0xf0, /* src */
47 /* GXandInverted*/ 0x0a, /* NOT src AND dst */
48 /* GXnoop */ 0xaa, /* dst */
49 /* GXxor */ 0x5a, /* src XOR dst */
50 /* GXor */ 0xfa, /* src OR dst */
51 /* GXnor */ 0x05, /* NOT src AND NOT dst */
52 /* GXequiv */ 0xa5, /* NOT src XOR dst */
53 /* GXinvert */ 0x55, /* NOT dst */
54 /* GXorReverse */ 0xf5, /* src OR NOT dst */
55 /* GXcopyInverted*/ 0x0f, /* NOT src */
56 /* GXorInverted */ 0xaf, /* NOT src OR dst */
57 /* GXnand */ 0x5f, /* NOT src OR NOT dst */
58 /* GXset */ 0xff, /* 1 */
61 CARD8 SiSBltRop[16] = {
62 /* GXclear */ 0x00, /* 0 */
63 /* GXand */ 0x88, /* src AND dst */
64 /* GXandReverse */ 0x44, /* src AND NOT dst */
65 /* GXcopy */ 0xcc, /* src */
66 /* GXandInverted*/ 0x22, /* NOT src AND dst */
67 /* GXnoop */ 0xaa, /* dst */
68 /* GXxor */ 0x66, /* src XOR dst */
69 /* GXor */ 0xee, /* src OR dst */
70 /* GXnor */ 0x11, /* NOT src AND NOT dst */
71 /* GXequiv */ 0x99, /* NOT src XOR dst */
72 /* GXinvert */ 0x55, /* NOT dst */
73 /* GXorReverse */ 0xdd, /* src OR NOT dst */
74 /* GXcopyInverted*/ 0x33, /* NOT src */
75 /* GXorInverted */ 0xbb, /* NOT src OR dst */
76 /* GXnand */ 0x77, /* NOT src OR NOT dst */
77 /* GXset */ 0xff, /* 1 */
80 int copydx, copydy;
81 int fifo_size;
82 SiSScreenInfo *accel_siss;
83 char *mmio;
84 CARD32 sis_color = 0;
85 CARD32 blitCmd;
87 static void
88 SiSWaitAvailMMIO(int n)
90 while (fifo_size < n) {
91 fifo_size = MMIO_IN32(mmio, REG_CommandQueue) & MASK_QueueLen;
93 fifo_size -= n;
96 static void
97 SiSWaitIdle(void)
99 CARD32 engineState;
100 do {
101 engineState = MMIO_IN32(mmio, REG_CommandQueue);
102 } while ((engineState & SiS_EngIdle) != SiS_EngIdle);
105 static Bool
106 SiSPrepareSolid(PixmapPtr pPixmap, int alu, Pixel pm, Pixel fg)
108 KdScreenPriv(pPixmap->drawable.pScreen);
109 SiSScreenInfo(pScreenPriv);
110 SiSCardInfo(pScreenPriv);
112 /* No acceleration for other formats (yet) */
113 if (pPixmap->drawable.bitsPerPixel !=
114 pScreenPriv->screen->fb[0].bitsPerPixel)
115 return FALSE;
117 if ((pm & 0x00ffffff) != 0x00ffffff) /* XXX */
118 SIS_FALLBACK(("Unsupported planemask 0x%x\n", pm));
120 accel_siss = siss;
121 mmio = sisc->reg_base;
123 SiSWaitAvailMMIO(4);
124 MMIO_OUT32(mmio, REG_BLT_PATFG, fg);
125 MMIO_OUT32(mmio, REG_BLT_DSTRECT, (-1 << 16) | pPixmap->devKind);
126 MMIO_OUT32(mmio, REG_BLT_SRCPITCH, siss->depthSet);
127 MMIO_OUT32(mmio, REG_BLT_DSTBASE, ((CARD8 *)pPixmap->devPrivate.ptr -
128 pScreenPriv->screen->memory_base));
130 blitCmd = BLT_CMD_BITBLT | BLT_PAT_FG | BLT_X_INC | BLT_Y_INC |
131 BLT_NOCLIP | (SiSSolidRop[alu] << 8);
133 return TRUE;
136 static void
137 SiSSolid(int x1, int y1, int x2, int y2)
139 SiSWaitAvailMMIO(3);
140 MMIO_OUT32(mmio, REG_BLT_DSTXY, (x1 << 16) | y1);
141 MMIO_OUT32(mmio, REG_BLT_H_W, ((y2 - y1) << 16) | (x2 - x1));
142 MMIO_OUT32(mmio, REG_BLT_CMD, blitCmd);
145 static void
146 SiSDoneSolid(void)
150 static Bool
151 SiSPrepareCopy(PixmapPtr pSrc, PixmapPtr pDst, int dx, int dy, int alu,
152 Pixel pm)
154 KdScreenPriv(pDst->drawable.pScreen);
155 SiSScreenInfo(pScreenPriv);
156 SiSCardInfo(pScreenPriv);
158 /* No acceleration for other formats (yet) */
159 if (pDst->drawable.bitsPerPixel !=
160 pScreenPriv->screen->fb[0].bitsPerPixel)
161 return FALSE;
163 if ((pm & 0x00ffffff) != 0x00ffffff) /* XXX */
164 SIS_FALLBACK(("Unsupported pixel mask 0x%x\n", pm));
166 accel_siss = siss;
167 mmio = sisc->reg_base;
169 SiSWaitAvailMMIO(4);
170 MMIO_OUT32(mmio, REG_BLT_SRCPITCH, siss->depthSet | pSrc->devKind);
171 MMIO_OUT32(mmio, REG_BLT_DSTRECT, (-1 << 16) | pDst->devKind);
172 MMIO_OUT32(mmio, REG_BLT_SRCBASE, ((CARD8 *)pSrc->devPrivate.ptr -
173 pScreenPriv->screen->memory_base));
174 MMIO_OUT32(mmio, REG_BLT_DSTBASE, ((CARD8 *)pDst->devPrivate.ptr -
175 pScreenPriv->screen->memory_base));
177 blitCmd = BLT_CMD_BITBLT | BLT_PAT_FG | BLT_NOCLIP |
178 (SiSBltRop[alu] << 8);
180 if (pSrc != pDst || dx >= 0)
181 blitCmd |= BLT_X_INC;
182 if (pSrc != pDst || dy >= 0)
183 blitCmd |= BLT_Y_INC;
185 return TRUE;
188 static void
189 SiSCopy(int srcX, int srcY, int dstX, int dstY, int w, int h)
191 if (!(blitCmd & BLT_X_INC)) {
192 srcX += w - 1;
193 dstX += w - 1;
196 if (!(blitCmd & BLT_Y_INC)) {
197 srcY += h - 1;
198 dstY += h - 1;
201 SiSWaitAvailMMIO(4);
202 MMIO_OUT32(mmio, REG_BLT_H_W, (h << 16) | w);
203 MMIO_OUT32(mmio, REG_BLT_SRCXY, (srcX << 16) | srcY);
204 MMIO_OUT32(mmio, REG_BLT_DSTXY, (dstX << 16) | dstY);
205 MMIO_OUT32(mmio, REG_BLT_CMD, blitCmd);
208 static void
209 SiSDoneCopy(void)
213 KaaScreenInfoRec SiSKaa = {
214 SiSPrepareSolid,
215 SiSSolid,
216 SiSDoneSolid,
217 SiSPrepareCopy,
218 SiSCopy,
219 SiSDoneCopy,
220 KAA_OFFSCREEN_PIXMAPS,
225 #define USE_TURBOQUEUE 0
227 Bool
228 SiSDrawInit(ScreenPtr pScreen)
230 KdScreenPriv(pScreen);
231 SiSScreenInfo(pScreenPriv);
232 CARD8 tmp;
233 #if USE_TURBOQUEUE
234 int tqsize;
235 #endif
237 switch (pScreenPriv->screen->fb[0].depth)
239 case 8:
240 siss->depthSet = 0x00000000;
241 break;
242 case 15:
243 siss->depthSet = 0x40000000;
244 break;
245 case 16:
246 siss->depthSet = 0x80000000;
247 break;
248 case 24:
249 if (pScreenPriv->screen->fb[0].bitsPerPixel == 32) {
250 siss->depthSet = 0xc0000000;
251 break;
253 /* FALLTHROUGH*/
254 default:
255 ErrorF("Unsupported depth/bpp %d/%d\n",
256 pScreenPriv->screen->fb[0].depth,
257 pScreenPriv->screen->fb[0].bitsPerPixel);
258 return FALSE;
261 outb(0x05, 0x3c4);
262 outb(0x86, 0x3c5); /* unlock registers */
264 outb(0x20, 0x3c4);
265 outb(0xA1, 0x3c5); /* enable pci linear addressing, MMIO, PCI_IO */
267 outb(0x1e, 0x3c4);
268 tmp = inb(0x3c5);
269 outb(tmp | 0x42 | 0x18, 0x3c5); /* Enable 2d and 3d */
271 #if USE_TURBOQUEUE
272 tqsize = (pScreenPriv->screen->memory_size / 1024) / 64 - 8;
273 /* Enable TQ */
274 outb(0x26, 0x3c4);
275 outb(tqsize & 0xff, 0x3c5);
276 outb(0x27, 0x3c4);
277 tmp = inb(0x3c5);
278 outb(((tqsize >> 8) & 0x03) | (tmp & 0x0c) | 0xF0, 0x3c5);
280 /* XXX: Adjust offscreen size to avoid TQ area (last 512k) */
281 #endif
283 ErrorF("Screen: %d/%d depth/bpp\n", pScreenPriv->screen->fb[0].depth,
284 pScreenPriv->screen->fb[0].bitsPerPixel);
286 if (!kaaDrawInit(pScreen, &SiSKaa))
287 return FALSE;
289 return TRUE;
292 void
293 SiSDrawEnable(ScreenPtr pScreen)
295 KdMarkSync(pScreen);
298 void
299 SiSDrawDisable(ScreenPtr pScreen)
303 void
304 SiSDrawFini(ScreenPtr pScreen)
306 kaaDrawFini (pScreen);
309 void
310 SiSDrawSync(ScreenPtr pScreen)
312 KdScreenPriv(pScreen);
313 SiSScreenInfo(pScreenPriv);
314 SiSCardInfo(pScreenPriv);
316 accel_siss = siss;
317 mmio = sisc->reg_base;
319 SiSWaitIdle();