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

« back to all changes in this revision

Viewing changes to hw/kdrive/chips/chipsdraw.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: tridentdraw.c,v 1.1 1999/11/02 03:54:47 keithp Exp $
 
3
 *
 
4
 * Copyright ļæ½ 1999 Keith Packard
 
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 Keith Packard not be used in
 
11
 * advertising or publicity pertaining to distribution of the software without
 
12
 * specific, written prior permission.  Keith Packard 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
 * KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
 
17
 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
 
18
 * EVENT SHALL KEITH PACKARD 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
/* $RCSId: xc/programs/Xserver/hw/kdrive/trident/tridentdraw.c,v 1.10 2001/06/03 18:48:19 keithp Exp $ */
 
25
 
 
26
#ifdef HAVE_CONFIG_H
 
27
#include <kdrive-config.h>
 
28
#endif
 
29
#include "chips.h"
 
30
 
 
31
#include        <X11/Xmd.h>
 
32
#include        "gcstruct.h"
 
33
#include        "scrnintstr.h"
 
34
#include        "pixmapstr.h"
 
35
#include        "regionstr.h"
 
36
#include        "mistruct.h"
 
37
#include        "dixfontstr.h"
 
38
#include        "fb.h"
 
39
#include        "migc.h"
 
40
#include        "miline.h"
 
41
#include        "kaa.h"
 
42
 
 
43
CARD8 chipsBltRop[16] = {
 
44
    /* GXclear      */      0x00,         /* 0 */
 
45
    /* GXand        */      0x88,         /* src AND dst */
 
46
    /* GXandReverse */      0x44,         /* src AND NOT dst */
 
47
    /* GXcopy       */      0xcc,         /* src */
 
48
    /* GXandInverted*/      0x22,         /* NOT src AND dst */
 
49
    /* GXnoop       */      0xaa,         /* dst */
 
50
    /* GXxor        */      0x66,         /* src XOR dst */
 
51
    /* GXor         */      0xee,         /* src OR dst */
 
52
    /* GXnor        */      0x11,         /* NOT src AND NOT dst */
 
53
    /* GXequiv      */      0x99,         /* NOT src XOR dst */
 
54
    /* GXinvert     */      0x55,         /* NOT dst */
 
55
    /* GXorReverse  */      0xdd,         /* src OR NOT dst */
 
56
    /* GXcopyInverted*/     0x33,         /* NOT src */
 
57
    /* GXorInverted */      0xbb,         /* NOT src OR dst */
 
58
    /* GXnand       */      0x77,         /* NOT src OR NOT dst */
 
59
    /* GXset        */      0xff,         /* 1 */
 
60
};
 
61
 
 
62
CARD8 chipsSolidRop[16] = {
 
63
    /* GXclear      */      0x00,         /* 0 */
 
64
    /* GXand        */      0xa0,         /* src AND dst */
 
65
    /* GXandReverse */      0x50,         /* src AND NOT dst */
 
66
    /* GXcopy       */      0xf0,         /* src */
 
67
    /* GXandInverted*/      0x0a,         /* NOT src AND dst */
 
68
    /* GXnoop       */      0xaa,         /* dst */
 
69
    /* GXxor        */      0x5a,         /* src XOR dst */
 
70
    /* GXor         */      0xfa,         /* src OR dst */
 
71
    /* GXnor        */      0x05,         /* NOT src AND NOT dst */
 
72
    /* GXequiv      */      0xa5,         /* NOT src XOR dst */
 
73
    /* GXinvert     */      0x55,         /* NOT dst */
 
74
    /* GXorReverse  */      0xf5,         /* src OR NOT dst */
 
75
    /* GXcopyInverted*/     0x0f,         /* NOT src */
 
76
    /* GXorInverted */      0xaf,         /* NOT src OR dst */
 
77
    /* GXnand       */      0x5f,         /* NOT src OR NOT dst */
 
78
    /* GXset        */      0xff,         /* 1 */
 
79
};
 
80
 
 
81
/* Definitions for the Chips and Technology BitBLT engine communication. */
 
82
/* These are done using Memory Mapped IO, of the registers */
 
83
/* BitBLT modes for register 93D0. */
 
84
 
 
85
#ifdef HIQV
 
86
#define ctPATCOPY               0xF0
 
