~ubuntu-branches/ubuntu/intrepid/xserver-xgl/intrepid

« back to all changes in this revision

Viewing changes to hw/kdrive/sis300/sis_draw.c

  • Committer: Bazaar Package Importer
  • Author(s): Matthew Garrett
  • Date: 2006-02-13 14:21:43 UTC
  • Revision ID: james.westby@ubuntu.com-20060213142143-mad6z9xzem7hzxz9
Tags: upstream-7.0.0
ImportĀ upstreamĀ versionĀ 7.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * $Id: sis_draw.c,v 1.3 2005/12/27 08:29:48 ajax Exp $
 
3
 *
 
4
 * Copyright ļæ½ 2003 Eric Anholt
 
5
 *
 
6
 * Permission to use, copy, modify, distribute, and sell this software and its
 
7
 * documentation for any purpose is hereby granted without fee, provided that
 
8
 * the above copyright notice appear in all copies and that both that
 
9
 * copyright notice and this permission notice appear in supporting
 
10
 * documentation, and that the name of Eric Anholt not be used in
 
11
 * advertising or publicity pertaining to distribution of the software without
 
12
 * specific, written prior permission.  Eric Anholt makes no
 
13
 * representations about the suitability of this software for any purpose.  It
 
14
 * is provided "as is" without express or implied warranty.
 
15
 *
 
16
 * ERIC ANHOLT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
 
17
 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
 
18
 * EVENT SHALL ERIC ANHOLT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
 
19
 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
 
20
 * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
 
21
 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
 
22
 * PERFORMANCE OF THIS SOFTWARE.
 
23
 */
 
24
/* $Header: /cvs/xorg/xserver/xorg/hw/kdrive/sis300/sis_draw.c,v 1.3 2005/12/27 08:29:48 ajax Exp $ */
 
25
 
 
26
#include <sys/io.h>
 
27
 
 
28
#ifdef HAVE_CONFIG_H
 
29
#include <kdrive-config.h>
 
30
#endif
 
31
 
 
32
#include "sis.h"
 
33
#include "sis_reg.h"
 
34
 
 
35
#if 0
 
36
#define SIS_FALLBACK(x)         \
 
37
do {                            \
 
38
        ErrorF x;               \
 
39
        return FALSE;           \
 
40
} while (0)
 
41
#else
 
42
#define SIS_FALLBACK(x) return FALSE
 
43
#endif
 
44
 
 
45
CARD8 SiSSolidRop[16] = {
 
46
    /* GXclear      */      0x00,         /* 0 */
 
47
    /* GXand        */      0xa0,         /* src AND dst */
 
48
    /* GXandReverse */      0x50,         /* src AND NOT dst */
 
49
    /* GXcopy       */      0xf0,         /* src */
 
50
    /* GXandInverted*/      0x0a,         /* NOT src AND dst */
 
51
    /* GXnoop       */      0xaa,         /* dst */
 
52
    /* GXxor        */      0x5a,         /* src XOR dst */
 
53
    /* GXor         */      0xfa,         /* src OR dst */
 
54
    /* GXnor        */      0x05,         /* NOT src AND NOT dst */
 
55
    /* GXequiv      */      0xa5,         /* NOT src XOR dst */
 
56
    /* GXinvert     */      0x55,         /* NOT dst */
 
57
    /* GXorReverse  */      0xf5,         /* src OR NOT dst */
 
58
    /* GXcopyInverted*/     0x0f,         /* NOT src */
 
59
    /* GXorInverted */      0xaf,         /* NOT src OR dst */
 
60
    /* GXnand       */      0x5f,         /* NOT src OR NOT dst */
 
61
    /* GXset        */      0xff,         /* 1 */
 
62
};
 
