summaryrefslogtreecommitdiff
path: root/src/blade_accel_exa.c
blob: a3e1ea0cd94a59b68dbd9a538dba3ecd04279a1e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
/*
 * Copyright 1997-2003 by Alan Hourihane, North Wales, UK.
 * Copyright (c) 2006, Jesse Barnes <jbarnes@virtuousgeek.org>
 *
 * Permission to use, copy, modify, distribute, and sell this software
 * and its documentation for any purpose is hereby granted without
 * fee, provided that the above copyright notice appear in all copies
 * and that both that copyright notice and this permission notice
 * appear in supporting documentation, and that the name of the
 * authors not be used in advertising or publicity pertaining to
 * distribution of the software without specific, written prior
 * permission.  The authors make no representations about the
 * suitability of this software for any purpose.  It is provided
 * "as is" without express or implied warranty.
 *
 * THE AUTHORS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS,
 * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY SPECIAL, INDIRECT
 * OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
 * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 *
 * Authors:  Alan Hourihane, <alanh@fairlite.demon.co.uk>
 *           Jesse Barnes <jbarnes@virtuousgeek.org>
 *
 * Trident Blade3D EXA support.
 * TODO:
 *   Composite hooks (some ops/arg. combos may not be supported)
 *   Upload/Download from screen (is this even possible
 *                                with this chip?)
 *   Fast mixed directoion Blts
 */

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

#include "xf86.h"
#include "xf86_OSproc.h"

#include "xf86Pci.h"

#include "exa.h"

#include "trident.h"
#include "trident_regs.h"

#include "xaarop.h"

#undef REPLICATE
#define REPLICATE(r, bpp)                           \
{                                                   \
    if (bpp == 16) {                                \
        r = ((r & 0xFFFF) << 16) | (r & 0xFFFF);    \
    } else                                          \
        if (bpp == 8) {                             \
            r &= 0xFF;                              \
            r |= (r << 8);                          \
            r |= (r << 16);                         \
    }                                               \
}

static int rop_table[16] = {
    ROP_0,              /* GXclear */
    ROP_DSa,            /* GXand */
    ROP_SDna,           /* GXandReverse */
    ROP_S,              /* GXcopy */
    ROP_DSna,           /* GXandInverted */
    ROP_D,              /* GXnoop */
    ROP_DSx,            /* GXxor */
    ROP_DSo,            /* GXor */
    ROP_DSon,           /* GXnor */
    ROP_DSxn,           /* GXequiv */
    ROP_Dn,             /* GXinvert*/
    ROP_SDno,           /* GXorReverse */
    ROP_Sn,             /* GXcopyInverted */
    ROP_DSno,           /* GXorInverted */
    ROP_DSan,           /* GXnand */
    ROP_1               /* GXset */
};

static int
GetCopyROP(int rop)
{
    return rop_table[rop];
}

static unsigned long
GetDepth(int depth)
{
    unsigned long ret;

    switch (depth) {
    case 8:
        ret = 0;
        break;
    case 15:
        ret = 5UL << 29; /* 555 */
    case 16:
        ret = 1UL << 29; /* 565 */
        break;
    case 32:
        ret = 2UL << 29;
        break;
    default:
        ret = 0;
        break;
    }

    return ret;
}

static Bool
PrepareSolid(PixmapPtr pPixmap,
                int rop, Pixel planemask, Pixel color)
{
    TRIDENTPtr pTrident = TRIDENTPTR(
            xf86ScreenToScrn(pPixmap->drawable.pScreen));

    REPLICATE(color, pPixmap->drawable.bitsPerPixel);
    BLADE_OUT(GER_FGCOLOR, color);
    BLADE_OUT(GER_ROP, GetCopyROP(rop));
    pTrident->BltScanDirection = 0;

    return TRUE;
}