87
#define ctLEFT2RIGHT            0x000
 
88
#define ctRIGHT2LEFT            0x100
 
89
#define ctTOP2BOTTOM            0x000
 
90
#define ctBOTTOM2TOP            0x200
 
91
#define ctSRCSYSTEM             0x400
 
92
#define ctDSTSYSTEM             0x800
 
93
#define ctSRCMONO               0x1000
 
94
#define ctBGTRANSPARENT         0x22000
 
95
#define ctCOLORTRANSENABLE      0x4000
 
96
#define ctCOLORTRANSDISABLE     0x0
 
97
#define ctCOLORTRANSDST         0x8000
 
98
#define ctCOLORTRANSROP         0x0
 
99
#define ctCOLORTRANSEQUAL       0x10000L
 
100
#define ctCOLORTRANSNEQUAL      0x0
 
101
#define ctPATMONO               0x40000L
 
102
#define ctPATSOLID              0x80000L
 
103
#define ctPATSTART0             0x000000L
 
104
#define ctPATSTART1             0x100000L
 
105
#define ctPATSTART2             0x200000L
 
106
#define ctPATSTART3             0x300000L
 
107
#define ctPATSTART4             0x400000L
 
108
#define ctPATSTART5             0x500000L
 
109
#define ctPATSTART6             0x600000L
 
110
#define ctPATSTART7             0x700000L
 
111
#define ctSRCFG                 0x000000L       /* Where is this for the 65550?? */
 
112
#else
 
113
#define ctPATCOPY               0xF0
 
114
#define ctTOP2BOTTOM            0x100
 
115
#define ctBOTTOM2TOP            0x000
 
116
#define ctLEFT2RIGHT            0x200
 
117
#define ctRIGHT2LEFT            0x000
 
118
#define ctSRCFG                 0x400
 
119
#define ctSRCMONO               0x800
 
120
#define ctPATMONO               0x1000
 
121
#define ctBGTRANSPARENT         0x2000
 
122
#define ctSRCSYSTEM             0x4000
 
123
#define ctPATSOLID              0x80000L
 
124
#define ctPATSTART0             0x00000L
 
125
#define ctPATSTART1             0x10000L
 
126
#define ctPATSTART2             0x20000L
 
127
#define ctPATSTART3             0x30000L
 
128
#define ctPATSTART4             0x40000L
 
129
#define ctPATSTART5             0x50000L
 
130
#define ctPATSTART6             0x60000L
 
131
#define ctPATSTART7             0x70000L
 
132
#endif
 
133
 
 
134
#define chipsFillPix(bpp,pixel) {\
 
135
    if (bpp == 8) \
 
136
    { \
 
137
        pixel = pixel & 0xff; \
 
138
    } \
 
139
    else if (bpp == 16) \
 
140
    { \
 
141
        pixel = pixel & 0xffff; \
 
142
    } \
 
143
}
 
144
 
 
145
static VOL8     *mmio;
 
146
static CARD32   byteStride;
 
147
static CARD32   bytesPerPixel;
 
148
static CARD32   pixelStride;
 
149
 
 
150
static void
 
151
chipsSet (ScreenPtr pScreen)
 
152
{
 
153
    KdScreenPriv(pScreen);
 
154
    chipsScreenInfo(pScreenPriv);
 
155
    
 
156
    mmio = chipss->mmio_base;
 
157
    byteStride = pScreenPriv->screen->fb[0].byteStride;
 
158
    bytesPerPixel = pScreenPriv->screen->fb[0].bitsPerPixel >> 3;
 
159
    pixelStride = pScreenPriv->screen->fb[0].pixelStride;
 
160
}
 
161
 
 
162
#ifdef HIQV
 
163
#define CHIPS_BR0       0x00    /* offset */
 
164
#define CHIPS_BR1       0x04    /* bg */
 
165
#define CHIPS_BR2       0x08    /* fg */
 
166
#define CHIPS_BR3       0x0c    /* monochrome */
 
167
#define CHIPS_BR4       0x10    /* bitblt */
 
168
#define CHIPS_BR5       0x14    /* pattern addr */
 
169
#define CHIPS_BR6       0x18    /* source addr */
 
170
#define CHIPS_BR7       0x1c    /* dst addr */
 
171
#define CHIPS_BR8       0x20    /* dst w/h */
 
