1dbbd9e4bSmacallan/*
2dbbd9e4bSmacallan * Acceleration for the Creator and Creator3D framebuffer - defines.
3dbbd9e4bSmacallan *
4dbbd9e4bSmacallan * Copyright (C) 1998,1999,2000 Jakub Jelinek (jakub@redhat.com)
5dbbd9e4bSmacallan * Copyright (C) 1998 Michal Rehacek (majkl@iname.com)
6dbbd9e4bSmacallan * Copyright (C) 1999 David S. Miller (davem@redhat.com)
7dbbd9e4bSmacallan *
8dbbd9e4bSmacallan * Permission is hereby granted, free of charge, to any person obtaining a copy
9dbbd9e4bSmacallan * of this software and associated documentation files (the "Software"), to deal
10dbbd9e4bSmacallan * in the Software without restriction, including without limitation the rights
11dbbd9e4bSmacallan * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12dbbd9e4bSmacallan * copies of the Software, and to permit persons to whom the Software is
13dbbd9e4bSmacallan * furnished to do so, subject to the following conditions:
14dbbd9e4bSmacallan *
15dbbd9e4bSmacallan * The above copyright notice and this permission notice shall be included in
16dbbd9e4bSmacallan * all copies or substantial portions of the Software.
17dbbd9e4bSmacallan *
18dbbd9e4bSmacallan * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19dbbd9e4bSmacallan * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20dbbd9e4bSmacallan * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
21dbbd9e4bSmacallan * JAKUB JELINEK, MICHAL REHACEK, OR DAVID MILLER BE LIABLE FOR ANY CLAIM,
22dbbd9e4bSmacallan * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
23dbbd9e4bSmacallan * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
24dbbd9e4bSmacallan * USE OR OTHER DEALINGS IN THE SOFTWARE.
25dbbd9e4bSmacallan *
26dbbd9e4bSmacallan */
27dbbd9e4bSmacallan
28dbbd9e4bSmacallan#ifndef FFB_H
29dbbd9e4bSmacallan#define FFB_H
30dbbd9e4bSmacallan
31dbbd9e4bSmacallan#include "xf86.h"
32dbbd9e4bSmacallan#include "xf86_OSproc.h"
3325ad54caSmrg#include "xf86Cursor.h"
347a5333bcSmrg#ifdef HAVE_XAA_H
35dbbd9e4bSmacallan#include "xaa.h"
367a5333bcSmrg#endif
3789b0bd4cSmacallan#include "exa.h"
3889b0bd4cSmacallan
39dbbd9e4bSmacallan#include <X11/Xmd.h>
40dbbd9e4bSmacallan#include "gcstruct.h"
41dbbd9e4bSmacallan#include "windowstr.h"
42dbbd9e4bSmacallan#include "ffb_regs.h"
43dbbd9e4bSmacallan#include "xf86sbusBus.h"
44dbbd9e4bSmacallan#include "ffb_dac.h"
45e33a93fdSmrg#ifdef HAVE_XEXTPROTO_71
46e33a93fdSmrg#include <X11/extensions/dpmsconst.h>
47e33a93fdSmrg#else
48dbbd9e4bSmacallan#ifndef  DPMS_SERVER
49dbbd9e4bSmacallan#define  DPMS_SERVER
50dbbd9e4bSmacallan#endif   /* DPMS_SERVER */
51dbbd9e4bSmacallan#include <X11/extensions/dpms.h>
52e33a93fdSmrg#endif
53dbbd9e4bSmacallan
547a5333bcSmrg#include "compat-api.h"
55dbbd9e4bSmacallan/* Various offsets in virtual (ie. mmap()) spaces Linux and Solaris support. */
56dbbd9e4bSmacallan/* Note: do not mmap FFB_DFB8R_VOFF and following mappings using one mmap together
57dbbd9e4bSmacallan   with any previous SFB mapping, otherwise the OS won't be able to use 4M pages
58dbbd9e4bSmacallan   for the DFB mappings. -jj */
59dbbd9e4bSmacallan#define	FFB_SFB8R_VOFF		0x00000000
60dbbd9e4bSmacallan#define	FFB_SFB8G_VOFF		0x00400000
61dbbd9e4bSmacallan#define	FFB_SFB8B_VOFF		0x00800000
62dbbd9e4bSmacallan#define	FFB_SFB8X_VOFF		0x00c00000
63dbbd9e4bSmacallan#define	FFB_SFB32_VOFF		0x01000000
64dbbd9e4bSmacallan#define	FFB_SFB64_VOFF		0x02000000
65dbbd9e4bSmacallan#define	FFB_FBC_REGS_VOFF	0x04000000
66dbbd9e4bSmacallan#define	FFB_BM_FBC_REGS_VOFF	0x04002000
67dbbd9e4bSmacallan#define	FFB_DFB8R_VOFF		0x04004000
68dbbd9e4bSmacallan#define	FFB_DFB8G_VOFF		0x04404000
69dbbd9e4bSmacallan#define	FFB_DFB8B_VOFF		0x04804000
70dbbd9e4bSmacallan#define	FFB_DFB8X_VOFF		0x04c04000
71dbbd9e4bSmacallan#define	FFB_DFB24_VOFF		0x05004000
72dbbd9e4bSmacallan#define	FFB_DFB32_VOFF		0x06004000
73dbbd9e4bSmacallan#define	FFB_DFB422A_VOFF	0x07004000	/* DFB 422 mode write to A */
74dbbd9e4bSmacallan#define	FFB_DFB422AD_VOFF	0x07804000	/* DFB 422 mode with line doubling */
75dbbd9e4bSmacallan#define	FFB_DFB24B_VOFF		0x08004000	/* DFB 24bit mode write to B */
76dbbd9e4bSmacallan#define	FFB_DFB422B_VOFF	0x09004000	/* DFB 422 mode write to B */
77dbbd9e4bSmacallan#define	FFB_DFB422BD_VOFF	0x09804000	/* DFB 422 mode with line doubling */
78dbbd9e4bSmacallan#define	FFB_SFB16Z_VOFF		0x0a004000	/* 16bit mode Z planes */
79dbbd9e4bSmacallan#define	FFB_SFB8Z_VOFF		0x0a404000	/* 8bit mode Z planes */
80dbbd9e4bSmacallan#define	FFB_SFB422_VOFF		0x0ac04000	/* SFB 422 mode write to A/B */
81dbbd9e4bSmacallan#define	FFB_SFB422D_VOFF	0x0b404000	/* SFB 422 mode with line doubling */
82dbbd9e4bSmacallan#define	FFB_FBC_KREGS_VOFF	0x0bc04000
83dbbd9e4bSmacallan#define	FFB_DAC_VOFF		0x0bc06000
84dbbd9e4bSmacallan#define	FFB_PROM_VOFF		0x0bc08000
85dbbd9e4bSmacallan#define	FFB_EXP_VOFF		0x0bc18000
86dbbd9e4bSmacallan
87dbbd9e4bSmacallan#if defined(__GNUC__) && defined(USE_VIS)
88dbbd9e4bSmacallan#define FFB_ALIGN64	__attribute__((aligned(8)))
89dbbd9e4bSmacallan#else
90dbbd9e4bSmacallan#define FFB_ALIGN64
91dbbd9e4bSmacallan#endif
92dbbd9e4bSmacallan
93dbbd9e4bSmacallantypedef struct {
94dbbd9e4bSmacallan	unsigned int fg FFB_ALIGN64, bg;	/* FG/BG colors for stipple	*/
95dbbd9e4bSmacallan	unsigned int patalign;			/* X/Y alignment of bits	*/
96dbbd9e4bSmacallan	unsigned char alu;			/* ALU operation		*/
97dbbd9e4bSmacallan	unsigned char inhw;			/* Cached in FFB		*/
98dbbd9e4bSmacallan	unsigned char pagable;			/* Can be used in a pagefill	*/
99dbbd9e4bSmacallan	unsigned char ph;			/* Page buffer height		*/
100dbbd9e4bSmacallan	unsigned int bits[32];			/* The stipple bits themselves	*/
101dbbd9e4bSmacallan} CreatorStippleRec, *CreatorStipplePtr;
102dbbd9e4bSmacallan
103dbbd9e4bSmacallan/* WID and framebuffer controls are a property of the
104dbbd9e4bSmacallan * window.
105dbbd9e4bSmacallan */
106dbbd9e4bSmacallantypedef struct {
107dbbd9e4bSmacallan	CreatorStipplePtr	Stipple;
108dbbd9e4bSmacallan	unsigned int		fbc_base;
109dbbd9e4bSmacallan	unsigned int		wid;
110dbbd9e4bSmacallan} CreatorPrivWinRec, *CreatorPrivWinPtr;
111dbbd9e4bSmacallan
112dbbd9e4bSmacallanenum ffb_resolution {
113dbbd9e4bSmacallan	ffb_res_standard = 0,	/* 1280 x 1024 */
114dbbd9e4bSmacallan	ffb_res_high,		/* 1920 x 1360 */
115dbbd9e4bSmacallan	ffb_res_stereo,		/* 960  x 580 */
116dbbd9e4bSmacallan	ffb_res_portrait	/* 1280 x 2048 */
117dbbd9e4bSmacallan};
118dbbd9e4bSmacallan
119dbbd9e4bSmacallanenum ffb_chip_type {
120dbbd9e4bSmacallan	ffb1_prototype = 0,	/* Early pre-FCS FFB */
121dbbd9e4bSmacallan	ffb1_standard,		/* First FCS FFB, 100Mhz UPA, 66MHz gclk */
122dbbd9e4bSmacallan	ffb1_speedsort,		/* Second FCS FFB, 100Mhz UPA, 75MHz gclk */
123dbbd9e4bSmacallan	ffb2_prototype,		/* Early pre-FCS vertical FFB2 */
124dbbd9e4bSmacallan	ffb2_vertical,		/* First FCS FFB2/vertical, 100Mhz UPA, 100MHZ gclk,
125dbbd9e4bSmacallan				   75(SingleBuffer)/83(DoubleBuffer) MHz fclk */
126dbbd9e4bSmacallan	ffb2_vertical_plus,	/* Second FCS FFB2/vertical, same timings */
127dbbd9e4bSmacallan	ffb2_horizontal,	/* First FCS FFB2/horizontal, same timings as FFB2/vert */
128dbbd9e4bSmacallan	ffb2_horizontal_plus,	/* Second FCS FFB2/horizontal, same timings */
129dbbd9e4bSmacallan	afb_m3,			/* FCS Elite3D, 3 float chips */
130dbbd9e4bSmacallan	afb_m6			/* FCS Elite3D, 6 float chips */
131dbbd9e4bSmacallan};
132dbbd9e4bSmacallan
133dbbd9e4bSmacallantypedef struct {
134dbbd9e4bSmacallan	unsigned short fifo_cache;
135dbbd9e4bSmacallan	unsigned short rp_active;
136dbbd9e4bSmacallan	ffb_fbcPtr regs;
137dbbd9e4bSmacallan	unsigned int ppc_cache;
138dbbd9e4bSmacallan	unsigned int pmask_cache;
139dbbd9e4bSmacallan	unsigned int rop_cache;
140dbbd9e4bSmacallan	unsigned int drawop_cache;
141dbbd9e4bSmacallan	unsigned int fg_cache;
142dbbd9e4bSmacallan	unsigned int bg_cache;
143dbbd9e4bSmacallan	unsigned int fontw_cache;
144dbbd9e4bSmacallan	unsigned int fontinc_cache;
145dbbd9e4bSmacallan	unsigned int fbc_cache;
146dbbd9e4bSmacallan	unsigned int wid_cache;
147dbbd9e4bSmacallan	enum ffb_chip_type ffb_type;
148dbbd9e4bSmacallan	CreatorStipplePtr laststipple;
149dbbd9e4bSmacallan	unsigned *fb;
150dbbd9e4bSmacallan	unsigned *sfb32;
151dbbd9e4bSmacallan	unsigned *sfb8r;
152dbbd9e4bSmacallan	unsigned *sfb8x;
153dbbd9e4bSmacallan	unsigned *dfb24;
154dbbd9e4bSmacallan	unsigned *dfb8r;
155dbbd9e4bSmacallan	unsigned *dfb8x;
156dbbd9e4bSmacallan
157dbbd9e4bSmacallan	/* Slot offset 0x0200000, used to probe board type. */
158dbbd9e4bSmacallan	volatile unsigned int *strapping_bits;
159dbbd9e4bSmacallan
160dbbd9e4bSmacallan	/* Needed for some 3DRAM revisions and ffb1 in hires */
161dbbd9e4bSmacallan	unsigned char disable_pagefill;
162dbbd9e4bSmacallan
163dbbd9e4bSmacallan	/* Needed for FFB2/AFB when in stereo or hires */
164dbbd9e4bSmacallan	unsigned char disable_fastfill_ap;
165dbbd9e4bSmacallan
166dbbd9e4bSmacallan	/* Needed for FFB1 in highres mode */
167dbbd9e4bSmacallan	unsigned char disable_vscroll;
168dbbd9e4bSmacallan
169dbbd9e4bSmacallan	/* Needed on all FFB1 boards. */
170dbbd9e4bSmacallan	unsigned char has_brline_bug;
171dbbd9e4bSmacallan
172dbbd9e4bSmacallan	/* Available on FFB2 and AFB */
173dbbd9e4bSmacallan	unsigned char use_blkread_prefetch;
174dbbd9e4bSmacallan
175dbbd9e4bSmacallan	/* Framebuffer configuration */
176dbbd9e4bSmacallan	unsigned char has_double_res;
177dbbd9e4bSmacallan	unsigned char has_z_buffer;
178dbbd9e4bSmacallan	unsigned char has_double_buffer;
179dbbd9e4bSmacallan
180dbbd9e4bSmacallan	/* XAA related info */
1817a5333bcSmrg#ifdef HAVE_XAA_H
182dbbd9e4bSmacallan	XAAInfoRecPtr pXAAInfo;
1837a5333bcSmrg#endif
184dbbd9e4bSmacallan	unsigned int xaa_linepat;
185dbbd9e4bSmacallan	int xaa_xdir, xaa_ydir, xaa_rop;
186dbbd9e4bSmacallan	unsigned char *xaa_scanline_buffers[2];
187dbbd9e4bSmacallan	int xaa_scanline_x, xaa_scanline_y, xaa_scanline_w;
188dbbd9e4bSmacallan	unsigned char *xaa_tex;
189dbbd9e4bSmacallan	int xaa_tex_pitch, xaa_tex_width, xaa_tex_height;
190dbbd9e4bSmacallan	unsigned int xaa_tex_color;
191dbbd9e4bSmacallan
192dbbd9e4bSmacallan	enum ffb_resolution ffb_res;
193dbbd9e4bSmacallan	BoxRec ClippedBoxBuf[64];
194dbbd9e4bSmacallan	xRectangle Pf_Fixups[4];
195dbbd9e4bSmacallan	short Pf_AlignTab[0x800];
196dbbd9e4bSmacallan
197dbbd9e4bSmacallan	ffb_dacPtr dac;
198dbbd9e4bSmacallan	sbusDevicePtr psdp;
199dbbd9e4bSmacallan	Bool HWCursor;
200dbbd9e4bSmacallan	Bool NoAccel;
201dbbd9e4bSmacallan	Bool vtSema;
202dbbd9e4bSmacallan	CloseScreenProcPtr CloseScreen;
203dbbd9e4bSmacallan	xf86CursorInfoPtr CursorInfoRec;
204dbbd9e4bSmacallan	unsigned char CursorShiftX, CursorShiftY;
205dbbd9e4bSmacallan	unsigned char *CursorData;
206dbbd9e4bSmacallan
20789b0bd4cSmacallan	/* EXA stuff */
20889b0bd4cSmacallan	ExaDriverPtr 	pExa;
20989b0bd4cSmacallan	int xdir, ydir, rop;
210504f16bcSmacallan	CARD32 planemask, fbc, wid, fillcolour;
211504f16bcSmacallan	Bool no_source_pixmap, source_is_solid;
212504f16bcSmacallan	int srcoff, srcpitch, mskoff, mskpitch;
213504f16bcSmacallan	CARD32 srcformat, dstformat, mskformat;
214504f16bcSmacallan	int op;
215504f16bcSmacallan
21689b0bd4cSmacallan
217dbbd9e4bSmacallan	PixmapPtr pix32, pix8;
218dbbd9e4bSmacallan
219dbbd9e4bSmacallan	void *I2C;
220dbbd9e4bSmacallan	struct ffb_dac_info dac_info;
221dbbd9e4bSmacallan
222dbbd9e4bSmacallan	OptionInfoPtr Options;
223dbbd9e4bSmacallan} FFBRec, *FFBPtr;
224dbbd9e4bSmacallan
225dbbd9e4bSmacallan/* Acceleration */
226dbbd9e4bSmacallanextern Bool FFBAccelInit(ScreenPtr, FFBPtr);
22789b0bd4cSmacallanextern Bool FFBInitEXA(ScreenPtr);
228dbbd9e4bSmacallanextern void CreatorVtChange (ScreenPtr pScreen, int enter);
229dbbd9e4bSmacallan
230dbbd9e4bSmacallan/* HW cursor support */
231dbbd9e4bSmacallanextern Bool FFBHWCursorInit(ScreenPtr);
232dbbd9e4bSmacallan
233dbbd9e4bSmacallan/* Exported DAC layer routines. */
234dbbd9e4bSmacallanextern void FFBDacLoadCursorPos(FFBPtr, int, int);
235dbbd9e4bSmacallanextern void FFBDacLoadCursorColor(FFBPtr, int, int);
236dbbd9e4bSmacallanextern void FFBDacCursorEnableDisable(FFBPtr, int);
237dbbd9e4bSmacallanextern void FFBDacCursorLoadBitmap(FFBPtr, int, int, unsigned int *);
238dbbd9e4bSmacallanextern void FFBDacLoadPalette(ScrnInfoPtr, int, int *, LOCO *, VisualPtr);
239dbbd9e4bSmacallanextern Bool FFBDacInit(FFBPtr);
240dbbd9e4bSmacallanextern void FFBDacFini(FFBPtr);
241dbbd9e4bSmacallanextern void FFBDacEnterVT(FFBPtr);
242dbbd9e4bSmacallanextern void FFBDacLeaveVT(FFBPtr);
243ec319841Smacallanextern Bool FFBDacSaveScreen(ScreenPtr, int);
244dbbd9e4bSmacallanextern void FFBDacDPMSMode(FFBPtr, int, int);
245dbbd9e4bSmacallan
246dbbd9e4bSmacallan/* Exported WID layer routines. */
247dbbd9e4bSmacallanextern void FFBWidPoolInit(FFBPtr);
248dbbd9e4bSmacallanextern unsigned int FFBWidAlloc(FFBPtr, int, int, Bool);
249dbbd9e4bSmacallanextern void FFBWidFree(FFBPtr, unsigned int);
250dbbd9e4bSmacallanextern unsigned int FFBWidUnshare(FFBPtr, unsigned int);
251dbbd9e4bSmacallanextern unsigned int FFBWidReshare(FFBPtr, unsigned int);
252dbbd9e4bSmacallanextern void FFBWidChangeBuffer(FFBPtr, unsigned int, int);
253cd6fbc61Smacallanextern void VISmoveImageLR(unsigned char *, unsigned char *, long, long, long, long);
254cd6fbc61Smacallanextern void VISmoveImageRL(unsigned char *, unsigned char *, long, long, long, long);
255dbbd9e4bSmacallan
256dbbd9e4bSmacallan/* Accelerated double-buffering. */
257dbbd9e4bSmacallanextern Bool FFBDbePreInit(ScreenPtr);
258dbbd9e4bSmacallan
259dbbd9e4bSmacallan/* The fastfill and pagefill buffer sizes change based upon
260dbbd9e4bSmacallan * the resolution.
261dbbd9e4bSmacallan */
262dbbd9e4bSmacallanstruct fastfill_parms {
263dbbd9e4bSmacallan	int	fastfill_small_area;
264dbbd9e4bSmacallan	int	pagefill_small_area;
265dbbd9e4bSmacallan
266dbbd9e4bSmacallan	int	fastfill_height;
267dbbd9e4bSmacallan	int	fastfill_width;
268dbbd9e4bSmacallan	int	pagefill_height;
269dbbd9e4bSmacallan	int	pagefill_width;
270dbbd9e4bSmacallan};
271dbbd9e4bSmacallan
272dbbd9e4bSmacallanextern struct fastfill_parms ffb_fastfill_parms[];
273dbbd9e4bSmacallan
274dbbd9e4bSmacallan#define FFB_FFPARMS(__fpriv)	(ffb_fastfill_parms[(__fpriv)->ffb_res])
275dbbd9e4bSmacallan
276dbbd9e4bSmacallan#define GET_FFB_FROM_SCRN(p)	((FFBPtr)((p)->driverPrivate))
277dbbd9e4bSmacallan
278dbbd9e4bSmacallan#undef DEBUG_FFB
279dbbd9e4bSmacallan
280dbbd9e4bSmacallan#ifdef DEBUG_FFB
281dbbd9e4bSmacallan
282dbbd9e4bSmacallanextern FILE *FDEBUG_FD;
283dbbd9e4bSmacallan
284dbbd9e4bSmacallanstatic __inline__ void FFB_DEBUG_init(void)
285dbbd9e4bSmacallan{
286dbbd9e4bSmacallan	FDEBUG_FD = fopen("/tmp/FFB.DEBUG", "a");
287dbbd9e4bSmacallan}
288dbbd9e4bSmacallan#define FDEBUG(__x)				\
289dbbd9e4bSmacallando {	fprintf __x; 				\
290dbbd9e4bSmacallan	fflush(FDEBUG_FD); 			\
291dbbd9e4bSmacallan} while(0)
292dbbd9e4bSmacallan#else
293dbbd9e4bSmacallan#define FFB_DEBUG_init()	do { } while(0)
294dbbd9e4bSmacallan#define FDEBUG(__x)		do { } while(0)
295dbbd9e4bSmacallan#endif
296dbbd9e4bSmacallan
297dbbd9e4bSmacallan/* Enable this to get very verbose tracing of the driver onto stderr. */
298dbbd9e4bSmacallan#undef TRACE_FFB
299dbbd9e4bSmacallan#ifdef TRACE_FFB
300dbbd9e4bSmacallan#define FFBLOG(__x)		ErrorF __x
301dbbd9e4bSmacallan#else
302dbbd9e4bSmacallan#define FFBLOG(__x)		do { } while(0)
303dbbd9e4bSmacallan#endif
304dbbd9e4bSmacallan
305504f16bcSmacallan/* common acceleration routines */
306504f16bcSmacallanvoid FFB_SetupTextureAttrs(FFBPtr);
307504f16bcSmacallanvoid FFB_HardwareSetup(FFBPtr);
308504f16bcSmacallanvoid CreatorAlignTabInit(FFBPtr);
309504f16bcSmacallan
310dbbd9e4bSmacallan#endif /* FFB_H */
311