summaryrefslogtreecommitdiff
path: root/src/atimach64exa.c
blob: 90cc2af994a76a9956e2a7616a582c6d011b9261 (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
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
/*
 * Copyright 2003 through 2004 by Marc Aurele La France (TSI @ UQV), tsi@xfree86.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 Marc Aurele La France not be used in advertising or
 * publicity pertaining to distribution of the software without specific,
 * written prior permission.  Marc Aurele La France makes no representations
 * about the suitability of this software for any purpose.  It is provided
 * "as-is" without express or implied warranty.
 *
 * MARC AURELE LA FRANCE DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.  IN NO
 * EVENT SHALL MARC AURELE LA FRANCE 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.
 */
/*
 * Copyright 1999-2000 Precision Insight, Inc., Cedar Park, Texas.
 * All Rights Reserved.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to
 * deal in the Software without restriction, including without limitation the
 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
 * sell copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice (including the next
 * paragraph) shall be included in all copies or substantial portions of the
 * Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.  IN NO EVENT SHALL
 * PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
 * DEALINGS IN THE SOFTWARE.
 */
/* 
 * DRI support by:
 *    Manuel Teira
 *    Leif Delgass <ldelgass@retinalburn.net>
 *
 * EXA support by:
 *    Jakub Stachowski <qbast@go2.pl>
 *    George Sapountzis <gsap7@yahoo.gr>
 */

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

#include <string.h>

#include "ati.h"
#include "atichip.h"
#include "atidri.h"
#include "atimach64accel.h"
#include "atimach64io.h"
#include "atipriv.h"
#include "atiregs.h"

#ifdef XF86DRI_DEVEL
#include "mach64_dri.h"
#include "mach64_sarea.h"
#endif

#ifdef USE_EXA
extern CARD8 ATIMach64ALU[];

extern void
ATIMach64ValidateClip
(
    ATIPtr pATI,
    int sc_left,
    int sc_right,
    int sc_top,
    int sc_bottom
);

#if 0
#define MACH64_TRACE(x)				\
do {						\
    ErrorF("Mach64(%s): ", __FUNCTION__);	\
    ErrorF x;					\
} while(0)
#else
#define MACH64_TRACE(x) do { } while(0)
#endif

#if 0
#define MACH64_FALLBACK(x)			\
do {						\
    ErrorF("Fallback(%s): ", __FUNCTION__);	\
    ErrorF x;					\
    return FALSE;				\
} while (0)
#else
#define MACH64_FALLBACK(x) return FALSE
#endif

static void
Mach64WaitMarker(ScreenPtr pScreenInfo, int Marker)
{
    ATIMach64Sync(xf86Screens[pScreenInfo->myNum]);
}

static Bool
Mach64GetDatatypeBpp(PixmapPtr pPix, CARD32 *pix_width)
{
	int bpp = pPix->drawable.bitsPerPixel;

	switch (bpp) {
	case 8:
		*pix_width =
			SetBits(PIX_WIDTH_8BPP, DP_DST_PIX_WIDTH) |
			SetBits(PIX_WIDTH_8BPP, DP_SRC_PIX_WIDTH) |
			SetBits(PIX_WIDTH_1BPP, DP_HOST_PIX_WIDTH);
		break;
	case 16:
		*pix_width =
			SetBits(PIX_WIDTH_16BPP, DP_DST_PIX_WIDTH) |
			SetBits(PIX_WIDTH_16BPP, DP_SRC_PIX_WIDTH) |
			SetBits(PIX_WIDTH_1BPP, DP_HOST_PIX_WIDTH);
		break;
	case 24:
		*pix_width =
			SetBits(PIX_WIDTH_8BPP, DP_DST_PIX_WIDTH) |
			SetBits(PIX_WIDTH_8BPP, DP_SRC_PIX_WIDTH) |
			SetBits(PIX_WIDTH_1BPP, DP_HOST_PIX_WIDTH);
		break;
	case 32:
		*pix_width =
			SetBits(PIX_WIDTH_32BPP, DP_DST_PIX_WIDTH) |
			SetBits(PIX_WIDTH_32BPP, DP_SRC_PIX_WIDTH) |
			SetBits(PIX_WIDTH_1BPP, DP_HOST_PIX_WIDTH);
		break;
	default:
		MACH64_FALLBACK(("Unsupported bpp: %d\n", bpp));
	}

#if X_BYTE_ORDER == X_LITTLE_ENDIAN

        *pix_width |= DP_BYTE_PIX_ORDER;

#endif /* X_BYTE_ORDER */

	return TRUE;
}

static Bool
Mach64GetOffsetPitch(PixmapPtr pPix, int bpp, CARD32 *pitch_offset,
		     unsigned int offset, unsigned int pitch)
{
#if 0
    ScrnInfoPtr pScreenInfo = xf86Screens[pPix->drawable.pScreen->myNum];
    ATIPtr pATI = ATIPTR(pScreenInfo);

    if (pitch % pATI->pExa->pixmapPitchAlign != 0)
        MACH64_FALLBACK(("Bad pitch 0x%08x\n", pitch));

    if (offset % pATI->pExa->pixmapOffsetAlign != 0)
        MACH64_FALLBACK(("Bad offset 0x%08x\n", offset));
#endif

    /* pixels / 8 = ((bytes * 8) / bpp) / 8 = bytes / bpp */
    pitch = pitch / bpp;

    /* bytes / 8 */
    offset = offset >> 3;

    *pitch_offset = ((pitch  << 22) | (offset <<  0));

    return TRUE;
}

static Bool
Mach64GetPixmapOffsetPitch(PixmapPtr pPix, CARD32 *pitch_offset)
{
    CARD32 pitch, offset;
    int bpp;

    bpp = pPix->drawable.bitsPerPixel;
    if (bpp == 24)
        bpp = 8;

    pitch = exaGetPixmapPitch(pPix);
    offset = exaGetPixmapOffset(pPix);

    return Mach64GetOffsetPitch(pPix, bpp, pitch_offset, offset, pitch);
}

static Bool
Mach64PrepareCopy
(
    PixmapPtr pSrcPixmap,
    PixmapPtr pDstPixmap,
    int       xdir,
    int       ydir,
    int       alu,
    Pixel     planemask
)
{
    ScrnInfoPtr pScreenInfo = xf86Screens[pDstPixmap->drawable.pScreen->myNum];
    ATIPtr pATI = ATIPTR(pScreenInfo);
    CARD32 src_pitch_offset, dst_pitch_offset, dp_pix_width;

    ATIDRISync(pScreenInfo);

    if (!Mach64GetDatatypeBpp(pDstPixmap, &dp_pix_width))
        return FALSE;
    if (!Mach64GetPixmapOffsetPitch(pSrcPixmap, &src_pitch_offset))
        return FALSE;
    if (!Mach64GetPixmapOffsetPitch(pDstPixmap, &dst_pitch_offset))
        return FALSE;

    ATIMach64WaitForFIFO(pATI, 7);
    outf(DP_WRITE_MASK, planemask);
    outf(DP_PIX_WIDTH, dp_pix_width);
    outf(SRC_OFF_PITCH, src_pitch_offset);
    outf(DST_OFF_PITCH, dst_pitch_offset); 
    
    outf(DP_SRC, DP_MONO_SRC_ALLONES |
        SetBits(SRC_BLIT, DP_FRGD_SRC) | SetBits(SRC_BKGD, DP_BKGD_SRC));
    outf(DP_MIX, SetBits(ATIMach64ALU[alu], DP_FRGD_MIX));

    outf(CLR_CMP_CNTL, CLR_CMP_FN_FALSE);

    pATI->dst_cntl = 0;

    if (ydir > 0)
        pATI->dst_cntl |= DST_Y_DIR;
    if (xdir > 0)
        pATI->dst_cntl |= DST_X_DIR;

    if (pATI->XModifier == 1)
        outf(DST_CNTL, pATI->dst_cntl);
    else
        pATI->dst_cntl |= DST_24_ROT_EN;

    return TRUE;
}

static void
Mach64Copy
(
    PixmapPtr pDstPixmap,
    int       srcX,
    int       srcY,
    int       dstX,
    int       dstY,
    int       w,
    int       h
)
{
    ScrnInfoPtr pScreenInfo = xf86Screens[pDstPixmap->drawable.pScreen->myNum];
    ATIPtr pATI = ATIPTR(pScreenInfo);

    srcX *= pATI->XModifier;
    dstY *= pATI->XModifier;
    w    *= pATI->XModifier;

    ATIDRISync(pScreenInfo);

    /* Disable clipping if it gets in the way */
    ATIMach64ValidateClip(pATI, dstX, dstX + w - 1, dstY, dstY + h - 1);

    if (!(pATI->dst_cntl & DST_X_DIR))
    {
        srcX += w - 1;
        dstX += w - 1;
    }

    if (!(pATI->dst_cntl & DST_Y_DIR))
    {
        srcY += h - 1;
        dstY += h - 1;
    }

    if (pATI->XModifier != 1)
        outf(DST_CNTL, pATI->dst_cntl | SetBits((dstX / 4) % 6, DST_24_ROT));

    ATIMach64WaitForFIFO(pATI, 4);
    outf(SRC_Y_X, SetWord(srcX, 1) | SetWord(srcY, 0));
    outf(SRC_WIDTH1, w);
    outf(DST_Y_X, SetWord(dstX, 1) | SetWord(dstY, 0));
    outf(DST_HEIGHT_WIDTH, SetWord(w, 1) | SetWord(h, 0));

    /*
     * On VTB's and later, the engine will randomly not wait for a copy
     * operation to commit its results to video memory before starting the next
     * one.  The probability of such occurrences increases with GUI_WB_FLUSH
     * (or GUI_WB_FLUSH_P) setting, bitsPerPixel and/or CRTC clock.  This
     * would point to some kind of video memory bandwidth problem were it noti
     * for the fact that the problem occurs less often (but still occurs) when
     * copying larger rectangles.
     */
    if ((pATI->Chip >= ATI_CHIP_264VTB) && !pATI->OptionDevel)
    {
        exaMarkSync(pScreenInfo->pScreen); /* Force sync. */
        exaWaitSync(pScreenInfo->pScreen); /* Sync and notify EXA. */
    }
}

static void Mach64DoneCopy(PixmapPtr pDstPixmap) { }

static Bool
Mach64PrepareSolid
(
    PixmapPtr pPixmap,
    int       alu, 
    Pixel     planemask, 
    Pixel     fg
)
{
    ScrnInfoPtr pScreenInfo = xf86Screens[pPixmap->drawable.pScreen->myNum];
    ATIPtr pATI = ATIPTR(pScreenInfo);
    CARD32 dst_pitch_offset, dp_pix_width;

    ATIDRISync(pScreenInfo);

    if (!Mach64GetDatatypeBpp(pPixmap, &dp_pix_width))
        return FALSE;
    if (!Mach64GetPixmapOffsetPitch(pPixmap, &dst_pitch_offset))
        return FALSE;

    ATIMach64WaitForFIFO(pATI, 7);
    outf(DP_WRITE_MASK, planemask);
    outf(DP_PIX_WIDTH, dp_pix_width);
    outf(DST_OFF_PITCH, dst_pitch_offset); 

    outf(DP_SRC, DP_MONO_SRC_ALLONES |
        SetBits(SRC_FRGD, DP_FRGD_SRC) | SetBits(SRC_BKGD, DP_BKGD_SRC));
    outf(DP_FRGD_CLR, fg);
    outf(DP_MIX, SetBits(ATIMach64ALU[alu], DP_FRGD_MIX));

    outf(CLR_CMP_CNTL, CLR_CMP_FN_FALSE);

    if (pATI->XModifier == 1)
        outf(DST_CNTL, DST_X_DIR | DST_Y_DIR);

    return TRUE;
}

static void
Mach64Solid
(
    PixmapPtr pPixmap, 
    int       x1, 
    int       y1, 
    int       x2, 
    int       y2
)
{
    ScrnInfoPtr pScreenInfo = xf86Screens[pPixmap->drawable.pScreen->myNum];
    ATIPtr pATI = ATIPTR(pScreenInfo);

    int x = x1;
    int y = y1;
    int w = x2-x1;
    int h = y2-y1;

    ATIDRISync(pScreenInfo);

    if (pATI->XModifier != 1)
    {
        x *= pATI->XModifier;
        w *= pATI->XModifier;

        outf(DST_CNTL, SetBits((x / 4) % 6, DST_24_ROT) |
            (DST_X_DIR | DST_Y_DIR | DST_24_ROT_EN));
    }

    /* Disable clipping if it gets in the way */
    ATIMach64ValidateClip(pATI, x, x + w - 1, y, y + h - 1);

    ATIMach64WaitForFIFO(pATI, 2);
    outf(DST_Y_X, SetWord(x, 1) | SetWord(y, 0));
    outf(DST_HEIGHT_WIDTH, SetWord(w, 1) | SetWord(h, 0));
}

static void Mach64DoneSolid(PixmapPtr pPixmap) { }

/*
 * Memcpy-based UTS.
 */
static Bool
Mach64UploadToScreen(PixmapPtr pDst, int x, int y, int w, int h,
    char *src, int src_pitch)
{
    char  *dst        = pDst->devPrivate.ptr;
    int    dst_pitch  = exaGetPixmapPitch(pDst);

    int bpp    = pDst->drawable.bitsPerPixel;
    int cpp    = (bpp + 7) / 8;
    int wBytes = w * cpp;

    exaWaitSync(pDst->drawable.pScreen);

    dst += (x * cpp) + (y * dst_pitch);

    while (h--) {
        memcpy(dst, src, wBytes);
        src += src_pitch;
        dst += dst_pitch;
    }

    return TRUE;
}

/*
 * Memcpy-based DFS.
 */
static Bool
Mach64DownloadFromScreen(PixmapPtr pSrc, int x, int y, int w, int h,
    char *dst, int dst_pitch)
{
    char  *src        = pSrc->devPrivate.ptr;
    int    src_pitch  = exaGetPixmapPitch(pSrc);

    int bpp    = pSrc->drawable.bitsPerPixel;
    int cpp    = (bpp + 7) / 8;
    int wBytes = w * cpp;

    exaWaitSync(pSrc->drawable.pScreen);

    src += (x * cpp) + (y * src_pitch);

    while (h--) {
        memcpy(dst, src, wBytes);
        src += src_pitch;
        dst += dst_pitch;
    }

    return TRUE;
}

/* Compute log base 2 of val. */
static __inline__ int Mach64Log2(int val)
{
    int bits;

    for (bits = 0; val != 0; val >>= 1, ++bits)
        ;
    return bits - 1;
}

/*
 * Memory layour for EXA with DRI (no local_textures):
 * | front  | back   | depth  | textures | pixmaps, xv | c |
 *
 * 1024x768@16bpp with 8 MB:
 * | 1.5 MB | 1.5 MB | 1.5 MB | 0        | ~3.5 MB     | c |
 *
 * 1024x768@32bpp with 8 MB:
 * | 3.0 MB | 3.0 MB | 1.5 MB | 0        | ~0.5 MB     | c |
 *
 * "c" is the hw cursor which occupies 1KB
 */
static void
Mach64SetupMemEXA(ScreenPtr pScreen)
{
    ScrnInfoPtr pScreenInfo = xf86Screens[pScreen->myNum];
    ATIPtr pATI = ATIPTR(pScreenInfo);

    int cpp = (pScreenInfo->bitsPerPixel + 7) / 8;
    /* front and back buffer */
    int bufferSize = pScreenInfo->virtualY * pScreenInfo->displayWidth * cpp;
    /* always 16-bit z-buffer */
    int depthSize  = pScreenInfo->virtualY * pScreenInfo->displayWidth * 2;

    ExaDriverPtr pExa = pATI->pExa;

    pExa->memoryBase = pATI->pMemory;
    pExa->memorySize = pScreenInfo->videoRam * 1024;
    pExa->offScreenBase = bufferSize;

#ifdef XF86DRI_DEVEL
    if (pATI->directRenderingEnabled)
    {
	ATIDRIServerInfoPtr pATIDRIServer = pATI->pDRIServerInfo;
	Bool is_pci = pATIDRIServer->IsPCI;

	int textureSize = 0;
	int pixmapCache = 0;
	int next = 0;

	/* front buffer */
	pATIDRIServer->frontOffset = 0;
	pATIDRIServer->frontPitch = pScreenInfo->displayWidth;
	next += bufferSize;

	/* back buffer */
	pATIDRIServer->backOffset = next;
	pATIDRIServer->backPitch = pScreenInfo->displayWidth;
	next += bufferSize;

	/* depth buffer */
	pATIDRIServer->depthOffset = next;
	pATIDRIServer->depthPitch = pScreenInfo->displayWidth;
	next += depthSize;

	/* ATIScreenInit does check for the this condition. */
	if (next > pExa->memorySize)
	{
	    xf86DrvMsg(pScreen->myNum, X_WARNING,
		"DRI static buffer allocation failed, disabling DRI --"
		"need at least %d kB video memory\n", next / 1024 );
	    ATIDRICloseScreen(pScreen);
	    pATI->directRenderingEnabled = FALSE;
	}

	/* local textures */

	/* Reserve approx. half of offscreen memory for local textures */
	textureSize = (pExa->memorySize - next) / 2;

	/* In case DRI requires more offscreen memory than available,
	 * should not happen as ATIScreenInit would have not enabled DRI */
	if (textureSize < 0)
	    textureSize = 0;

	/* Try for enough pixmap cache for a full viewport */
	pixmapCache = (pExa->memorySize - next) - textureSize;
	if (pixmapCache < bufferSize)
	    textureSize = 0;

	/* Don't allocate a local texture heap for AGP unless requested */
	if ( !is_pci && !pATI->OptionLocalTextures )
	    textureSize = 0;

	if (textureSize > 0)
	{
	    int l = Mach64Log2(textureSize / MACH64_NR_TEX_REGIONS);
	    if (l < MACH64_LOG_TEX_GRANULARITY)
		l = MACH64_LOG_TEX_GRANULARITY;
	    pATIDRIServer->logTextureGranularity = l;

	    /* Round the texture size down to the nearest whole number of
	     * texture regions.
	     */
	    textureSize = (textureSize >> l) << l;
	}

	/* Set a minimum usable local texture heap size.  This will fit
	 * two 256x256 textures.  We check this after any rounding of
	 * the texture area.
	 */
	if (textureSize < 256*256 * cpp * 2)
	    textureSize = 0;

	/* Disable DRI for PCI if cannot allocate a local texture heap */
	if ( is_pci && textureSize == 0 )
	{
	    xf86DrvMsg(pScreen->myNum, X_WARNING,
		"Not enough memory for local textures, disabling DRI\n");
	    ATIDRICloseScreen(pScreen);
	    pATI->directRenderingEnabled = FALSE;
	}

	pATIDRIServer->textureOffset = next;
	pATIDRIServer->textureSize = textureSize;
	next += textureSize;

	if (pATI->directRenderingEnabled)
	    pExa->offScreenBase = next;
    }
#endif /* XF86DRI_DEVEL */

    xf86DrvMsg(pScreen->myNum, X_INFO,
        "EXA memory management initialized\n"
        "\t base     :  %10p\n"
        "\t offscreen: +%10lx\n"
        "\t size     : +%10lx\n"
        "\t cursor   :  %10p\n",
        pExa->memoryBase,
        pExa->offScreenBase,
        pExa->memorySize,
        pATI->pCursorImage);

    if (TRUE || xf86GetVerbosity() > 1)
    {
        int offscreen = pExa->memorySize - pExa->offScreenBase;
        int viewport = bufferSize;
        int dvdframe = 720*480*cpp; /* enough for single-buffered DVD */

        xf86DrvMsg(pScreen->myNum, X_INFO,
            "Will use %d kB of offscreen memory for EXA\n"
            "\t\t or %5.2f viewports (composite)\n"
            "\t\t or %5.2f dvdframes (xvideo)\n",
            offscreen / 1024,
            1.0 * offscreen / viewport,
            1.0 * offscreen / dvdframe);
    }

#ifdef XF86DRI_DEVEL
    if (pATI->directRenderingEnabled)
    {
        ATIDRIServerInfoPtr pATIDRIServer = pATI->pDRIServerInfo;

        xf86DrvMsg(pScreen->myNum, X_INFO,
                   "Will use back  buffer at offset 0x%x\n",
                   pATIDRIServer->backOffset);

        xf86DrvMsg(pScreen->myNum, X_INFO,
                   "Will use depth buffer at offset 0x%x\n",
                   pATIDRIServer->depthOffset);

        if (pATIDRIServer->textureSize > 0)
        {
            xf86DrvMsg(pScreen->myNum, X_INFO,
                   "Will use %d kB for local textures at offset 0x%x\n",
                   pATIDRIServer->textureSize/1024,
                   pATIDRIServer->textureOffset);
        }
    }
#endif /* XF86DRI_DEVEL */

    pExa->pixmapOffsetAlign = 64;
    pExa->pixmapPitchAlign = 64;

    pExa->flags = EXA_OFFSCREEN_PIXMAPS;

    pExa->maxX = ATIMach64MaxX;
    pExa->maxY = ATIMach64MaxY;
}

Bool ATIMach64ExaInit(ScreenPtr pScreen)
{
    ScrnInfoPtr pScreenInfo = xf86Screens[pScreen->myNum];
    ATIPtr pATI = ATIPTR(pScreenInfo);
    ExaDriverPtr pExa;

    /* FIXME: which chips support EXA ? */
    if (pATI->Chip < ATI_CHIP_264CT)
    {
        xf86DrvMsg(pScreenInfo->scrnIndex, X_ERROR,
            "EXA is not supported for ATI chips earlier than "
            "the ATI Mach64.\n");
        return FALSE;
    }

    pExa = exaDriverAlloc();
    if (!pExa)
        return FALSE;

    pATI->pExa = pExa;

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

    Mach64SetupMemEXA(pScreen);

    pExa->WaitMarker = Mach64WaitMarker;

    pExa->PrepareSolid = Mach64PrepareSolid;
    pExa->Solid = Mach64Solid;
    pExa->DoneSolid = Mach64DoneSolid;

    pExa->PrepareCopy = Mach64PrepareCopy;
    pExa->Copy = Mach64Copy;
    pExa->DoneCopy = Mach64DoneCopy;

    /* EXA hits more optimized paths when it does not have to fallback because
     * of missing UTS/DFS, hook memcpy-based UTS/DFS.
     */
    pExa->UploadToScreen = Mach64UploadToScreen;
    pExa->DownloadFromScreen = Mach64DownloadFromScreen;

    if (!exaDriverInit(pScreen, pATI->pExa)) {
	xfree(pATI->pExa);
	pATI->pExa = NULL;
	return FALSE;
    }

    return TRUE;
}
#endif