63
 
 
64
CARD8 SiSBltRop[16] = {
 
65
    /* GXclear      */      0x00,         /* 0 */
 
66
    /* GXand        */      0x88,         /* src AND dst */
 
67
    /* GXandReverse */      0x44,         /* src AND NOT dst */
 
68
    /* GXcopy       */      0xcc,         /* src */
 
69
    /* GXandInverted*/      0x22,         /* NOT src AND dst */
 
70
    /* GXnoop       */      0xaa,         /* dst */
 
71
    /* GXxor        */      0x66,         /* src XOR dst */
 
72
    /* GXor         */      0xee,         /* src OR dst */
 
73
    /* GXnor        */      0x11,         /* NOT src AND NOT dst */
 
74
    /* GXequiv      */      0x99,         /* NOT src XOR dst */
 
75
    /* GXinvert     */      0x55,         /* NOT dst */
 
76
    /* GXorReverse  */      0xdd,         /* src OR NOT dst */
 
77
    /* GXcopyInverted*/     0x33,         /* NOT src */
 
78
    /* GXorInverted */      0xbb,         /* NOT src OR dst */
 
79
    /* GXnand       */      0x77,         /* NOT src OR NOT dst */
 
80
    /* GXset        */      0xff,         /* 1 */
 
81
};
 
82
 
 
83
int copydx, copydy;
 
84
int fifo_size;
 
85
SiSScreenInfo *accel_siss;
 
86
char *mmio;
 
87
CARD32 sis_color = 0;
 
88
CARD32 blitCmd;
 
89
 
 
90
static void
 
91
SiSWaitAvailMMIO(int n)
 
92
{
 
93
        while (fifo_size < n) {
 
94
                fifo_size = MMIO_IN32(mmio, REG_CommandQueue) & MASK_QueueLen;
 
95
        }
 
96
        fifo_size -= n;
 
97
}
 
98
 
 
99
static void
 
100
SiSWaitIdle(void)
 
101
{
 
102
        CARD32 engineState;
 
103
        do {
 
104
                engineState = MMIO_IN32(mmio, REG_CommandQueue);
 
105
        } while ((engineState & SiS_EngIdle) != SiS_EngIdle);
 
106
}
 
107
 
 
108
static Bool
 
109
SiSPrepareSolid(PixmapPtr pPixmap, int alu, Pixel pm, Pixel fg)
 
110
{
 
111
        KdScreenPriv(pPixmap->drawable.pScreen);
 
112
        SiSScreenInfo(pScreenPriv);
 
113
        SiSCardInfo(pScreenPriv);
 
114
 
 
115
        /* No acceleration for other formats (yet) */
 
116
        if (pPixmap->drawable.bitsPerPixel !=
 
117
            pScreenPriv->screen->fb[0].bitsPerPixel)
 
118
                return FALSE;
 
119
 
 
120
        if ((pm & 0x00ffffff) != 0x00ffffff)    /* XXX */
 
121
                SIS_FALLBACK(("Unsupported planemask 0x%x\n", pm));
 
122
 
 
123
        accel_siss = siss;
 
124
        mmio = sisc->reg_base;
 
125
 
 
126
        SiSWaitAvailMMIO(4);
 
127
        MMIO_OUT32(mmio, REG_BLT_PATFG, fg);
 
128
        MMIO_OUT32(mmio, REG_BLT_DSTRECT, (-1 << 16) | pPixmap->devKind);
 
129
        MMIO_OUT32(mmio, REG_BLT_SRCPITCH, siss->depthSet);
 
130
        MMIO_OUT32(mmio, REG_BLT_DSTBASE, ((CARD8 *)pPixmap->devPrivate.ptr -
 
131
            pScreenPriv->screen->memory_base));
 
132
 
 
133
        blitCmd = BLT_CMD_BITBLT | BLT_PAT_FG | BLT_X_INC | BLT_Y_INC |
 
134
            BLT_NOCLIP | (SiSSolidRop[alu] << 8);
 
135
 
 
136
        return TRUE;
 
137
}
 
138
 
 
139
static void
 
140
SiSSolid(int x1, int y1, int x2, int y2)
 
