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.
26 #include <kdrive-config.h>
33 #define SIS_FALLBACK(x) \
39 #define SIS_FALLBACK(x) return FALSE
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 */
82 SiSScreenInfo
*accel_siss
;
88 SiSWaitAvailMMIO(int n
)
90 while (fifo_size
< n
) {
91 fifo_size
= MMIO_IN32(mmio
, REG_CommandQueue
) & MASK_QueueLen
;
101 engineState
= MMIO_IN32(mmio
, REG_CommandQueue
);
102 } while ((engineState
& SiS_EngIdle
) != SiS_EngIdle
);
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
)
117 if ((pm
& 0x00ffffff) != 0x00ffffff) /* XXX */
118 SIS_FALLBACK(("Unsupported planemask 0x%x\n", pm
));
121 mmio
= sisc
->reg_base
;
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);
137 SiSSolid(int x1
, int y1
, int x2
, int y2
)
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
);
151 SiSPrepareCopy(PixmapPtr pSrc
, PixmapPtr pDst
, int dx
, int dy
, int alu
,
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
)
163 if ((pm
& 0x00ffffff) != 0x00ffffff) /* XXX */
164 SIS_FALLBACK(("Unsupported pixel mask 0x%x\n", pm
));
167 mmio
= sisc
->reg_base
;
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
;
189 SiSCopy(int srcX
, int srcY
, int dstX
, int dstY
, int w
, int h
)
191 if (!(blitCmd
& BLT_X_INC
)) {
196 if (!(blitCmd
& BLT_Y_INC
)) {
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
);
213 KaaScreenInfoRec SiSKaa
= {
220 KAA_OFFSCREEN_PIXMAPS
,
225 #define USE_TURBOQUEUE 0
228 SiSDrawInit(ScreenPtr pScreen
)
230 KdScreenPriv(pScreen
);
231 SiSScreenInfo(pScreenPriv
);
237 switch (pScreenPriv
->screen
->fb
[0].depth
)
240 siss
->depthSet
= 0x00000000;
243 siss
->depthSet
= 0x40000000;
246 siss
->depthSet
= 0x80000000;
249 if (pScreenPriv
->screen
->fb
[0].bitsPerPixel
== 32) {
250 siss
->depthSet
= 0xc0000000;
255 ErrorF("Unsupported depth/bpp %d/%d\n",
256 pScreenPriv
->screen
->fb
[0].depth
,
257 pScreenPriv
->screen
->fb
[0].bitsPerPixel
);
262 outb(0x86, 0x3c5); /* unlock registers */
265 outb(0xA1, 0x3c5); /* enable pci linear addressing, MMIO, PCI_IO */
269 outb(tmp
| 0x42 | 0x18, 0x3c5); /* Enable 2d and 3d */
272 tqsize
= (pScreenPriv
->screen
->memory_size
/ 1024) / 64 - 8;
275 outb(tqsize
& 0xff, 0x3c5);
278 outb(((tqsize
>> 8) & 0x03) | (tmp
& 0x0c) | 0xF0, 0x3c5);
280 /* XXX: Adjust offscreen size to avoid TQ area (last 512k) */
283 ErrorF("Screen: %d/%d depth/bpp\n", pScreenPriv
->screen
->fb
[0].depth
,
284 pScreenPriv
->screen
->fb
[0].bitsPerPixel
);
286 if (!kaaDrawInit(pScreen
, &SiSKaa
))
293 SiSDrawEnable(ScreenPtr pScreen
)
299 SiSDrawDisable(ScreenPtr pScreen
)
304 SiSDrawFini(ScreenPtr pScreen
)
306 kaaDrawFini (pScreen
);
310 SiSDrawSync(ScreenPtr pScreen
)
312 KdScreenPriv(pScreen
);
313 SiSScreenInfo(pScreenPriv
);
314 SiSCardInfo(pScreenPriv
);
317 mmio
= sisc
->reg_base
;