summaryrefslogtreecommitdiff
path: root/hw/kdrive/pm2/pm2_draw.c
blob: 0761232810c121d84011fa038175e34add9e1a27 (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
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include "kdrive.h"

#include "pm2.h"

static PM2CardInfo	*card;
static VOL8	*mmio;

static void Permedia2LoadCoord(int x, int y, int w, int h);

static Bool
pmPrepareSolid (PixmapPtr   	pPixmap,
		int		rop,
		Pixel		planemask,
		Pixel		color)
{
    ScreenPtr pScreen = pPixmap->drawable.pScreen;
    KdScreenPriv(pScreen);
    pmCardInfo(pScreenPriv);

    card = pm2c;
    mmio = pm2c->reg_base;

    if (~planemask & FbFullMask(pPixmap->drawable.depth))
	return FALSE;

    REPLICATE(color);

    GLINT_WAIT(6);
    DO_PLANEMASK(planemask);
    if (rop == GXcopy) {
	GLINT_WRITE_REG(UNIT_DISABLE, ColorDDAMode);
	GLINT_WRITE_REG(card->pprod, FBReadMode);
	GLINT_WRITE_REG(color, FBBlockColor);
    } else {
	GLINT_WRITE_REG(UNIT_ENABLE, ColorDDAMode);
      	GLINT_WRITE_REG(color, ConstantColor);
	/* We can use Packed mode for filling solid non-GXcopy rasters */
	GLINT_WRITE_REG(card->pprod|FBRM_DstEnable|FBRM_Packed, FBReadMode);
    }
    LOADROP(rop);

    return TRUE;
}

static void
pmSolid (int x1, int y1, int x2, int y2)
{
    int speed = 0;

    if (card->ROP == GXcopy) {
	GLINT_WAIT(3);
        Permedia2LoadCoord(x1, y1, x2-x1, y2-y1);
  	speed = FastFillEnable;
    } else {
	GLINT_WAIT(4);
        Permedia2LoadCoord(x1>>card->BppShift, y1, 
			    ((x2-x1)+7)>>card->BppShift, y2-y1);
  	GLINT_WRITE_REG(x1<<16|(x1+(x2-x1)), PackedDataLimits);
  	speed = 0;
    }
    GLINT_WRITE_REG(PrimitiveRectangle | XPositive | YPositive | speed, Render);
}

static void
pmDoneSolid (void)
{
}

static Bool
pmPrepareCopy (PixmapPtr	pSrcPixmap,
	       PixmapPtr	pDstPixmap,
	       int		dx,
	       int		dy,
	       int		rop,
	       Pixel		planemask)
{
    ScreenPtr pScreen = pDstPixmap->drawable.pScreen;
    KdScreenPriv(pScreen);
    pmCardInfo(pScreenPriv);

    card = pm2c;
    mmio = pm2c->reg_base;

    if (~planemask & FbFullMask(pDstPixmap->drawable.depth))
	return FALSE;

    card->BltScanDirection = ((dx >= 0 ? XPositive : 0) | (dy >= 0 ? YPositive : 0));

    GLINT_WAIT(4);
    DO_PLANEMASK(planemask);

    GLINT_WRITE_REG(UNIT_DISABLE, ColorDDAMode);
    if ((rop == GXset) || (rop == GXclear)) {
	card->FrameBufferReadMode = card->pprod;
    } else
    if ((rop == GXcopy) || (rop == GXcopyInverted)) {
	card->FrameBufferReadMode = card->pprod |FBRM_SrcEnable;
    } else {
	card->FrameBufferReadMode = card->pprod | FBRM_SrcEnable |
							FBRM_DstEnable;
    }
    LOADROP(rop);

    return TRUE;
}


static void
pmCopy (int x1,
        int y1,
        int x2,
        int y2,
        int w,
        int h)
{
    char align;

    /* We can only use GXcopy for Packed modes */
    if (card->ROP != GXcopy) {
	GLINT_WAIT(5);
	GLINT_WRITE_REG(card->FrameBufferReadMode, FBReadMode);
        Permedia2LoadCoord(x2, y2, w, h);
        GLINT_WRITE_REG(((y1-y2)&0x0FFF)<<16 | ((x1-x2)&0x0FFF), FBSourceDelta);
    } else {
  	align = (x2 & card->bppalign) - (x1 & card->bppalign);
	GLINT_WAIT(6);
	GLINT_WRITE_REG(card->FrameBufferReadMode|FBRM_Packed, FBReadMode);
        Permedia2LoadCoord(x2>>card->BppShift, y2, 
				(w+7)>>card->BppShift, h);
  	GLINT_WRITE_REG(align<<29|x2<<16|(x2+w), PackedDataLimits);
        GLINT_WRITE_REG(((y1-y2)&0x0FFF)<<16 | (((x1 & ~card->bppalign)-(x2 & ~card->bppalign))&0x0FFF), FBSourceDelta);
    }

    GLINT_WRITE_REG(PrimitiveRectangle | card->BltScanDirection, Render);
}


static void
pmDoneCopy (void)
{
}

static void
Permedia2LoadCoord(int x, int y,
		   int w, int h)
{
    if ((h != card->h) || (w != card->w)) {
	card->w = w;
	card->h = h;
	GLINT_WRITE_REG(((h&0x0FFF)<<16)|(w&0x0FFF), RectangleSize);
    }
    if ((y != card->y) || (x != card->x)) {
	card->x = x;
	card->y = y;
	GLINT_WRITE_REG(((y&0x0FFF)<<16)|(x&0x0FFF), RectangleOrigin);
    }
}

KaaScreenInfoRec    pmKaa = {
    pmPrepareSolid,
    pmSolid,
    pmDoneSolid,

    pmPrepareCopy,
    pmCopy,
    pmDoneCopy,
};

Bool
pmDrawInit (ScreenPtr pScreen)
{
    KdScreenPriv(pScreen);
    pmCardInfo(pScreenPriv);
    Bool    ret = TRUE;

    card = pm2c;
    mmio = pm2c->reg_base;

    if (ret && !kaaDrawInit (pScreen, &pmKaa))
    {
	ErrorF ("kaaDrawInit failed\n");
	ret = FALSE;
    }

    return ret;
}


void
pmDrawEnable (ScreenPtr pScreen)
{
    KdScreenPriv(pScreen);
    pmCardInfo(pScreenPriv);

    card = pm2c;
    mmio = pm2c->reg_base;

    GLINT_SLOW_WRITE_REG(UNIT_DISABLE,	ScissorMode);
    GLINT_SLOW_WRITE_REG(UNIT_ENABLE,	FBWriteMode);
    GLINT_SLOW_WRITE_REG(0, 		dXSub);
    GLINT_SLOW_WRITE_REG(GWIN_DisableLBUpdate,   GLINTWindow);
    GLINT_SLOW_WRITE_REG(UNIT_DISABLE,	DitherMode);
    GLINT_SLOW_WRITE_REG(UNIT_DISABLE,	AlphaBlendMode);
    GLINT_SLOW_WRITE_REG(UNIT_DISABLE,	ColorDDAMode);
    GLINT_SLOW_WRITE_REG(UNIT_DISABLE,	TextureColorMode);
    GLINT_SLOW_WRITE_REG(UNIT_DISABLE,	TextureAddressMode);
    GLINT_SLOW_WRITE_REG(UNIT_DISABLE,	PMTextureReadMode);
    GLINT_SLOW_WRITE_REG(card->pprod,	LBReadMode);
    GLINT_SLOW_WRITE_REG(UNIT_DISABLE,	AlphaBlendMode);
    GLINT_SLOW_WRITE_REG(UNIT_DISABLE,	TexelLUTMode);
    GLINT_SLOW_WRITE_REG(UNIT_DISABLE,	YUVMode);
    GLINT_SLOW_WRITE_REG(UNIT_DISABLE,	DepthMode);
    GLINT_SLOW_WRITE_REG(UNIT_DISABLE,	RouterMode);
    GLINT_SLOW_WRITE_REG(UNIT_DISABLE,	FogMode);
    GLINT_SLOW_WRITE_REG(UNIT_DISABLE,	AntialiasMode);
    GLINT_SLOW_WRITE_REG(UNIT_DISABLE,	AlphaTestMode);
    GLINT_SLOW_WRITE_REG(UNIT_DISABLE,	StencilMode);
    GLINT_SLOW_WRITE_REG(UNIT_DISABLE,	AreaStippleMode);
    GLINT_SLOW_WRITE_REG(UNIT_DISABLE,	LogicalOpMode);
    GLINT_SLOW_WRITE_REG(UNIT_DISABLE,	DepthMode);
    GLINT_SLOW_WRITE_REG(UNIT_DISABLE,	StatisticMode);
    GLINT_SLOW_WRITE_REG(0x400,		FilterMode);
    GLINT_SLOW_WRITE_REG(0xffffffff,	FBHardwareWriteMask);
    GLINT_SLOW_WRITE_REG(0xffffffff,	FBSoftwareWriteMask);
    GLINT_SLOW_WRITE_REG(UNIT_DISABLE,	RasterizerMode);
    GLINT_SLOW_WRITE_REG(UNIT_DISABLE,	GLINTDepth);
    GLINT_SLOW_WRITE_REG(UNIT_DISABLE,	FBSourceOffset);
    GLINT_SLOW_WRITE_REG(UNIT_DISABLE,	FBPixelOffset);
    GLINT_SLOW_WRITE_REG(UNIT_DISABLE,	LBSourceOffset);
    GLINT_SLOW_WRITE_REG(UNIT_DISABLE,	WindowOrigin);
    GLINT_SLOW_WRITE_REG(UNIT_DISABLE,	FBWindowBase);
    GLINT_SLOW_WRITE_REG(UNIT_DISABLE,	FBSourceBase);
    GLINT_SLOW_WRITE_REG(UNIT_DISABLE,	LBWindowBase);

#if X_BYTE_ORDER == X_BIG_ENDIAN
    card->RasterizerSwap = 1;
#else
    card->RasterizerSwap = 0;
#endif

    switch (pScreenPriv->screen->fb[0].bitsPerPixel) {
	case 8:
	    card->PixelWidth = 0x0; /* 8 Bits */
	    card->TexMapFormat = card->pprod;
#if X_BYTE_ORDER == X_BIG_ENDIAN
	    card->RasterizerSwap |= 3<<15;	/* Swap host data */
#endif
	    break;
	case 16:
	    card->PixelWidth = 0x1; /* 16 Bits */
	    card->TexMapFormat = card->pprod | 1<<19;
#if X_BYTE_ORDER == X_BIG_ENDIAN
	    card->RasterizerSwap |= 2<<15;	/* Swap host data */
#endif
	    break;
	case 24:
 	    card->PixelWidth = 0x4; /* 24 Bits */
	    card->TexMapFormat = card->pprod | 2<<19;
	    break;
	case 32:
	    card->PixelWidth = 0x2; /* 32 Bits */
	    card->TexMapFormat = card->pprod | 2<<19;
  	    break;
    }
    card->ClippingOn = FALSE;
    card->startxdom = 0;
    card->startxsub = 0;
    card->starty = 0;
    card->count = 0;
    card->dy = 1<<16;
    card->dxdom = 0;
    card->x = 0;
    card->y = 0;
    card->h = 0;
    card->w = 0;
    card->ROP = 0xFF;
    GLINT_SLOW_WRITE_REG(card->PixelWidth, FBReadPixel);
    GLINT_SLOW_WRITE_REG(card->TexMapFormat, PMTextureMapFormat);
    GLINT_SLOW_WRITE_REG(0, RectangleSize);
    GLINT_SLOW_WRITE_REG(0, RectangleOrigin);
    GLINT_SLOW_WRITE_REG(0, dXDom);
    GLINT_SLOW_WRITE_REG(1<<16, dY);
    GLINT_SLOW_WRITE_REG(0, StartXDom);
    GLINT_SLOW_WRITE_REG(0, StartXSub);
    GLINT_SLOW_WRITE_REG(0, StartY);
    GLINT_SLOW_WRITE_REG(0, GLINTCount);

    KdMarkSync (pScreen);
}

void
pmDrawDisable (ScreenPtr pScreen)
{
}

void
pmDrawFini (ScreenPtr pScreen)
{
}

void
pmDrawSync (ScreenPtr pScreen)
{
    CHECKCLIPPING;

    while (GLINT_READ_REG(DMACount) != 0);
    GLINT_WAIT(2);
    GLINT_WRITE_REG(0x400, FilterMode);
    GLINT_WRITE_REG(0, GlintSync);
    do {
   	while(GLINT_READ_REG(OutFIFOWords) == 0);
    } while (GLINT_READ_REG(OutputFIFO) != Sync_tag);
}