172
#else
 
173
#define CHIPS_DR0       0x83d0
 
174
#define CHIPS_DR1       0x87d0
 
175
#define CHIPS_DR2       0x8bd0
 
176
#define CHIPS_DR3       0x8fd0
 
177
#define CHIPS_DR4       0x93d0
 
178
#define CHIPS_DR5       0x97d0
 
179
#define CHIPS_DR6       0x9bd0
 
180
#define CHIPS_DR7       0x9fd0
 
181
#endif
 
182
 
 
183
#define DBG(x)
 
184
 
 
185
static void
 
186
chipsPitch (int src, int dst)
 
187
{
 
188
    CARD32  p;
 
189
 
 
190
    p = ((dst & 0xffff) << 16) | (src & 0xffff);
 
191
    DBG(ErrorF ("\tpitch 0x%x\n", p));
 
192
#ifdef HIQV
 
193
    *(VOL32 *) (mmio + CHIPS_BR0) = p;
 
194
#else
 
195
    *(VOL32 *) (mmio + CHIPS_DR0) = p;
 
196
#endif
 
197
}
 
198
 
 
199
static void
 
200
chipsBg (Pixel   bg)
 
201
{
 
202
    DBG(ErrorF ("\tbg 0x%x\n", bg));
 
203
#ifdef HIQV
 
204
    *(VOL32 *) (mmio + CHIPS_BR1) = bg & 0xffff;
 
205
#else
 
206
    *(VOL32 *) (mmio + CHIPS_DR2) = bg;
 
207
#endif
 
208
}
 
209
 
 
210
static void
 
211
chipsFg (Pixel   fg)
 
212
{
 
213
    DBG(ErrorF ("\tfg 0x%x\n", fg));
 
214
#ifdef HIQV
 
215
    *(VOL32 *) (mmio + CHIPS_BR2) = fg;
 
216
#else
 
217
    *(VOL32 *) (mmio + CHIPS_DR3) = fg;
 
218
#endif
 
219
}
 
220
 
 
221
static void
 
222
chipsOp (CARD32 op)
 
223
{
 
224
    DBG(ErrorF ("\top 0x%x\n", op));
 
225
#ifdef HIQV
 
226
    *(VOL32 *) (mmio + CHIPS_BR4) = op;
 
227
#else
 
228
    *(VOL32 *) (mmio + CHIPS_DR4) = op;
 
229
#endif
 
230
}
 
231
    
 
232
static void
 
233
chipsRopSolid (int rop)
 
234
{
 
235
    CARD32  op;
 
236
    
 
237
    op = chipsSolidRop[rop] | ctTOP2BOTTOM | ctLEFT2RIGHT | ctPATSOLID | ctPATMONO;
 
238
    chipsOp (op);
 
239
}
 
240
 
 
241
static void
 
242
chipsSrc (int addr)
 
243
{
 
244
    DBG(ErrorF ("\tsrc 0x%x\n", addr));
 
245
#ifdef HIQV
 
246
    *(VOL32 *) (mmio + CHIPS_BR6) = addr;
 
247
#else
 
248
    *(VOL32 *) (mmio + CHIPS_DR5) = addr;
 
249
#endif
 
250
}
 
251
 
 
252
static void
 
253
chipsDst (int addr)
 
254
{
 
255
    DBG(ErrorF ("\tdst 0x%x\n", addr));
 
256
#ifdef HIQV
 
257
    *(VOL32 *) (mmio + CHIPS_BR7) = addr;
 
258
#else
 
259
    *(VOL32 *) (mmio + CHIPS_DR6) = addr;
 
260
#endif
 
261
}
 
262
 
 
263
static void
 
264
chipsWidthHeightGo (int w, int h)
 
265
{
 
266
    DBG(ErrorF ("\twidth height %d/%d\n", w, h));
 
267
#ifdef HIQV
 
268
    *(VOL32 *) (mmio + CHIPS_BR8) = ((h & 0xffff) << 16) | (w & 0xffff);
 
269
#else
 
270
    *(VOL32 *) (mmio + CHIPS_DR7) = ((h & 0xffff) << 16) | (w & 0xffff);
 
271
#endif
 
272
}
 
273
 
 
274
static void
 
275
chipsWaitIdle (void)
 