static void
Solid(PixmapPtr pPixmap,
        int x, int y,
        int x2, int y2)
{
    TRIDENTPtr pTrident = TRIDENTPTR(
                        xf86ScreenToScrn(pPixmap->drawable.pScreen));
    int dst_stride = (pPixmap->drawable.width + 7) / 8;
    int dst_off = exaGetPixmapOffset(pPixmap) / 8;

    BLADE_OUT(GER_DSTBASE0,
                GetDepth(pPixmap->drawable.bitsPerPixel) |
                (dst_stride << 20) |
                dst_off);

    BLADE_OUT(GER_DRAW_CMD,
                GER_OP_LINE |
                pTrident->BltScanDirection |
                GER_DRAW_SRC_COLOR | GER_ROP_ENABLE | GER_SRC_CONST);

    BLADE_OUT(GER_DST1, (y << 16) | x);
    BLADE_OUT(GER_DST2, (((y2 - 1) & 0xfff) << 16) |
                        ((x2 - 1) & 0xfff));
}

static void
DoneSolid(PixmapPtr pPixmap)
{
}

static Bool
PrepareCopy(PixmapPtr pSrcPixmap, PixmapPtr pDstPixmap,
            int xdir, int ydir,
            int alu, Pixel planemask)
{
    TRIDENTPtr pTrident = TRIDENTPTR(
                    xf86ScreenToScrn(pSrcPixmap->drawable.pScreen));
    int src_stride = (pSrcPixmap->drawable.width + 7) / 8;
    int src_off = exaGetPixmapOffset(pSrcPixmap) / 8;
    int dst_stride = (pDstPixmap->drawable.width + 7) / 8;
    int dst_off = exaGetPixmapOffset(pDstPixmap) / 8;

    pTrident->BltScanDirection = 0;

    REPLICATE(planemask, pSrcPixmap->drawable.bitsPerPixel);
    if (planemask != (unsigned int) -1) {
        BLADE_OUT(GER_BITMASK, ~planemask);
        pTrident->BltScanDirection |= (1 << 5);
    }

    BLADE_OUT(GER_SRCBASE0,
                GetDepth(pSrcPixmap->drawable.bitsPerPixel) |
                (src_stride << 20) |
                src_off);

    BLADE_OUT(GER_DSTBASE0,
                GetDepth(pDstPixmap->drawable.bitsPerPixel) |
                (dst_stride << 20) |
                dst_off);

    if ((xdir < 0) || (ydir < 0))
        pTrident->BltScanDirection |= (1 << 1);

    BLADE_OUT(GER_ROP, GetCopyROP(alu));

    return TRUE;
}

static void
Copy(PixmapPtr pDstPixmap,
        int x1, int y1,
        int x2, int y2,
        int w, int h)
{
    TRIDENTPtr pTrident = TRIDENTPTR(
                    xf86ScreenToScrn(pDstPixmap->drawable.pScreen));

    BLADE_OUT(GER_DRAW_CMD, GER_OP_BLT_HOST |
                            GER_DRAW_SRC_COLOR |
                            GER_ROP_ENABLE |
                            GER_BLT_SRC_FB |
                            pTrident->BltScanDirection);

    if (pTrident->BltScanDirection) {
        BLADE_OUT(GER_SRC1, ((y1 + h - 1) << 16) | (x1 + w - 1));
        BLADE_OUT(GER_SRC2, (y1 << 16) | x1);
        BLADE_OUT(GER_DST1, ((y2 + h - 1) << 16) | (x2 + w - 1));
        BLADE_OUT(GER_DST2, ((y2 & 0xfff) << 16) | (x2 & 0xfff));
    } else {
        BLADE_OUT(GER_SRC1, (y1 << 16) | x1);
        BLADE_OUT(GER_SRC2, ((y1 + h - 1) << 16) | (x1 + w - 1));
        BLADE_OUT(GER_DST1, (y2 << 16) | x2);
        BLADE_OUT(GER_DST2, ((((y2 + h - 1) & 0xfff) << 16) |
                            ((x2 + w - 1) & 0xfff)));
    }
}

