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
|
/*
* Copyright 2005 Eric Anholt
* Copyright 2005 Benjamin Herrenschmidt
* 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 NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS 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.
*
* Authors:
* Eric Anholt <anholt@FreeBSD.org>
* Zack Rusin <zrusin@trolltech.com>
* Benjamin Herrenschmidt <benh@kernel.crashing.org>
*
*/
#if defined(ACCEL_MMIO) && defined(ACCEL_CP)
#error Cannot define both MMIO and CP acceleration!
#endif
#if !defined(UNIXCPP) || defined(ANSICPP)
#define FUNC_NAME_CAT(prefix,suffix) prefix##suffix
#else
#define FUNC_NAME_CAT(prefix,suffix) prefix/**/suffix
#endif
#ifdef ACCEL_MMIO
#define FUNC_NAME(prefix) FUNC_NAME_CAT(prefix,MMIO)
#else
#ifdef ACCEL_CP
#define FUNC_NAME(prefix) FUNC_NAME_CAT(prefix,CP)
#else
#error No accel type defined!
#endif
#endif
#include <string.h>
#include "radeon.h"
#include "atidri.h"
#include "exa.h"
#include "fbdevhw.h"
static void
FUNC_NAME(RADEONSync)(ScreenPtr pScreen, int marker)
{
TRACE;
FUNC_NAME(RADEONWaitForIdle)(xf86Screens[pScreen->myNum]);
}
static Bool
FUNC_NAME(RADEONPrepareSolid)(PixmapPtr pPix, int alu, Pixel pm, Pixel fg)
{
RINFO_FROM_SCREEN(pPix->drawable.pScreen);
CARD32 datatype, dst_pitch_offset;
ACCEL_PREAMBLE();
TRACE;
if (pPix->drawable.bitsPerPixel == 24)
RADEON_FALLBACK(("24bpp unsupported\n"));
if (!RADEONGetDatatypeBpp(pPix->drawable.bitsPerPixel, &datatype))
RADEON_FALLBACK(("RADEONGetDatatypeBpp failed\n"));
if (!RADEONGetPixmapOffsetPitch(pPix, &dst_pitch_offset))
RADEON_FALLBACK(("RADEONGetPixmapOffsetPitch failed\n"));
RADEON_SWITCH_TO_2D();
BEGIN_ACCEL(5);
OUT_ACCEL_REG(RADEON_DP_GUI_MASTER_CNTL,
RADEON_GMC_DST_PITCH_OFFSET_CNTL |
RADEON_GMC_BRUSH_SOLID_COLOR |
(datatype << 8) |
RADEON_GMC_SRC_DATATYPE_COLOR |
RADEON_ROP[alu].pattern |
RADEON_GMC_CLR_CMP_CNTL_DIS);
OUT_ACCEL_REG(RADEON_DP_BRUSH_FRGD_CLR, fg);
OUT_ACCEL_REG(RADEON_DP_WRITE_MASK, pm);
OUT_ACCEL_REG(RADEON_DP_CNTL,
(RADEON_DST_X_LEFT_TO_RIGHT | RADEON_DST_Y_TOP_TO_BOTTOM));
OUT_ACCEL_REG(RADEON_DST_PITCH_OFFSET, dst_pitch_offset);
FINISH_ACCEL();
return TRUE;
}
static void
FUNC_NAME(RADEONSolid)(PixmapPtr pPix, int x1, int y1, int x2, int y2)
{
RINFO_FROM_SCREEN(pPix->drawable.pScreen);
ACCEL_PREAMBLE();
TRACE;
BEGIN_ACCEL(2);
OUT_ACCEL_REG(RADEON_DST_Y_X, (y1 << 16) | x1);
OUT_ACCEL_REG(RADEON_DST_HEIGHT_WIDTH, ((y2 - y1) << 16) | (x2 - x1));
FINISH_ACCEL();
}
static void
FUNC_NAME(RADEONDoneSolid)(PixmapPtr pPix)
{
TRACE;
}
static Bool
FUNC_NAME(RADEONPrepareCopy)(PixmapPtr pSrc, PixmapPtr pDst,
int xdir, int ydir,
int rop,
Pixel planemask)
{
RINFO_FROM_SCREEN(pDst->drawable.pScreen);
CARD32 datatype, src_pitch_offset, dst_pitch_offset;
ACCEL_PREAMBLE();
TRACE;
info->xdir = xdir;
info->ydir = ydir;
if (pDst->drawable.bitsPerPixel == 24)
RADEON_FALLBACK(("24bpp unsupported"));
if (!RADEONGetDatatypeBpp(pDst->drawable.bitsPerPixel, &datatype))
RADEON_FALLBACK(("RADEONGetDatatypeBpp failed\n"));
if (!RADEONGetPixmapOffsetPitch(pSrc, &src_pitch_offset))
RADEON_FALLBACK(("RADEONGetPixmapOffsetPitch source failed\n"));
if (!RADEONGetPixmapOffsetPitch(pDst, &dst_pitch_offset))
RADEON_FALLBACK(("RADEONGetPixmapOffsetPitch dest failed\n"));
RADEON_SWITCH_TO_2D();
BEGIN_ACCEL(5);
OUT_ACCEL_REG(RADEON_DP_GUI_MASTER_CNTL,
RADEON_GMC_DST_PITCH_OFFSET_CNTL |
RADEON_GMC_SRC_PITCH_OFFSET_CNTL |
RADEON_GMC_BRUSH_NONE |
(datatype << 8) |
RADEON_GMC_SRC_DATATYPE_COLOR |
RADEON_ROP[rop].rop |
RADEON_DP_SRC_SOURCE_MEMORY |
RADEON_GMC_CLR_CMP_CNTL_DIS);
OUT_ACCEL_REG(RADEON_DP_WRITE_MASK, planemask);
OUT_ACCEL_REG(RADEON_DP_CNTL,
((xdir >= 0 ? RADEON_DST_X_LEFT_TO_RIGHT : 0) |
(ydir >= 0 ? RADEON_DST_Y_TOP_TO_BOTTOM : 0)));
OUT_ACCEL_REG(RADEON_DST_PITCH_OFFSET, dst_pitch_offset);
OUT_ACCEL_REG(RADEON_SRC_PITCH_OFFSET, src_pitch_offset);
FINISH_ACCEL();
return TRUE;
}
static void
FUNC_NAME(RADEONCopy)(PixmapPtr pDst,
int srcX, int srcY,
int dstX, int dstY,
int w, int h)
{
RINFO_FROM_SCREEN(pDst->drawable.pScreen);
ACCEL_PREAMBLE();
TRACE;
if (info->xdir < 0) {
srcX += w - 1;
dstX += w - 1;
}
if (info->ydir < 0) {
srcY += h - 1;
dstY += h - 1;
}
BEGIN_ACCEL(3);
OUT_ACCEL_REG(RADEON_SRC_Y_X, (srcY << 16) | srcX);
OUT_ACCEL_REG(RADEON_DST_Y_X, (dstY << 16) | dstX);
OUT_ACCEL_REG(RADEON_DST_HEIGHT_WIDTH, (h << 16) | w);
FINISH_ACCEL();
}
static void
FUNC_NAME(RADEONDoneCopy)(PixmapPtr pDst)
{
TRACE;
}
static Bool
FUNC_NAME(RADEONUploadToScreen)(PixmapPtr pDst, int x, int y, int w, int h,
char *src, int src_pitch)
{
#if X_BYTE_ORDER == X_BIG_ENDIAN || defined(ACCEL_CP)
RINFO_FROM_SCREEN(pDst->drawable.pScreen);
#endif
CARD8 *dst = pDst->devPrivate.ptr;
unsigned int dst_pitch = exaGetPixmapPitch(pDst);
unsigned int bpp = pDst->drawable.bitsPerPixel;
#ifdef ACCEL_CP
unsigned int hpass;
CARD32 buf_pitch;
#endif
#if X_BYTE_ORDER == X_BIG_ENDIAN
unsigned char *RADEONMMIO = info->MMIO;
unsigned int swapper = info->ModeReg.surface_cntl &
~(RADEON_NONSURF_AP0_SWP_32BPP | RADEON_NONSURF_AP1_SWP_32BPP |
RADEON_NONSURF_AP0_SWP_16BPP | RADEON_NONSURF_AP1_SWP_16BPP);
#endif
TRACE;
if (bpp < 8)
return FALSE;
#ifdef ACCEL_CP
if (info->directRenderingEnabled) {
CARD8 *buf;
int cpp = bpp / 8;
ACCEL_PREAMBLE();
dst += (x * cpp) + (y * dst_pitch);
RADEON_SWITCH_TO_2D();
while ((buf = RADEONHostDataBlit(pScrn,
cpp, w, dst_pitch, &buf_pitch,
&dst, &h, &hpass)) != 0) {
RADEONHostDataBlitCopyPass(pScrn, cpp, buf, (unsigned char *)src,
hpass, buf_pitch, src_pitch);
src += hpass * src_pitch;
}
exaMarkSync(pDst->drawable.pScreen);
return TRUE;
}
#endif
/* Do we need that sync here ? probably not .... */
exaWaitSync(pDst->drawable.pScreen);
#if X_BYTE_ORDER == X_BIG_ENDIAN
switch(bpp) {
case 15:
case 16:
swapper |= RADEON_NONSURF_AP0_SWP_16BPP
| RADEON_NONSURF_AP1_SWP_16BPP;
break;
case 24:
case 32:
swapper |= RADEON_NONSURF_AP0_SWP_32BPP
| RADEON_NONSURF_AP1_SWP_32BPP;
break;
}
OUTREG(RADEON_SURFACE_CNTL, swapper);
#endif
w *= bpp / 8;
dst += (x * bpp / 8) + (y * dst_pitch);
while (h--) {
memcpy(dst, src, w);
src += src_pitch;
dst += dst_pitch;
}
#if X_BYTE_ORDER == X_BIG_ENDIAN
/* restore byte swapping */
OUTREG(RADEON_SURFACE_CNTL, info->ModeReg.surface_cntl);
#endif
return TRUE;
}
static Bool
FUNC_NAME(RADEONDownloadFromScreen)(PixmapPtr pSrc, int x, int y, int w, int h,
char *dst, int dst_pitch)
{
#if X_BYTE_ORDER == X_BIG_ENDIAN
RINFO_FROM_SCREEN(pSrc->drawable.pScreen);
unsigned char *RADEONMMIO = info->MMIO;
unsigned int swapper = info->ModeReg.surface_cntl &
~(RADEON_NONSURF_AP0_SWP_32BPP | RADEON_NONSURF_AP1_SWP_32BPP |
RADEON_NONSURF_AP0_SWP_16BPP | RADEON_NONSURF_AP1_SWP_16BPP);
#endif
unsigned char *src = pSrc->devPrivate.ptr;
int src_pitch = exaGetPixmapPitch(pSrc);
int bpp = pSrc->drawable.bitsPerPixel;
TRACE;
/*
* This is currently done without DMA until I have ironed out the
* various endian issues with R300 among others
*/
exaWaitSync(pSrc->drawable.pScreen);
#if X_BYTE_ORDER == X_BIG_ENDIAN
switch(bpp) {
case 15:
case 16:
swapper |= RADEON_NONSURF_AP0_SWP_16BPP
| RADEON_NONSURF_AP1_SWP_16BPP;
break;
case 24:
case 32:
swapper |= RADEON_NONSURF_AP0_SWP_32BPP
| RADEON_NONSURF_AP1_SWP_32BPP;
break;
}
OUTREG(RADEON_SURFACE_CNTL, swapper);
#endif
src += (x * bpp / 8) + (y * src_pitch);
w *= bpp / 8;
while (h--) {
memcpy(dst, src, w);
src += src_pitch;
dst += dst_pitch;
}
#if X_BYTE_ORDER == X_BIG_ENDIAN
/* restore byte swapping */
OUTREG(RADEON_SURFACE_CNTL, info->ModeReg.surface_cntl);
#endif
return TRUE;
}
Bool FUNC_NAME(RADEONDrawInit)(ScreenPtr pScreen)
{
RINFO_FROM_SCREEN(pScreen);
if (info->exa == NULL) {
xf86DrvMsg(pScreen->myNum, X_ERROR, "Memory map not set up\n");
return FALSE;
}
info->exa->exa_major = 2;
info->exa->exa_minor = 0;
info->exa->PrepareSolid = FUNC_NAME(RADEONPrepareSolid);
info->exa->Solid = FUNC_NAME(RADEONSolid);
info->exa->DoneSolid = FUNC_NAME(RADEONDoneSolid);
info->exa->PrepareCopy = FUNC_NAME(RADEONPrepareCopy);
info->exa->Copy = FUNC_NAME(RADEONCopy);
info->exa->DoneCopy = FUNC_NAME(RADEONDoneCopy);
info->exa->WaitMarker = FUNC_NAME(RADEONSync);
info->exa->UploadToScreen = FUNC_NAME(RADEONUploadToScreen);
info->exa->DownloadFromScreen = FUNC_NAME(RADEONDownloadFromScreen);
#if X_BYTE_ORDER == X_BIG_ENDIAN
info->exa->PrepareAccess = RADEONPrepareAccess;
info->exa->FinishAccess = RADEONFinishAccess;
#endif /* X_BYTE_ORDER == X_BIG_ENDIAN */
info->exa->flags = EXA_OFFSCREEN_PIXMAPS;
info->exa->pixmapOffsetAlign = RADEON_BUFFER_ALIGN + 1;
info->exa->pixmapPitchAlign = 64;
info->exa->maxX = 2047;
info->exa->maxY = 2047;
#ifdef RENDER
if (info->RenderAccel) {
if (info->ChipFamily >= CHIP_FAMILY_R300) {
xf86DrvMsg(pScrn->scrnIndex, X_INFO, "Render acceleration "
"unsupported on R300 type cards and newer.\n");
} else if ((info->ChipFamily == CHIP_FAMILY_RV250) ||
(info->ChipFamily == CHIP_FAMILY_RV280) ||
(info->ChipFamily == CHIP_FAMILY_RS300) ||
(info->ChipFamily == CHIP_FAMILY_R200)) {
xf86DrvMsg(pScrn->scrnIndex, X_INFO, "Render acceleration "
"enabled for R200 type cards.\n");
info->exa->CheckComposite = R200CheckComposite;
info->exa->PrepareComposite =
FUNC_NAME(R200PrepareComposite);
info->exa->Composite = FUNC_NAME(RadeonComposite);
info->exa->DoneComposite = RadeonDoneComposite;
} else {
xf86DrvMsg(pScrn->scrnIndex, X_INFO, "Render acceleration "
"enabled for R100 type cards.\n");
info->exa->CheckComposite = R100CheckComposite;
info->exa->PrepareComposite =
FUNC_NAME(R100PrepareComposite);
info->exa->Composite = FUNC_NAME(RadeonComposite);
info->exa->DoneComposite = RadeonDoneComposite;
}
}
#endif
RADEONEngineInit(pScrn);
if (!exaDriverInit(pScreen, info->exa)) {
xfree(info->exa);
return FALSE;
}
exaMarkSync(pScreen);
return TRUE;
}
#undef FUNC_NAME
|