276
{
 
277
#ifdef HIQV
 
278
    int timeout = 0;
 
279
    CARD8   tmp;
 
280
    VOL32   *br4 = (VOL32 *) (mmio + CHIPS_BR4);
 
281
    
 
282
    DBG(ErrorF ("\tBR4 0x%x 0x%x\n", mmio + CHIPS_BR4, *br4));
 
283
    DBG(ErrorF ("\tXR20 0x%x\n", chipsReadXR (0, 0x20)));
 
284
    for (;;)
 
285
    {
 
286
        if ((*br4 & 0x80000000) == 0)
 
287
            break;
 
288
        tmp = chipsReadXR (0, 0x20);
 
289
        if ((tmp & 1) == 0)
 
290
            break;
 
291
        if (++timeout > 1000000)
 
292
        {
 
293
            ErrorF ("timeout\n");
 
294
            tmp = chipsReadXR (0, 0x20);
 
295
            chipsWriteXR (0, 0x20, tmp | 2);
 
296
            sleep (1);
 
297
            chipsWriteXR (0, 0x20, tmp);
 
298
            sleep (1);
 
299
        }
 
300
    }
 
301
#else
 
302
    while (*(VOL32 *) (mmio + CHIPS_DR4) & 0x00100000)
 
303
        ;
 
304
#endif
 
305
}
 
306
 
 
307
static void
 
308
chipsWaitMarker (ScreenPtr pScreen, int marker)
 
309
{
 
310
    chipsSet (pScreen);
 
311
    chipsWaitIdle ();
 
312
}
 
313
 
 
314
static Bool
 
315
chipsPrepareSolid (PixmapPtr    pPixmap,
 
316
                   int          alu,
 
317
                   Pixel        pm,
 
318
                   Pixel        fg)
 
319
{
 
320
    FbBits  depthMask;
 
321
    
 
322
    DBG(ErrorF ("PrepareSolid %d 0x%x\n", alu, fg));
 
323
    depthMask = FbFullMask(pPixmap->drawable.depth);
 
324
    if ((pm & depthMask) != depthMask)
 
325
        return FALSE;
 
326
    else
 
327
    {
 
328
        chipsSet (pPixmap->drawable.pScreen);
 
329
        chipsWaitIdle ();
 
330
        chipsFillPix(pPixmap->drawable.bitsPerPixel,fg);
 
331
        chipsFg (fg);
 
332
        chipsBg (fg);
 
333
        chipsRopSolid (alu);
 
334
        chipsPitch (byteStride, byteStride);
 
335
        return TRUE;
 
336
    }
 
337
}
 
338
 
 
339
static void
 
340
chipsSolid (int x1, int y1, int x2, int y2)
 
341
{
 
342
    CARD32  dst;
 
343
    int     w, h;
 
344
 
 
345
    DBG(ErrorF ("    Solid %dx%d %dx%d\n", x1, y1, x2, y2));
 
346
    dst = y1 * byteStride + x1 * bytesPerPixel;
 
347
    w = (x2 - x1) * bytesPerPixel;
 
348
    h = (y2 - y1);
 
349
    chipsWaitIdle ();
 
350
    chipsDst (dst);
 
351
    chipsWidthHeightGo (w, h);
 
352
}
 
353
 
 
354
static void
 
355
chipsDoneSolid (void)
 
356
{
 
357
}
 
358
 
 
359
static CARD32   copyOp;
 
360
 
 
361
static Bool
 
362
chipsPrepareCopy (PixmapPtr     pSrcPixmap,
 
363
                  PixmapPtr     pDstPixmap,
 
364
                  int           dx,
 
365
                  int           dy,
 
366
                  int           alu,
 
367
                  Pixel         pm)
 
368
{
 
369
    FbBits  depthMask;
 
370
    
 
371
    DBG(ErrorF ("PrepareSolid %d 0x%x\n", alu, fg));
 
372
    depthMask = FbFullMask(pDstPixmap->drawable.depth);
 
373
    if ((pm & depthMask) != depthMask)
 
374
        return FALSE;
 
375
    else
 
376
    {
 
377
        copyOp = chipsBltRop[alu];
 
378
        if (dy >= 0)
 
379
            copyOp |= ctTOP2BOTTOM;
 
380
        else
 
381
            copyOp |= ctBOTTOM2TOP;
 
382
        if (dx >= 0)
 
383
            copyOp |= ctLEFT2RIGHT;
 
384
        else
 
385
            copyOp |= ctRIGHT2LEFT;
 
386
        chipsSet (pDstPixmap->drawable.pScreen);
 
387
        chipsWaitIdle ();
 
388
        chipsOp (copyOp);
 
389
        chipsPitch (byteStride, byteStride);
 
390
        return TRUE;
 
391
    }
 
392
}
 
