summaryrefslogtreecommitdiff
path: root/xc/programs/Xserver/hw/xfree86/drivers/neomagic/neo_2070.c
blob: 47584537c93bd55992801849edc0919a20409458 (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
/**********************************************************************
Copyright 1998, 1999 by Precision Insight, Inc., Cedar Park, Texas.

                        All Rights Reserved

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 Precision Insight not be
used in advertising or publicity pertaining to distribution of the
software without specific, written prior permission.  Precision Insight
and its suppliers make no representations about the suitability of this
software for any purpose.  It is provided "as is" without express or 
implied warranty.

PRECISION INSIGHT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS 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.
**********************************************************************/
/* $XFree86: xc/programs/Xserver/hw/xfree86/drivers/neomagic/neo_2070.c,v 1.2 1999/06/27 14:08:08 dawes Exp $ */

/*
 * The original Precision Insight driver for
 * XFree86 v.3.3 has been sponsored by Red Hat.
 *
 * Authors:
 *   Jens Owen (jens@precisioninsight.com)
 *   Kevin E. Martin (kevin@precisioninsight.com)
 *
 * Port to Xfree86 v.4.0
 *   1998, 1999 by Egbert Eich (Egbert.Eich@Physik.TU-Darmstadt.DE)
 */

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

/* Drivers that use XAA need this */
#include "xf86fbman.h"

#include "miline.h"

#include "neo.h"
#include "neo_reg.h"
#include "neo_macros.h"

/* Memory Mapped I/O for BitBlt */
#define NEO2070_BLTSTAT		0x00
#define NEO2070_BLTCNTL		0x04
#define NEO2070_XPCOLOR		0x08
#define NEO2070_FGCOLOR		0x0c
#define NEO2070_BGCOLOR		0x10
#define NEO2070_PLANEMASK	0x14
#define NEO2070_XYEXT           0x18
#define NEO2070_SRCPITCH        0x1c
#define NEO2070_SRCBITOFF       0x20
#define NEO2070_SRCSTART        0x24
#define NEO2070_DSTPITCH        0x28
#define NEO2070_DSTBITOFF       0x2c
#define NEO2070_DSTSTART        0x30

static unsigned int neo2070Rop[16] = {
    0x000000,    /* 0x0000 - GXclear         */
    0x080000,    /* 0x1000 - GXand           */
    0x040000,    /* 0x0100 - GXandReverse    */
    0x0c0000,    /* 0x1100 - GXcopy          */
    0x020000,    /* 0x0010 - GXandInvert     */
    0x0a0000,    /* 0x1010 - GXnoop          */
    0x060000,    /* 0x0110 - GXxor           */
    0x0e0000,    /* 0x1110 - GXor            */
    0x010000,    /* 0x0001 - GXnor           */
    0x090000,    /* 0x1001 - GXequiv         */
    0x050000,    /* 0x0101 - GXinvert        */
    0x0d0000,    /* 0x1101 - GXorReverse     */
    0x030000,    /* 0x0011 - GXcopyInvert    */
    0x0b0000,    /* 0x1011 - GXorInverted    */
    0x070000,    /* 0x0111 - GXnand          */
    0x0f0000     /* 0x1111 - GXset           */
};

static void Neo2070Sync(ScrnInfoPtr pScrn);
static void Neo2070SetupForScreenToScreenCopy(ScrnInfoPtr pScrn, int xdir,
					      int ydir, int rop,
					      unsigned int planemask,
					      int trans_color);
static void Neo2070SubsequentScreenToScreenCopy(ScrnInfoPtr pScrn, int srcX,
						int srcY, int dstX, int dstY,
						int w, int h);
static void Neo2070SetupForSolidFillRect(ScrnInfoPtr pScrn, int color, int rop,
				  unsigned int planemask);
static void Neo2070SubsequentSolidFillRect(ScrnInfoPtr pScrn, int x, int y,
					   int w, int h);

Bool 
Neo2070AccelInit(ScreenPtr pScreen)
{
    XAAInfoRecPtr infoPtr;
    ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
    NEOPtr nPtr = NEOPTR(pScrn);
    NEOACLPtr nAcl = NEOACLPTR(pScrn);
    BoxRec AvailFBArea;

    nPtr->AccelInfoRec = infoPtr = XAACreateInfoRec();
    if(!infoPtr) return FALSE;

    /*
     * Set up the main acceleration flags.
     */
    infoPtr->Flags |= LINEAR_FRAMEBUFFER | OFFSCREEN_PIXMAPS;
    if(nAcl->cacheEnd > nAcl->cacheStart) infoPtr->Flags = PIXMAP_CACHE;
#if 0
    infoPtr->PixmapCacheFlags |= DO_NOT_BLIT_STIPPLES;
#endif
    /* sync */
    infoPtr->Sync = Neo2070Sync;

    /* screen to screen copy */
    infoPtr->ScreenToScreenCopyFlags = (NO_TRANSPARENCY | GXCOPY_ONLY);
    infoPtr->SetupForScreenToScreenCopy = 
	Neo2070SetupForScreenToScreenCopy;
    infoPtr->SubsequentScreenToScreenCopy = 
	Neo2070SubsequentScreenToScreenCopy;

    /* solid filled rectangles */
    infoPtr->SolidFillFlags = GXCOPY_ONLY;
    infoPtr->SetupForSolidFill = 
	Neo2070SetupForSolidFillRect;
    infoPtr->SubsequentSolidFillRect = 
	Neo2070SubsequentSolidFillRect;

    /*
     * Setup some global variables
     */
    
    /* Initialize for 8bpp or 15/16bpp support accellerated */
    switch (pScrn->bitsPerPixel) {
    case 8:
	nAcl->BltCntlFlags = NEO_BC1_DEPTH8;
	nAcl->ColorShiftAmt = 8;
	nAcl->PixelWidth = 1;
	nAcl->PlaneMask = 0xff;
	break;
    case 15:
    case 16:
	nAcl->BltCntlFlags = NEO_BC1_DEPTH16;
	nAcl->ColorShiftAmt = 0;
	nAcl->PixelWidth = 2;
	nAcl->PlaneMask = 0xffff;
	break;
    case 24: /* not supported, but check anyway */
    default:
	return FALSE;
    }

    /* Initialize for widths */
    nAcl->Pitch = pScrn->displayWidth * nAcl->PixelWidth;

    AvailFBArea.x1 = 0;
    AvailFBArea.y1 = 0;
    AvailFBArea.x2 = pScrn->displayWidth;
    AvailFBArea.y2 = nAcl->cacheEnd /
      (pScrn->displayWidth * (pScrn->bitsPerPixel >> 3));
    xf86InitFBManager(pScreen, &AvailFBArea); 

    return(XAAInit(pScreen, infoPtr));

}

static void
Neo2070Sync(ScrnInfoPtr pScrn)
{
    NEOPtr nPtr = NEOPTR(pScrn);
    WAIT_ENGINE_IDLE();
}

static void
Neo2070SetupForScreenToScreenCopy(ScrnInfoPtr pScrn, int xdir, int ydir,
				  int rop,
				  unsigned int planemask,
				  int trans_color)
{
    NEOPtr nPtr = NEOPTR(pScrn);
    NEOACLPtr nAcl = NEOACLPTR(pScrn);

    /* set blt control */
    WAIT_ENGINE_IDLE();
    OUTREG(NEO2070_BLTCNTL, nAcl->tmpBltCntlFlags);
    OUTREG(NEO2070_PLANEMASK, planemask |= (planemask << nAcl->ColorShiftAmt));
    OUTREG(NEO2070_SRCPITCH, nAcl->Pitch);
    OUTREG(NEO2070_DSTPITCH, nAcl->Pitch);
    OUTREG(NEO2070_SRCBITOFF, 0);
    OUTREG(NEO2070_DSTBITOFF, 0);
}

static void
Neo2070SubsequentScreenToScreenCopy(ScrnInfoPtr pScrn,
				    int srcX, int srcY,
				    int dstX, int dstY,
				    int w, int h)
{
    NEOPtr nPtr = NEOPTR(pScrn);
    NEOACLPtr nAcl = NEOACLPTR(pScrn);

    if ((dstY < srcY) || ((dstY == srcY) && (dstX < srcX))) {
	/* start with upper left corner */
	WAIT_ENGINE_IDLE();
	OUTREG(NEO2070_BLTCNTL, nAcl->tmpBltCntlFlags);
	OUTREG(NEO2070_XYEXT, ((h-1)<<16) | ((w-1) & 0xffff));
	OUTREG(NEO2070_SRCSTART, 
	    (srcY * nAcl->Pitch) + (srcX * nAcl->PixelWidth));
	OUTREG(NEO2070_DSTSTART, 
	    (dstY * nAcl->Pitch) + (dstX * nAcl->PixelWidth));
    }
    else {
	/* start with lower right corner */
	WAIT_ENGINE_IDLE();
	OUTREG(NEO2070_BLTCNTL, (nAcl->tmpBltCntlFlags | NEO_BC0_X_DEC
                                                        | NEO_BC0_DST_Y_DEC 
                                                        | NEO_BC0_SRC_Y_DEC));
	OUTREG(NEO2070_XYEXT, ((h-1)<<16) | ((w-1) & 0xffff));
	OUTREG(NEO2070_SRCSTART, 
	    ((srcY+h-1) * nAcl->Pitch) + ((srcX+w-1) * nAcl->PixelWidth));
	OUTREG(NEO2070_DSTSTART, 
	    ((dstY+h-1) * nAcl->Pitch) + ((dstX+w-1) * nAcl->PixelWidth));
    }
}


static void
Neo2070SetupForSolidFillRect(ScrnInfoPtr pScrn, int color, int rop,
			     unsigned int planemask)
{
    NEOPtr nPtr = NEOPTR(pScrn);
    NEOACLPtr nAcl = NEOACLPTR(pScrn);

    planemask &= nAcl->PlaneMask;
    if (!rop) color=0;

    WAIT_ENGINE_IDLE();

    OUTREG(NEO2070_BLTCNTL, nAcl->BltCntlFlags  |
                            NEO_BC0_SRC_IS_FG    | neo2070Rop[3]);
    OUTREG(NEO2070_PLANEMASK, planemask |= (planemask << nAcl->ColorShiftAmt));
    if (pScrn->bitsPerPixel == 8) 
	OUTREG(NEO2070_FGCOLOR, color |= (color << 8));
    else
	/* swap bytes in color */
	OUTREG(NEO2070_FGCOLOR, ((color&0xff00) >> 8) | (color << 8));
    OUTREG(NEO2070_SRCPITCH, nAcl->Pitch);
    OUTREG(NEO2070_DSTPITCH, nAcl->Pitch);
    OUTREG(NEO2070_SRCBITOFF, 0);
    OUTREG(NEO2070_DSTBITOFF, 0);
}


static void
Neo2070SubsequentSolidFillRect(ScrnInfoPtr pScrn, int x, int y, int w, int h)
{
    NEOPtr nPtr = NEOPTR(pScrn);
    NEOACLPtr nAcl = NEOACLPTR(pScrn);

    WAIT_ENGINE_IDLE();
    OUTREG(NEO2070_XYEXT, ((h-1)<<16) | ((w-1) & 0xffff));
    OUTREG(NEO2070_DSTSTART, (y * nAcl->Pitch) + (x * nAcl->PixelWidth));
}