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
|
/* COPYRIGHT AND PERMISSION NOTICE
Copyright (c) 2000, 2001 Nokia Home Communications
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, and/or sell copies of the Software, and to permit persons
to whom the Software is furnished to do so, provided that the above
copyright notice(s) and this permission notice appear in all copies of
the Software and that both the above copyright notice(s) and this
permission notice appear in supporting documentation.
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
OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
HOLDERS INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR 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.
Except as contained in this notice, the name of a copyright holder
shall not be used in advertising or otherwise to promote the sale, use
or other dealings in this Software without prior written authorization
of the copyright holder.
X Window System is a trademark of The Open Group */
/* Hardware accelerated drawing for KDrive i810 driver.
Author: Pontus Lidman <pontus.lidman@nokia.com>
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include "kdrive.h"
#ifdef XV
#include "kxv.h"
#endif
#include "i810.h"
#include "i810_reg.h"
#include "Xmd.h"
#include "gcstruct.h"
#include "scrnintstr.h"
#include "pixmapstr.h"
#include "regionstr.h"
#include "mistruct.h"
#include "fontstruct.h"
#include "dixfontstr.h"
#include "fb.h"
#include "migc.h"
#include "miline.h"
#include "picturestr.h"
#define NUM_STACK_RECTS 1024
void
i810Sync( KdScreenInfo *screen );
int
i810WaitLpRing( KdScreenInfo *screen, int n, int timeout_millis );
void
i810EmitInvarientState(KdScreenInfo *screen)
{
KdCardInfo *card = screen->card;
I810CardInfo *i810c = (I810CardInfo *) card->driver;
BEGIN_LP_RING( 10 );
OUT_RING( INST_PARSER_CLIENT | INST_OP_FLUSH | INST_FLUSH_MAP_CACHE );
OUT_RING( GFX_CMD_CONTEXT_SEL | CS_UPDATE_USE | CS_USE_CTX0 );
OUT_RING( INST_PARSER_CLIENT | INST_OP_FLUSH | INST_FLUSH_MAP_CACHE);
OUT_RING( 0 );
OUT_RING( GFX_OP_COLOR_CHROMA_KEY );
OUT_RING( CC1_UPDATE_KILL_WRITE |
CC1_DISABLE_KILL_WRITE |
CC1_UPDATE_COLOR_IDX |
CC1_UPDATE_CHROMA_LOW |
CC1_UPDATE_CHROMA_HI |
0);
OUT_RING( 0 );
OUT_RING( 0 );
/* No depth buffer in KDrive yet */
/* OUT_RING( CMD_OP_Z_BUFFER_INFO ); */
/* OUT_RING( pI810->DepthBuffer.Start | pI810->auxPitchBits); */
ADVANCE_LP_RING();
}
static unsigned int i810PatternRop[16] = {
0x00, /* GXclear */
0xA0, /* GXand */
0x50, /* GXandReverse */
0xF0, /* GXcopy */
0x0A, /* GXandInvert */
0xAA, /* GXnoop */
0x5A, /* GXxor */
0xFA, /* GXor */
0x05, /* GXnor */
0xA5, /* GXequiv */
0x55, /* GXinvert */
0xF5, /* GXorReverse */
0x0F, /* GXcopyInvert */
0xAF, /* GXorInverted */
0x5F, /* GXnand */
0xFF /* GXset */
};
void
i810SetupForSolidFill(KdScreenInfo *screen, int color, int rop,
unsigned int planemask)
{
KdCardInfo *card = screen->card;
I810CardInfo *i810c = (I810CardInfo *) card->driver;
if (I810_DEBUG & DEBUG_VERBOSE_ACCEL)
ErrorF( "i810SetupForFillRectSolid color: %x rop: %x mask: %x\n",
color, rop, planemask);
/* Color blit, p166 */
i810c->BR[13] = (BR13_SOLID_PATTERN |
(i810PatternRop[rop] << 16) |
(screen->width * i810c->cpp));
i810c->BR[16] = color;
}
void
i810SubsequentSolidFillRect(KdScreenInfo *screen, int x, int y, int w, int h)
{
KdCardInfo *card = screen->card;
I810CardInfo *i810c = (I810CardInfo *) card->driver;
if (I810_DEBUG & DEBUG_VERBOSE_ACCEL)
ErrorF( "i810SubsequentFillRectSolid %d,%d %dx%d\n",
x,y,w,h);
{
BEGIN_LP_RING(6);
OUT_RING( BR00_BITBLT_CLIENT | BR00_OP_COLOR_BLT | 0x3 );
OUT_RING( i810c->BR[13] );
OUT_RING( (h << 16) | (w * i810c->cpp));
OUT_RING( i810c->bufferOffset +
(y * screen->width + x) * i810c->cpp);
OUT_RING( i810c->BR[16]);
OUT_RING( 0 ); /* pad to quadword */
ADVANCE_LP_RING();
}
}
BOOL
i810FillOk (GCPtr pGC)
{
FbBits depthMask;
switch (pGC->fillStyle) {
case FillSolid:
return TRUE;
/* More cases later... */
}
return FALSE;
}
void
i810FillBoxSolid (KdScreenInfo *screen, int nBox, BoxPtr pBox,
unsigned long pixel, int alu, unsigned long planemask)
{
i810SetupForSolidFill(screen, pixel, alu, planemask);
while (nBox--)
{
i810SubsequentSolidFillRect(screen, pBox->x1, pBox->y1,
pBox->x2-pBox->x1, pBox->y2-pBox->y1);
pBox++;
}
KdMarkSync(screen->pScreen);
}
void
i810PolyFillRect (DrawablePtr pDrawable, GCPtr pGC,
int nrectFill, xRectangle *prectInit)
{
xRectangle *prect;
RegionPtr prgnClip;
register BoxPtr pbox;
register BoxPtr pboxClipped;
BoxPtr pboxClippedBase;
BoxPtr pextent;
BoxRec stackRects[NUM_STACK_RECTS];
FbGCPrivPtr fbPriv = fbGetGCPrivate (pGC);
int numRects;
int n;
int xorg, yorg;
int x, y;
KdScreenPriv(pDrawable->pScreen);
KdScreenInfo *screen = pScreenPriv->screen;
if (!i810FillOk (pGC))
{
KdCheckPolyFillRect (pDrawable, pGC, nrectFill, prectInit);
return;
}
prgnClip = fbGetCompositeClip(pGC);
xorg = pDrawable->x;
yorg = pDrawable->y;
if (xorg || yorg)
{
prect = prectInit;
n = nrectFill;
while(n--)
{
prect->x += xorg;
prect->y += yorg;
prect++;
}
}
prect = prectInit;
numRects = REGION_NUM_RECTS(prgnClip) * nrectFill;
if (numRects > NUM_STACK_RECTS)
{
pboxClippedBase = (BoxPtr)xalloc(numRects * sizeof(BoxRec));
if (!pboxClippedBase)
return;
}
else
pboxClippedBase = stackRects;
pboxClipped = pboxClippedBase;
if (REGION_NUM_RECTS(prgnClip) == 1)
{
int x1, y1, x2, y2, bx2, by2;
pextent = REGION_RECTS(prgnClip);
x1 = pextent->x1;
y1 = pextent->y1;
x2 = pextent->x2;
y2 = pextent->y2;
while (nrectFill--)
{
if ((pboxClipped->x1 = prect->x) < x1)
pboxClipped->x1 = x1;
if ((pboxClipped->y1 = prect->y) < y1)
pboxClipped->y1 = y1;
bx2 = (int) prect->x + (int) prect->width;
if (bx2 > x2)
bx2 = x2;
pboxClipped->x2 = bx2;
by2 = (int) prect->y + (int) prect->height;
if (by2 > y2)
by2 = y2;
pboxClipped->y2 = by2;
prect++;
if ((pboxClipped->x1 < pboxClipped->x2) &&
(pboxClipped->y1 < pboxClipped->y2))
{
pboxClipped++;
}
}
}
else
{
int x1, y1, x2, y2, bx2, by2;
pextent = REGION_EXTENTS(pGC->pScreen, prgnClip);
x1 = pextent->x1;
y1 = pextent->y1;
x2 = pextent->x2;
y2 = pextent->y2;
while (nrectFill--)
{
BoxRec box;
if ((box.x1 = prect->x) < x1)
box.x1 = x1;
if ((box.y1 = prect->y) < y1)
box.y1 = y1;
bx2 = (int) prect->x + (int) prect->width;
if (bx2 > x2)
bx2 = x2;
box.x2 = bx2;
by2 = (int) prect->y + (int) prect->height;
if (by2 > y2)
by2 = y2;
box.y2 = by2;
prect++;
if ((box.x1 >= box.x2) || (box.y1 >= box.y2))
continue;
n = REGION_NUM_RECTS (prgnClip);
pbox = REGION_RECTS(prgnClip);
/* clip the rectangle to each box in the clip region
this is logically equivalent to calling Intersect()
*/
while(n--)
{
pboxClipped->x1 = max(box.x1, pbox->x1);
pboxClipped->y1 = max(box.y1, pbox->y1);
pboxClipped->x2 = min(box.x2, pbox->x2);
pboxClipped->y2 = min(box.y2, pbox->y2);
pbox++;
/* see if clipping left anything */
if(pboxClipped->x1 < pboxClipped->x2 &&
pboxClipped->y1 < pboxClipped->y2)
{
pboxClipped++;
}
}
}
}
if (pboxClipped != pboxClippedBase)
{
switch (pGC->fillStyle) {
case FillSolid:
i810FillBoxSolid(screen,
pboxClipped-pboxClippedBase, pboxClippedBase,
pGC->fgPixel, pGC->alu, pGC->planemask);
break;
/* More cases later... */
}
}
if (pboxClippedBase != stackRects)
xfree(pboxClippedBase);
}
void
i810RefreshRing(KdScreenInfo *screen)
{
KdCardInfo *card = screen->card;
I810CardInfo *i810c = (I810CardInfo *) card->driver;
i810c->LpRing.head = INREG(LP_RING + RING_HEAD) & HEAD_ADDR;
i810c->LpRing.tail = INREG(LP_RING + RING_TAIL);
i810c->LpRing.space = i810c->LpRing.head - (i810c->LpRing.tail+8);
if (i810c->LpRing.space < 0)
i810c->LpRing.space += i810c->LpRing.mem.Size;
i810c->NeedToSync = TRUE;
}
int
i810WaitLpRing( KdScreenInfo *screen, int n, int timeout_millis )
{
KdCardInfo *card = screen->card;
I810CardInfo *i810c = (I810CardInfo *) card->driver;
I810RingBuffer *ring = &(i810c->LpRing);
int iters = 0;
int start = 0;
int now = 0;
int last_head = 0;
int first = 0;
/* If your system hasn't moved the head pointer in 2 seconds, I'm going to
* call it crashed.
*/
if (timeout_millis == 0)
timeout_millis = 2000;
if (I810_DEBUG) {
fprintf(stderr, "i810WaitLpRing %d\n", n);
first = GetTimeInMillis();
}
while (ring->space < n)
{
int i;
ring->head = INREG(LP_RING + RING_HEAD) & HEAD_ADDR;
ring->space = ring->head - (ring->tail+8);
if (ring->space < 0)
ring->space += ring->mem.Size;
iters++;
now = GetTimeInMillis();
if ( start == 0 || now < start || ring->head != last_head) {
if (I810_DEBUG)
if (now > start)
fprintf(stderr, "space: %d wanted %d\n", ring->space, n );
start = now;
last_head = ring->head;
} else if ( now - start > timeout_millis ) {
i810PrintErrorState( screen->card );
fprintf(stderr, "space: %d wanted %d\n", ring->space, n );
FatalError("lockup\n");
}
for (i = 0 ; i < 2000 ; i++)
;
}
if (I810_DEBUG)
{
now = GetTimeInMillis();
if (now - first) {
fprintf(stderr,"Elapsed %d ms\n", now - first);
fprintf(stderr, "space: %d wanted %d\n", ring->space, n );
}
}
return iters;
}
void
i810Sync( KdScreenInfo *screen )
{
KdCardInfo *card = screen->card;
I810CardInfo *i810c = card->driver;
if (I810_DEBUG)
fprintf(stderr, "i810Sync\n");
/* Send a flush instruction and then wait till the ring is empty.
* This is stronger than waiting for the blitter to finish as it also
* flushes the internal graphics caches.
*/
{
BEGIN_LP_RING(2);
OUT_RING( INST_PARSER_CLIENT | INST_OP_FLUSH | INST_FLUSH_MAP_CACHE );
OUT_RING( 0 ); /* pad to quadword */
ADVANCE_LP_RING();
}
i810WaitLpRing(screen, i810c->LpRing.mem.Size - 8, 0 );
i810c->LpRing.space = i810c->LpRing.mem.Size - 8;
i810c->nextColorExpandBuf = 0;
}
static const GCOps i810Ops = {
KdCheckFillSpans,
KdCheckSetSpans,
KdCheckPutImage,
KdCheckCopyArea,
KdCheckCopyPlane,
KdCheckPolyPoint,
KdCheckPolylines,
KdCheckPolySegment,
miPolyRectangle,
KdCheckPolyArc,
miFillPolygon,
i810PolyFillRect,
miPolyFillArc,
miPolyText8,
miPolyText16,
miImageText8,
miImageText16,
KdCheckImageGlyphBlt,
KdCheckPolyGlyphBlt,
KdCheckPushPixels,
#ifdef NEED_LINEHELPER
,NULL
#endif
};
void
i810ValidateGC (GCPtr pGC, Mask changes, DrawablePtr pDrawable)
{
FbGCPrivPtr fbPriv = fbGetGCPrivate(pGC);
fbValidateGC (pGC, changes, pDrawable);
if (pDrawable->type == DRAWABLE_WINDOW)
pGC->ops = (GCOps *) &i810Ops;
else
pGC->ops = (GCOps *) &kdAsyncPixmapGCOps;
}
GCFuncs i810GCFuncs = {
i810ValidateGC,
miChangeGC,
miCopyGC,
miDestroyGC,
miChangeClip,
miDestroyClip,
miCopyClip
};
int
i810CreateGC (GCPtr pGC)
{
if (!fbCreateGC (pGC))
return FALSE;
if (pGC->depth != 1)
pGC->funcs = &i810GCFuncs;
return TRUE;
}
static void
i810SetRingRegs( KdScreenInfo *screen ) {
unsigned int itemp;
KdCardInfo *card = screen->card;
I810CardInfo *i810c = (I810CardInfo *) card->driver;
OUTREG(LP_RING + RING_TAIL, 0 );
OUTREG(LP_RING + RING_HEAD, 0 );
itemp = INREG(LP_RING + RING_START);
itemp &= ~(START_ADDR);
itemp |= i810c->LpRing.mem.Start;
OUTREG(LP_RING + RING_START, itemp );
itemp = INREG(LP_RING + RING_LEN);
itemp &= ~(RING_NR_PAGES | RING_REPORT_MASK | RING_VALID_MASK);
itemp |= ((i810c->LpRing.mem.Size-4096) | RING_NO_REPORT | RING_VALID);
OUTREG(LP_RING + RING_LEN, itemp );
}
Bool
i810InitAccel(ScreenPtr pScreen)
{
/* fprintf(stderr,"i810InitAccel\n"); */
/*
* Hook up asynchronous drawing
*/
KdScreenInitAsync (pScreen);
/*
* Replace various fb screen functions
*/
pScreen->CreateGC = i810CreateGC;
return TRUE;
}
void
i810EnableAccel(ScreenPtr pScreen)
{
KdScreenPriv(pScreen);
KdScreenInfo *screen = pScreenPriv->screen;
KdCardInfo *card = screen->card;
I810CardInfo *i810c = (I810CardInfo *) card->driver;
/* fprintf(stderr,"i810EnableAccel\n"); */
if (i810c->LpRing.mem.Size == 0) {
ErrorF("No memory for LpRing!! Acceleration not functional!!\n");
}
i810SetRingRegs( screen );
KdMarkSync (pScreen);
}
void
i810SyncAccel(ScreenPtr pScreen)
{
KdScreenPriv(pScreen);
KdScreenInfo *screen = pScreenPriv->screen;
i810Sync(screen);
}
void
i810DisableAccel(ScreenPtr pScreen)
{
KdScreenPriv(pScreen);
KdScreenInfo *screen = pScreenPriv->screen;
/* fprintf(stderr,"i810DisableAccel\n"); */
i810RefreshRing( screen );
i810Sync( screen );
}
void
i810FiniAccel(ScreenPtr pScreen)
{
/* fprintf(stderr,"i810FiniAccel\n"); */
}
|