393
 
 
394
static void
 
395
chipsCopy (int srcX,
 
396
           int srcY,
 
397
           int dstX,
 
398
           int dstY,
 
399
           int w,
 
400
           int h)
 
401
{
 
402
    int src, dst;
 
403
    if ((copyOp & (ctTOP2BOTTOM|ctBOTTOM2TOP)) == ctBOTTOM2TOP)
 
404
    {
 
405
        src = (srcY + h - 1) * byteStride;
 
406
        dst = (dstY + h - 1) * byteStride;
 
407
    }
 
408
    else
 
409
    {
 
410
        src = srcY * byteStride;
 
411
        dst = dstY * byteStride;
 
412
    }
 
413
    if ((copyOp & (ctLEFT2RIGHT|ctRIGHT2LEFT)) == ctRIGHT2LEFT)
 
414
    {
 
415
        src = src + (srcX + w) * bytesPerPixel - 1;
 
416
        dst = dst + (dstX + w) * bytesPerPixel - 1;
 
417
    }
 
418
    else
 
419
    {
 
420
        src = src + srcX * bytesPerPixel;
 
421
        dst = dst + dstX * bytesPerPixel;
 
422
    }
 
423
    chipsWaitIdle ();
 
424
    chipsSrc (src);
 
425
    chipsDst (dst);
 
426
    chipsWidthHeightGo (w * bytesPerPixel, h);
 
427
}
 
428
 
 
429
static void
 
430
chipsDoneCopy (void)
 
431
{
 
432
}
 
433
 
 
434
Bool
 
435
chipsDrawInit (ScreenPtr pScreen)
 
436
{
 
437
    KdScreenPriv(pScreen);
 
438
    chipsScreenInfo(pScreenPriv);
 
439
 
 
440
    switch (pScreenPriv->screen->fb[0].bitsPerPixel) {
 
441
    case 8:
 
442
    case 16:
 
443
        break;
 
444
    default:
 
445
        return FALSE;
 
446
    }
 
447
        
 
448
    memset(&chipss->kaa, 0, sizeof(KaaScreenInfoRec));
 
449
    chipss->kaa.waitMarker      = chipsWaitMarker;
 
450
    chipss->kaa.PrepareSolid    = chipsPrepareSolid;
 
451
    chipss->kaa.Solid           = chipsSolid;
 
452
    chipss->kaa.DoneSolid       = chipsDoneSolid;
 
453
    chipss->kaa.PrepareCopy     = chipsPrepareCopy;
 
454
    chipss->kaa.Copy            = chipsCopy;
 
455
    chipss->kaa.DoneCopy        = chipsDoneCopy;
 
456
 
 
457
    if (!kaaDrawInit (pScreen, &chipss->kaa))
 
458
        return FALSE;
 
459
    
 
460
    return TRUE;
 
461
}
 
462
 
 
463
void
 
464
chipsDrawEnable (ScreenPtr pScreen)
 
465
{
 
466
    KdScreenPriv(pScreen);
 
467
    chipsScreenInfo(pScreenPriv);
 
468
    CARD8 mode = 0x00;
 
469
    
 
470
    switch (pScreenPriv->screen->fb[0].bitsPerPixel) {
 
471
    case 8:
 
472
        mode = 0x00;
 
473
        break;
 
474
    case 16:
 
475
        mode = 0x10;
 
476
        break;
 
477
    }
 
478
    chipsSet (pScreen);
 
479
    chipsWaitIdle ();
 
480
    chipsWriteXR (chipss, 0x20, mode);
 
481
    
 
482
    kaaMarkSync (pScreen);
 
483
}
 
484
 
 
485
void
 
486
chipsDrawDisable (ScreenPtr pScreen)
 
487
{
 
488
}
 
489
 
 
490
void
 
491
chipsDrawFini (ScreenPtr pScreen)
 
492
{
 
493
}
 
494