neo.h revision eaa3dbe0
1/**********************************************************************
2Copyright 1998, 1999 by Precision Insight, Inc., Cedar Park, Texas.
3
4                        All Rights Reserved
5
6Permission to use, copy, modify, distribute, and sell this software and
7its documentation for any purpose is hereby granted without fee,
8provided that the above copyright notice appear in all copies and that
9both that copyright notice and this permission notice appear in
10supporting documentation, and that the name of Precision Insight not be
11used in advertising or publicity pertaining to distribution of the
12software without specific, written prior permission.  Precision Insight
13and its suppliers make no representations about the suitability of this
14software for any purpose.  It is provided "as is" without express or
15implied warranty.
16
17PRECISION INSIGHT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
18INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
19EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR ANY
20SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
21RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
22CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
23CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
24**********************************************************************/
25
26/*
27 * The original Precision Insight driver for
28 * XFree86 v.3.3 has been sponsored by Red Hat.
29 *
30 * Authors:
31 *   Jens Owen (jens@tungstengraphics.com)
32 *   Kevin E. Martin (kevin@precisioninsight.com)
33 *
34 * Port to Xfree86 v.4.0
35 *   1998, 1999 by Egbert Eich (Egbert.Eich@Physik.TU-Darmstadt.DE)
36 */
37
38#include <string.h>
39
40#include "neo_pcirename.h"
41
42/* All drivers should typically include these */
43#include "xf86.h"
44#include "xf86_OSproc.h"
45
46/* Everything using inb/outb, etc needs "compiler.h" */
47#include "compiler.h"
48
49#ifdef HAVE_XAA_H
50#include "xaa.h"
51#include "xaalocal.h"		/* XAA internals as we replace some of XAA */
52#endif
53#include "xf86fbman.h"
54#include "xf86Cursor.h"
55
56#include "shadowfb.h"
57
58#include "vbe.h"
59
60/* Needed by the Shadow Framebuffer */
61#include "shadow.h"
62
63/* Drivers that need to access the PCI config space directly need this */
64#include "xf86Pci.h"
65
66#include "xf86i2c.h"
67
68#include "xf86xv.h"
69#include <X11/extensions/Xv.h>
70
71/*
72 * Driver data structures.
73 */
74#include "neo_reg.h"
75#include "neo_macros.h"
76
77#include "compat-api.h"
78/* Supported chipsets */
79typedef enum {
80    NM2070,
81    NM2090,
82    NM2093,
83    NM2097,
84    NM2160,
85    NM2200,
86    NM2230,
87    NM2360,
88    NM2380
89} NEOType;
90
91/* function prototypes */
92
93extern Bool NEOSwitchMode(SWITCH_MODE_ARGS_DECL);
94extern void NEOAdjustFrame(ADJUST_FRAME_ARGS_DECL);
95
96/* in neo_2070.c */
97extern Bool Neo2070AccelInit(ScreenPtr pScreen);
98
99/* in neo_2090.c */
100extern Bool Neo2090AccelInit(ScreenPtr pScreen);
101
102/* in neo_2097.c */
103extern Bool Neo2097AccelInit(ScreenPtr pScreen);
104
105/* in neo_2200.c */
106extern Bool Neo2200AccelInit(ScreenPtr pScreen);
107
108/* in neo_cursor.c */
109extern Bool NeoCursorInit(ScreenPtr pScrn);
110extern void NeoShowCursor(ScrnInfoPtr pScrn);
111extern void NeoHideCursor(ScrnInfoPtr pScrn);
112
113/* in neo_i2c.c */
114extern Bool neo_I2CInit(ScrnInfoPtr pScrn);
115
116/* in neo_shadow.c */
117void neoShadowUpdate (ScreenPtr pScreen, shadowBufPtr pBuf);
118void neoPointerMoved(SCRN_ARG_TYPE arg, int x, int y);
119void neoRefreshArea(ScrnInfoPtr pScrn, int num, BoxPtr pbox);
120void neoRefreshArea8(ScrnInfoPtr pScrn, int num, BoxPtr pbox);
121void neoRefreshArea16(ScrnInfoPtr pScrn, int num, BoxPtr pbox);
122void neoRefreshArea24(ScrnInfoPtr pScrn, int num, BoxPtr pbox);
123void neoRefreshArea32(ScrnInfoPtr pScrn, int num, BoxPtr pbox);
124
125/* in neo_dga.c */
126Bool NEODGAInit(ScreenPtr pScreen);
127
128/* in neo_video.c */
129extern void NEOInitVideo(ScreenPtr pScreen);
130extern void NEOResetVideo(ScrnInfoPtr pScrn);
131
132/* shadow regs */
133
134#define NEO_EXT_CR_MAX 0x85
135#define NEO_EXT_GR_MAX 0xC7
136typedef struct {
137    unsigned char CR[NEO_EXT_CR_MAX+1];
138    unsigned char GR[NEO_EXT_GR_MAX+1];
139} regSaveRec, *regSavePtr;
140
141/* registers */
142typedef struct {
143    unsigned char GeneralLockReg;
144    unsigned char ExtCRTDispAddr;
145    unsigned char ExtCRTOffset;
146    unsigned char SysIfaceCntl1;
147    unsigned char SysIfaceCntl2;
148    unsigned char ExtColorModeSelect;
149    unsigned char SingleAddrPage;
150    unsigned char DualAddrPage;
151    unsigned char biosMode;
152    unsigned char PanelDispCntlReg1;
153    unsigned char PanelDispCntlReg2;
154    unsigned char PanelDispCntlReg3;
155    unsigned char PanelVertCenterReg1;
156    unsigned char PanelVertCenterReg2;
157    unsigned char PanelVertCenterReg3;
158    unsigned char PanelVertCenterReg4;
159    unsigned char PanelVertCenterReg5;
160    unsigned char PanelHorizCenterReg1;
161    unsigned char PanelHorizCenterReg2;
162    unsigned char PanelHorizCenterReg3;
163    unsigned char PanelHorizCenterReg4;
164    unsigned char PanelHorizCenterReg5;
165    unsigned char Sequencer1;
166    Bool ProgramVCLK;
167    unsigned char VCLK3NumeratorLow;
168    unsigned char VCLK3NumeratorHigh;
169    unsigned char VCLK3Denominator;
170    unsigned char VerticalExt;
171    regSavePtr reg;
172} NeoRegRec, *NeoRegPtr;
173
174typedef struct {
175    /* Hardware cursor address */
176    unsigned int CursorAddress;
177    Bool UseHWCursor;
178    Bool NoCursorMode;
179    unsigned char CursTemp[1024];
180    /* Boundaries of the pixmap cache */
181    unsigned int cacheStart;
182    unsigned int cacheEnd;
183    /* Blitter */
184    unsigned int tmpBltCntlFlags;
185    unsigned int BltCntlFlags;
186    unsigned int BltModeFlags;
187    unsigned int ColorShiftAmt;
188    unsigned int Pitch;
189    unsigned int PixelWidth;
190    unsigned int PlaneMask;
191    int CPUToScreenColorExpandFill_x;
192    int CPUToScreenColorExpandFill_y;
193    int CPUToScreenColorExpandFill_w;
194    int CPUToScreenColorExpandFill_h;
195    int CPUToScreenColorExpandFill_skipleft;
196} NEOACLRec, *NEOACLPtr;
197#define NEOACLPTR(p)	&((NEOPtr)((p)->driverPrivate))->Accel
198
199/* globals */
200typedef struct neoRec
201{
202    int NeoChipset;
203    pciVideoPtr PciInfo;
204#ifndef XSERVER_LIBPCIACCESS
205    PCITAG      PciTag;
206#endif
207    EntityInfoPtr pEnt;
208#ifdef HAVE_XAA_H
209    XAAInfoRecPtr	AccelInfoRec;
210#endif
211    NEOACLRec Accel;
212    unsigned long NeoMMIOAddr;
213    unsigned long NeoLinearAddr;
214    unsigned char* NeoMMIOBase;
215    unsigned long NeoMMIOAddr2;
216    unsigned char* NeoMMIOBase2;
217    unsigned char* NeoFbBase;
218    long NeoFbMapSize;
219    unsigned long vgaIOBase;
220    DGAModePtr		DGAModes;
221    int			numDGAModes;
222    Bool		DGAactive;
223    int			DGAViewportStatus;
224    /* ??? */
225    int NeoFifoCount;
226    /* cursor */
227    int NeoCursorMem;
228    Bool NeoHWCursorShown;
229    Bool NeoHWCursorInitialized;
230    xf86CursorInfoPtr CursorInfo;
231    int NeoCursorOffset;
232    int NeoCursorPrevX;
233    int NeoCursorPrevY;
234    unsigned char *NeoCursorImage;
235    /* Panels size */
236    int NeoPanelWidth;
237    int NeoPanelHeight;
238    /* options */
239    OptionInfoPtr Options;
240    Bool noAccel;
241    Bool noAccelSet;
242    Bool swCursor;
243    Bool noMMIO;
244    Bool internDisp;
245    Bool externDisp;
246    Bool noLcdStretch;
247    Bool shadowFB;
248    Bool lcdCenter;
249    Bool onPciBurst;
250    Bool progLcdRegs;
251    Bool progLcdStretch;
252    Bool progLcdStretchOpt;
253    Bool overrideValidate;
254    Bool strangeLockups;
255    /* registers */
256    NeoRegRec NeoModeReg;
257    NeoRegRec NeoSavedReg;
258    /* proc pointer */
259    CloseScreenProcPtr CloseScreen;
260    I2CBusPtr I2C;
261    vbeInfoPtr          pVbe;
262    unsigned char * ShadowPtr;
263    int ShadowPitch;
264    CreateScreenResourcesProcPtr CreateScreenResources;
265    RefreshAreaFuncPtr refreshArea;
266    void	(*PointerMoved)(SCRN_ARG_TYPE arg, int x, int y);
267    int rotate;
268    Bool showcache;
269    Bool video;
270    double videoHZoom;
271    double videoVZoom;
272    XF86VideoAdaptorPtr overlayAdaptor;
273    int overlay;
274    int overlay_offset;
275    int videoKey;
276    int interlace;
277} NEORec, *NEOPtr;
278
279typedef struct {
280    int x_res;
281    int y_res;
282    int mode;
283} biosMode;
284
285/* The privates of the NEO driver */
286#define NEOPTR(p)	((NEOPtr)((p)->driverPrivate))
287
288/* I/O register offsets */
289#define GRAX	0x3CE
290
291/* vga IO functions */
292#define VGArCR(index)		(*hwp->readCrtc)(hwp, index)
293#define VGAwCR(index, val)	(*hwp->writeCrtc)(hwp, index, val)
294#define VGArGR(index)		(*hwp->readGr)(hwp, index)
295#define VGAwGR(index, val)	(*hwp->writeGr)(hwp, index, val)
296#define VGArSR(index)		(*hwp->readSeq)(hwp, index)
297#define VGAwSR(index, val)	(*hwp->writeSeq)(hwp, index, val)
298
299/* memory mapped register access macros */
300#define INREG8(addr)		MMIO_IN8(nPtr->NeoMMIOBase, addr)
301#define INREG16(addr)		MMIO_IN16(nPtr->NeoMMIOBase, addr)
302#define INREG(addr)		MMIO_IN32(nPtr->NeoMMIOBase, addr)
303#define OUTREG8(addr, val)	MMIO_OUT8(nPtr->NeoMMIOBase, addr, val)
304#define OUTREG16(addr, val)	MMIO_OUT16(nPtr->NeoMMIOBase, addr, val)
305#define OUTREG(addr, val)	MMIO_OUT32(nPtr->NeoMMIOBase, addr, val)
306
307/* This swizzle macro is to support the manipulation of cursor masks when
308 * the sprite moves off the left edge of the display.  This code is
309 * platform specific, and is known to work with 32bit little endian machines
310 */
311#define SWIZZLE32(__b) { \
312  ((unsigned char *)&__b)[0] = byte_reversed[((unsigned char *)&__b)[0]]; \
313  ((unsigned char *)&__b)[1] = byte_reversed[((unsigned char *)&__b)[1]]; \
314  ((unsigned char *)&__b)[2] = byte_reversed[((unsigned char *)&__b)[2]]; \
315  ((unsigned char *)&__b)[3] = byte_reversed[((unsigned char *)&__b)[3]]; \
316}
317
318#define PROBED_NM2070	0x01
319#define PROBED_NM2090	0x42
320#define PROBED_NM2093	0x43
321#define PROBED_NM2097	0x83
322#define PROBED_NM2160	0x44
323#define PROBED_NM2200	0x45
324
325#define PCI_VENDOR_NEOMAGIC		0x10C8
326#define PCI_CHIP_NM2070			0x0001
327#define PCI_CHIP_NM2090			0x0002
328#define PCI_CHIP_NM2093			0x0003
329#define PCI_CHIP_NM2097			0x0083
330#define PCI_CHIP_NM2160			0x0004
331#define PCI_CHIP_NM2200			0x0005
332#define PCI_CHIP_NM2230			0x0025
333#define PCI_CHIP_NM2360			0x0006
334#define PCI_CHIP_NM2380			0x0016
335