summaryrefslogtreecommitdiff
path: root/src/alp_xaam.c
blob: 8e9fd52704414cf9a90416b629f928cf1b338360 (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
/* (c) Itai Nahshon */
/* #define DEBUG */

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

#include "xf86.h"
#include "xf86_OSproc.h"
#include "compiler.h"

#include "xf86Pci.h"

#include "vgaHW.h"

#include "cir.h"
#define _ALP_PRIVATE_
#include "alp.h"

#ifdef HAVE_XAA_H
#ifdef DEBUG
#define minb(p) \
        (ErrorF("minb(%X)\n", p),\
        MMIO_IN8(pCir->chip.alp->BLTBase, (p)))
#define moutb(p,v) \
        (ErrorF("moutb(%X, %X)\n", p,v),\
	MMIO_OUT8(pCir->chip.alp->BLTBase, (p),(v)))
#define vga_minb(p) \
        (ErrorF("minb(%X)\n", p),\
        MMIO_IN8(hwp->MMIOBase, (hwp->MMIOOffset + (p))))
#define vga_moutb(p,v) \
        { ErrorF("moutb(%X, %X)\n", p,v);\
	MMIO_OUT8(hwp->MMIOBase, (hwp->MMIOOffset + (p)),(v));}
#define minl(p) \
        (ErrorF("minl(%X)\n", p),\
        MMIO_IN32(pCir->chip.alp->BLTBase, (p)))
#define moutl(p,v) \
        (ErrorF("moutl(%X, %X)\n", p,v),\
	MMIO_OUT32(pCir->chip.alp->BLTBase, (p),(v)))
#else
#define minb(p) MMIO_IN8(pCir->chip.alp->BLTBase, (p))
#define moutb(p,v) MMIO_OUT8(pCir->chip.alp->BLTBase, (p),(v))
#define vga_minb(p) MMIO_IN8(hwp->MMIIOBase, (hwp->MMIOOffset + (p)))
#define vga_moutb(p,v) MMIO_OUT8(hwp->MMIOBase, (hwp->MMIOOffset + (p)),(v))
#define minl(p) MMIO_IN32(pCir->chip.alp->BLTBase, (p))
#define moutl(p,v) MMIO_OUT32(pCir->chip.alp->BLTBase, (p),(v))
#endif

static const CARD8 translated_rop[] =
{
  /* GXclear */        0x00U,
  /* GXand   */        0x05U,
  /* GXandreverse */   0x09U,
  /* GXcopy */         0x0DU,
  /* GXandinversted */ 0x50U,
  /* GXnoop */         0x06U,
  /* GXxor */          0x59U,
  /* GXor */           0x6DU,
  /* GXnor */          0x90U,
  /* GXequiv */        0x95U,
  /* GXinvert */       0x0BU,
  /* GXorReverse */    0xADU,
  /* GXcopyInverted */ 0xD0U,
  /* GXorInverted */   0xD6U,
  /* GXnand */         0xDAU,
  /* GXset */          0x0EU
};

#define WAIT while(minl(0x40) & pCir->chip.alp->waitMsk){};
#define WAIT_1 while((minl(0x40)) & 0x1){};

static void AlpSync(ScrnInfoPtr pScrn)
{
    CirPtr pCir = CIRPTR(pScrn);
#ifdef ALP_DEBUG
	ErrorF("AlpSync mm\n");
#endif
	WAIT_1;
	return;
}

static void
AlpSetupForScreenToScreenCopy(ScrnInfoPtr pScrn, int xdir, int ydir, int rop,
								unsigned int planemask, int trans_color)
{
	CirPtr pCir = CIRPTR(pScrn);
	int pitch = pCir->pitch;

	WAIT;

	pCir->chip.alp->transRop = translated_rop[rop] << 16;
	
#ifdef ALP_DEBUG
	ErrorF("AlpSetupForScreenToScreenCopy xdir=%d ydir=%d rop=%x planemask=%x trans_color=%x\n",
			xdir, ydir, rop, planemask, trans_color);
#endif
	moutl(0x0C, (pitch << 16) | pitch); 

}

static void
AlpSubsequentScreenToScreenCopy(ScrnInfoPtr pScrn, int x1, int y1, int x2,
								int y2, int w, int h)
{
    CirPtr pCir = CIRPTR(pScrn);
    int source, dest;
    int  hh, ww;
    int decrement = 0;
    int pitch = pCir->pitch;
    
    ww = ((w * pScrn->bitsPerPixel / 8) - 1) & 0x1fff;
    hh = (h - 1) & 0x1fff;
    dest = y2 * pitch + x2 * pScrn->bitsPerPixel / 8;
    source = y1 * pitch + x1 * pScrn->bitsPerPixel / 8;
    if (dest > source) {
        decrement = 1;
	dest += hh * pitch + ww;
	source += hh * pitch + ww;
    }

    WAIT;

    /* Width / Height */
    moutl(0x08, (hh << 16) | ww);
    /* source */
    moutl(0x14, source & 0x3fffff);
    moutl(0x18, pCir->chip.alp->transRop | decrement);
    
    /* dest */
    write_mem_barrier();
    moutl(0x10, dest & 0x3fffff);
    
#ifdef ALP_DEBUG
    ErrorF("AlpSubsequentScreenToScreenCopy x1=%d y1=%d x2=%d y2=%d w=%d h=%d\n",
	   x1, y1, x2, y2, w, h);
    ErrorF("AlpSubsequentScreenToScreenCopy s=%d d=%d ww=%d hh=%d\n",
	   source, dest, ww, hh);
#endif
    if (!pCir->chip.alp->autoStart) {
        CARD32 val = minl(0x40);
	moutl(0x40,val | 0x02);
    }
    write_mem_barrier();
}


static void
AlpSetupForSolidFill(ScrnInfoPtr pScrn, int color, int rop,
						unsigned int planemask)
{
    CirPtr pCir = CIRPTR(pScrn);
    int pitch = pCir->pitch;

    WAIT;

#ifdef ALP_DEBUG
    ErrorF("AlpSetupForSolidFill color=%x rop=%x planemask=%x\n",
	   color, rop, planemask);
#endif

    moutl(0x04, color & 0xffffff);

    /* Set dest pitch */
    moutl(0x0C, pitch & 0x1fff);
    moutl(0x18, (((pScrn->bitsPerPixel - 8) << 1))
	  | translated_rop[rop] << 16
	  | 0x040000C0);
}

static void
AlpSubsequentSolidFillRect(ScrnInfoPtr pScrn, int x, int y, int w, int h)
{
    int dest;
    int hh, ww;
    CirPtr pCir = CIRPTR(pScrn);
    int pitch = pCir->pitch;

    ww = ((w * pScrn->bitsPerPixel / 8) - 1) & 0x1fff;
    hh = (h - 1) & 0x7ff;
    dest = y * pitch + x * pScrn->bitsPerPixel / 8;

    WAIT;
    
    /* Width / Height */
    write_mem_barrier();
    moutl(0x08, (hh << 16) | ww);

#ifdef ALP_DEBUG
    ErrorF("AlpSubsequentSolidFillRect x=%d y=%d w=%d h=%d\n",
	   x, y, w, h);
#endif
    /* dest */
    moutl(0x10, (dest & 0x3fffff));
    
    if (!pCir->chip.alp->autoStart) {
        CARD32 val = minl(0x40);
	moutl(0x40, val | 0x02);
    }
    write_mem_barrier();
}

static void
AlpAccelEngineInit(ScrnInfoPtr pScrn)
{
  vgaHWPtr hwp = VGAHWPTR(pScrn);
    CirPtr pCir = CIRPTR(pScrn);

    if (pCir->Chipset != PCI_CHIP_GD7548)  {
        vga_moutb(0x3CE, 0x0E); /* enable writes to gr33 */
        vga_moutb(0x3CF, 0x20); /* enable writes to gr33 */
    }
    if (pCir->properties & ACCEL_AUTOSTART) {
        moutl(0x40, 0x80); /* enable autostart */
	pCir->chip.alp->waitMsk = 0x10;
	pCir->chip.alp->autoStart = TRUE;
    } else {
        pCir->chip.alp->waitMsk = 0x1;
	pCir->chip.alp->autoStart = FALSE;
    }
}

Bool
AlpXAAInitMMIO(ScreenPtr pScreen)
{
	ScrnInfoPtr pScrn = xf86ScreenToScrn(pScreen);
	CirPtr pCir = CIRPTR(pScrn);
	XAAInfoRecPtr XAAPtr;
	
	pCir->InitAccel =  AlpAccelEngineInit;
#ifdef ALP_DEBUG
	ErrorF("AlpXAAInitMM\n");
#endif

	XAAPtr = XAACreateInfoRec();
	if (!XAAPtr) return FALSE;
	
	XAAPtr->Flags |= LINEAR_FRAMEBUFFER;
	XAAPtr->Sync = AlpSync;

	XAAPtr->SetupForScreenToScreenCopy = AlpSetupForScreenToScreenCopy;
	XAAPtr->SubsequentScreenToScreenCopy = AlpSubsequentScreenToScreenCopy;
	XAAPtr->ScreenToScreenCopyFlags = 
	  (NO_TRANSPARENCY | NO_PLANEMASK);

	XAAPtr->SetupForSolidFill = AlpSetupForSolidFill;
	XAAPtr->SubsequentSolidFillRect = AlpSubsequentSolidFillRect;
	XAAPtr->SubsequentSolidFillTrap = NULL;
	XAAPtr->SolidFillFlags =  NO_PLANEMASK;

	switch (pCir->Chipset) {
	  case PCI_CHIP_GD5480:
	  case PCI_CHIP_GD5446:
	      pCir->chip.alp->BLTBase = pCir->IOBase + 0x100;
	      break;
	  default:
	      pCir->chip.alp->BLTBase = pCir->IOBase;
	      break;
	}

	AlpAccelEngineInit(pScrn);
	
	pCir->AccelInfoRec = XAAPtr;

	if (!XAAInit(pScreen, XAAPtr))
	    return FALSE;

	return TRUE;
}

#endif