141
{
 
142
        SiSWaitAvailMMIO(3);
 
143
        MMIO_OUT32(mmio, REG_BLT_DSTXY, (x1 << 16) | y1);
 
144
        MMIO_OUT32(mmio, REG_BLT_H_W, ((y2 - y1) << 16) | (x2 - x1));
 
145
        MMIO_OUT32(mmio, REG_BLT_CMD, blitCmd);
 
146
}
 
147
 
 
148
static void
 
149
SiSDoneSolid(void)
 
150
{
 
151
}
 
152
 
 
153
static Bool
 
154
SiSPrepareCopy(PixmapPtr pSrc, PixmapPtr pDst, int dx, int dy, int alu,
 
155
    Pixel pm)
 
156
{
 
157
        KdScreenPriv(pDst->drawable.pScreen);
 
158
        SiSScreenInfo(pScreenPriv);
 
159
        SiSCardInfo(pScreenPriv);
 
160
 
 
161
        /* No acceleration for other formats (yet) */
 
162
        if (pDst->drawable.bitsPerPixel !=
 
163
            pScreenPriv->screen->fb[0].bitsPerPixel)
 
164
                return FALSE;
 
165
 
 
166
        if ((pm & 0x00ffffff) != 0x00ffffff)    /* XXX */
 
167
                SIS_FALLBACK(("Unsupported pixel mask 0x%x\n", pm));
 
168
 
 
169
        accel_siss = siss;
 
170
        mmio = sisc->reg_base;
 
171
 
 
172
        SiSWaitAvailMMIO(4);
 
173
        MMIO_OUT32(mmio, REG_BLT_SRCPITCH, siss->depthSet | pSrc->devKind);
 
174
        MMIO_OUT32(mmio, REG_BLT_DSTRECT, (-1 << 16) | pDst->devKind);
 
175
        MMIO_OUT32(mmio, REG_BLT_SRCBASE, ((CARD8 *)pSrc->devPrivate.ptr -
 
176
            pScreenPriv->screen->memory_base));
 
177
        MMIO_OUT32(mmio, REG_BLT_DSTBASE, ((CARD8 *)pDst->devPrivate.ptr -
 
178
            pScreenPriv->screen->memory_base));
 
179
 
 
180
        blitCmd = BLT_CMD_BITBLT | BLT_PAT_FG | BLT_NOCLIP |
 
181
            (SiSBltRop[alu] << 8);
 
182
 
 
183
        if (pSrc != pDst || dx >= 0)
 
184
                blitCmd |= BLT_X_INC;
 
185
        if (pSrc != pDst || dy >= 0)
 
186
                blitCmd |= BLT_Y_INC;
 
187
 
 
188
        return TRUE;
 
189
}
 
190
 
 
191
static void
 
192
SiSCopy(int srcX, int srcY, int dstX, int dstY, int w, int h)
 
193
{
 
194
        if (!(blitCmd & BLT_X_INC)) {
 
195
                srcX += w - 1;
 
196
                dstX += w - 1;
 
197
        }
 
198
 
 
199
        if (!(blitCmd & BLT_Y_INC)) {
 
200
                srcY += h - 1;
 
201
                dstY += h - 1;
 
202
        }
 
203
 
 
204
        SiSWaitAvailMMIO(4);
 
205
        MMIO_OUT32(mmio, REG_BLT_H_W, (h << 16) | w);
 
206
        MMIO_OUT32(mmio, REG_BLT_SRCXY, (srcX << 16) | srcY);
 
207
        MMIO_OUT32(mmio, REG_BLT_DSTXY, (dstX << 16) | dstY);
 
208
        MMIO_OUT32(mmio, REG_BLT_CMD, blitCmd);
 
209
}
 
210
 
 
211
static void
 
212
SiSDoneCopy(void)
 
213
{
 
214
}
 
215
 
 
216
KaaScreenInfoRec SiSKaa = {
 
217
        SiSPrepareSolid,
 
218
        SiSSolid,
 
219
        SiSDoneSolid,
 
220
        SiSPrepareCopy,
 
221
        SiSCopy,
 
222
        SiSDoneCopy,
 
223
        KAA_OFFSCREEN_PIXMAPS,
 
224
        8,
 
225
        8
 
226
};
 