static void
DoneCopy(PixmapPtr pDstPixmap)
{
}

static int
MarkSync(ScreenPtr pScreen)
{
    return 0;
}

static void
WaitMarker(ScreenPtr pScreen,
            int marker)
{
    TRIDENTPtr pTrident = TRIDENTPTR(xf86ScreenToScrn(pScreen));
    int busy;
    int cnt = 10000000;

    BLADE_OUT(GER_PATSTYLE, 0); /* Clear pattern & style first? */

    BLADEBUSY(busy);
    while (busy != 0) {
        if (--cnt < 0) {
            ErrorF("GE timeout\n");
            BLADE_OUT(GER_CONTROL, GER_CTL_RESET);
            BLADE_OUT(GER_CONTROL, GER_CTL_RESUME);
            break;
        }

        BLADEBUSY(busy);
    }
}

static void
BladeInitializeAccelerator(ScrnInfoPtr pScrn)
{
    TRIDENTPtr pTrident = TRIDENTPTR(pScrn);

    BLADE_OUT(GER_DSTBASE0, 0);
    BLADE_OUT(GER_DSTBASE1, 0);
    BLADE_OUT(GER_DSTBASE2, 0);
    BLADE_OUT(GER_DSTBASE3, 0);
    BLADE_OUT(GER_SRCBASE0, 0);
    BLADE_OUT(GER_SRCBASE1, 0);
    BLADE_OUT(GER_SRCBASE2, 0);
    BLADE_OUT(GER_SRCBASE3, 0);
    BLADE_OUT(GER_PATSTYLE, 0);
}

Bool
BladeExaInit(ScreenPtr pScreen)
{
    ScrnInfoPtr pScrn = xf86ScreenToScrn(pScreen);
    TRIDENTPtr pTrident = TRIDENTPTR(pScrn);
    ExaDriverPtr ExaDriver;

    if (pTrident->NoAccel)
        return FALSE;

    if (!(ExaDriver = exaDriverAlloc())) {
        pTrident->NoAccel = TRUE;
        return FALSE;
    }

    ExaDriver->exa_major = 2;
    ExaDriver->exa_minor = 0;

    pTrident->EXADriverPtr = ExaDriver;

    pTrident->InitializeAccelerator = BladeInitializeAccelerator;
    BladeInitializeAccelerator(pScrn);

    ExaDriver->memoryBase = pTrident->FbBase;
    ExaDriver->memorySize = pScrn->videoRam * 1024;

    ExaDriver->offScreenBase = pScrn->displayWidth * pScrn->virtualY
            * ((pScrn->bitsPerPixel + 7) / 8);

    if (ExaDriver->memorySize > ExaDriver->offScreenBase)
        ExaDriver->flags |= EXA_OFFSCREEN_PIXMAPS;
    else {
        xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
                "Not enough video RAM for "
                        "offscreen memory manager. Xv disabled\n");
        /* disable Xv here... */
    }

    ExaDriver->pixmapOffsetAlign = 32;
    ExaDriver->pixmapPitchAlign = 32;
    ExaDriver->maxX = 2047;
    ExaDriver->maxY = 2047;

    ExaDriver->flags |= EXA_TWO_BITBLT_DIRECTIONS;

    ExaDriver->MarkSync = MarkSync;
    ExaDriver->WaitMarker = WaitMarker;

    /* Solid fill & copy, the bare minimum */
    ExaDriver->PrepareSolid = PrepareSolid;
    ExaDriver->Solid = Solid;
    ExaDriver->DoneSolid = DoneSolid;
    ExaDriver->PrepareCopy = PrepareCopy;
    ExaDriver->Copy = Copy;
    ExaDriver->DoneCopy = DoneCopy;

    return exaDriverInit(pScreen, ExaDriver);
}