227
 
 
228
#define USE_TURBOQUEUE 0
 
229
 
 
230
Bool
 
231
SiSDrawInit(ScreenPtr pScreen)
 
232
{
 
233
        KdScreenPriv(pScreen);
 
234
        SiSScreenInfo(pScreenPriv);
 
235
        CARD8 tmp;
 
236
#if USE_TURBOQUEUE
 
237
        int tqsize;
 
238
#endif
 
239
 
 
240
        switch (pScreenPriv->screen->fb[0].depth)
 
241
        {
 
242
        case 8:
 
243
                siss->depthSet = 0x00000000;
 
244
                break;
 
245
        case 15:
 
246
                siss->depthSet = 0x40000000;
 
247
                break;
 
248
        case 16:
 
249
                siss->depthSet = 0x80000000;
 
250
                break;
 
251
        case 24:
 
252
                if (pScreenPriv->screen->fb[0].bitsPerPixel == 32) {
 
253
                        siss->depthSet = 0xc0000000;
 
254
                        break;
 
255
                }
 
256
                /* FALLTHROUGH*/
 
257
        default:
 
258
                ErrorF("Unsupported depth/bpp %d/%d\n",
 
259
                    pScreenPriv->screen->fb[0].depth,
 
260
                    pScreenPriv->screen->fb[0].bitsPerPixel);
 
261
                return FALSE;
 
262
        }
 
263
 
 
264
        outb(0x05, 0x3c4);
 
265
        outb(0x86, 0x3c5); /* unlock registers */
 
266
 
 
267
        outb(0x20, 0x3c4);
 
268
        outb(0xA1, 0x3c5); /* enable pci linear addressing, MMIO, PCI_IO */
 
269
 
 
270
        outb(0x1e, 0x3c4);
 
271
        tmp = inb(0x3c5);
 
272
        outb(tmp | 0x42 | 0x18, 0x3c5); /* Enable 2d and 3d */
 
273
 
 
274
#if USE_TURBOQUEUE
 
275
        tqsize = (pScreenPriv->screen->memory_size / 1024) / 64 - 8;
 
276
        /* Enable TQ */
 
277
        outb(0x26, 0x3c4);
 
278
        outb(tqsize & 0xff, 0x3c5);
 
279
        outb(0x27, 0x3c4);
 
280
        tmp = inb(0x3c5);
 
281
        outb(((tqsize >> 8) & 0x03) | (tmp & 0x0c) | 0xF0, 0x3c5);
 
282
        
 
283
        /* XXX: Adjust offscreen size to avoid TQ area (last 512k) */
 
284
#endif
 
285
 
 
286
        ErrorF("Screen: %d/%d depth/bpp\n", pScreenPriv->screen->fb[0].depth,
 
287
            pScreenPriv->screen->fb[0].bitsPerPixel);
 
288
 
 
289
        if (!kaaDrawInit(pScreen, &SiSKaa))
 
290
                return FALSE;
 
291
 
 
292
        return TRUE;
 
293
}
 
294
 
 
295
void
 
296
SiSDrawEnable(ScreenPtr pScreen)
 
297
{
 
298
        KdMarkSync(pScreen);
 
299
}
 
300
 
 
301
void
 
302
SiSDrawDisable(ScreenPtr pScreen)
 
303
{
 
304
}
 
305
 
 
306
void
 
307
SiSDrawFini(ScreenPtr pScreen)
 
308
{
 
309
        kaaDrawFini (pScreen);
 
310
}
 
311
 
 
312
void
 
313
SiSDrawSync(ScreenPtr pScreen)
 
314
{
 
315
        KdScreenPriv(pScreen);
 
316
        SiSScreenInfo(pScreenPriv);
 
317
        SiSCardInfo(pScreenPriv);
 
318
 
 
319
        accel_siss = siss;
 
320
        mmio = sisc->reg_base;
 
321
 
 
322
        SiSWaitIdle();
 
323
}