summaryrefslogtreecommitdiff
path: root/src/ffb_rcache.h
blob: a9bac9b31d49ea25d59abebf7f221cc21727cdc4 (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
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
/*
 * Acceleration for the Creator and Creator3D framebuffer - register caching.
 *
 * Copyright (C) 1999 David S. Miller (davem@redhat.com)
 * Copyright (C) 1999 Jakub Jelinek (jakub@redhat.com)
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
 * JAKUB JELINEK OR DAVID MILLER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
 * IN THE SOFTWARE.
 *
 */
/* $XFree86: xc/programs/Xserver/hw/xfree86/drivers/sunffb/ffb_rcache.h,v 1.1 2000/05/18 23:21:37 dawes Exp $ */

#ifndef FFBRCACHE_H
#define FFBRCACHE_H

/* We only need to write the bits which actually change,
 * writing unnessary bits causes the operation to go more
 * slowly. -DaveM
 *
 * We used to have some hairy code here which tried to
 * avoid writing attribute bits unnecessarily.  It has been
 * removed because various two bit fields have different
 * semantics.  For example, for some the higher bit is the
 * edit bit, for others there are three state patterns
 * and zero is a special "no edit" value.  Ho hum, it was
 * a nice idea...
 */
#define FFB_WRITE_PPC(__fpriv, __ffb, __val, __chg_mask) \
do {	unsigned int __oldval = (__fpriv)->ppc_cache; \
	unsigned int __t; \
	__t = (__oldval & (__chg_mask)) ^ (__val); \
	if (__t) { \
		unsigned int __newval = __oldval & ~(__chg_mask); \
		__newval |= (__val); \
		(__fpriv)->ppc_cache = __newval; \
		FFBFifo((__fpriv), 1); \
		(__ffb)->ppc = (__val); \
	} \
} while(0)

#define FFB_WRITE_PMASK(__fpriv, __ffb, __val) \
do {	if((__fpriv)->pmask_cache != (__val)) { \
		(__fpriv)->pmask_cache = (__val); \
		FFBFifo((__fpriv), 1); \
		(__ffb)->pmask = (__val); \
	} \
} while(0)

#define FFB_WRITE_ROP(__fpriv, __ffb, __val) \
do {	if((__fpriv)->rop_cache != (__val)) { \
		(__fpriv)->rop_cache = (__val); \
		FFBFifo((__fpriv), 1); \
		(__ffb)->rop = (__val); \
	} \
} while(0)

#define FFB_WRITE_DRAWOP(__fpriv, __ffb, __val) \
do {	if((__fpriv)->drawop_cache != (__val)) { \
		(__fpriv)->drawop_cache = (__val); \
		FFBFifo((__fpriv), 1); \
		(__ffb)->drawop = (__val); \
	} \
} while(0)

#define FFB_WRITE_FG(__fpriv, __ffb, __val) \
do {	if((__fpriv)->fg_cache != (__val)) { \
		(__fpriv)->fg_cache = (__val); \
		FFBFifo((__fpriv), 1); \
		(__ffb)->fg = (__val); \
	} \
} while(0)

#define FFB_WRITE_BG(__fpriv, __ffb, __val) \
do {	if((__fpriv)->bg_cache != (__val)) { \
		(__fpriv)->bg_cache = (__val); \
		FFBFifo((__fpriv), 1); \
		(__ffb)->bg = (__val); \
	} \
} while(0)

#define FFB_WRITE_FONTW(__fpriv, __ffb, __val) \
do {	if((__fpriv)->fontw_cache != (__val)) { \
		(__fpriv)->fontw_cache = (__val); \
		FFBFifo((__fpriv), 1); \
		(__ffb)->fontw = (__val); \
	} \
} while(0)

#define FFB_WRITE_FONTINC(__fpriv, __ffb, __val) \
do {	if((__fpriv)->fontinc_cache != (__val)) { \
		(__fpriv)->fontinc_cache = (__val); \
		FFBFifo((__fpriv), 1); \
		(__ffb)->fontinc = (__val); \
	} \
} while(0)

#define FFB_WRITE_FBC(__fpriv, __ffb, __val) \
do {	if((__fpriv)->fbc_cache != (__val)) { \
		(__fpriv)->fbc_cache = (__val); \
		FFBFifo((__fpriv), 1); \
		(__ffb)->fbc = (__val); \
	} \
} while(0)

#define FFB_WRITE_WID(__fpriv, __ffb, __val) \
do {	if((__fpriv)->wid_cache != (__val)) { \
		(__fpriv)->wid_cache = (__val); \
		FFBFifo((__fpriv), 1); \
		(__ffb)->wid = (__val); \
	} \
} while(0)

extern void __FFB_Attr_Raw(FFBPtr pFfb,
			   unsigned int ppc,
			   unsigned int ppc_mask,
			   unsigned int pmask,
			   unsigned int rop,
			   int drawop, int fg,
			   unsigned int fbc,
			   unsigned int wid);

#define FFB_ATTR_RAW(__fpriv, __ppc, __ppc_mask, __pmask, __rop, __drawop, __fg, __fbc, __wid) \
	if((((__fpriv)->ppc_cache & (__ppc_mask)) != (__ppc))			|| \
	   ((__fpriv)->pmask_cache != (__pmask))				|| \
	   ((__fpriv)->rop_cache != (__rop))					|| \
	   (((__drawop) != -1) && ((__fpriv)->drawop_cache != (__drawop)))	|| \
	   ((__fpriv)->fg_cache != (__fg))					|| \
	   ((__fpriv)->fbc_cache != (__fbc))					|| \
	   ((__fpriv)->wid_cache != (__wid))) \
		__FFB_Attr_Raw((__fpriv), (__ppc), (__ppc_mask), (__pmask), \
			       (__rop), (__drawop), (__fg), (__fbc), (__wid))

#define FFB_PPC_GCMASK	(FFB_PPC_APE_MASK | FFB_PPC_CS_MASK)

/* This is for loading the FFB attributes for the case where
 * where most of the values come directly from the graphics
 * context and only the PPC and DRAWOP are variable.
 */
extern void __FFB_Attr_GC(FFBPtr pFfb, GCPtr pGC, WindowPtr pWin,
			  unsigned int ppc, int drawop);

#define FFB_ATTR_GC(__fpriv, __pgc, __pwin, __ppc, __drawop)		\
do {	CreatorPrivWinPtr __winpriv = CreatorGetWindowPrivate(__pwin);	\
	unsigned int __rop = ((__pgc)->alu | FFB_ROP_EDIT_BIT);		\
	unsigned int __fbc = ((__winpriv)->fbc_base);			\
	__fbc &= ~FFB_FBC_XE_MASK;					\
	__fbc |= FFB_FBC_XE_OFF;					\
	__rop |= (FFB_ROP_NEW << 8);					\
	if ((((__fpriv)->ppc_cache & FFB_PPC_GCMASK) != (__ppc))||	\
	    ((__fpriv)->pmask_cache != ((__pgc)->planemask))	||	\
	    ((__fpriv)->rop_cache != (__rop))			||	\
	    ((__fpriv)->drawop_cache != (__drawop))		||	\
	    ((__fpriv)->fg_cache != ((__pgc)->fgPixel))		||	\
	    ((__fpriv)->fbc_cache != __fbc))				\
		__FFB_Attr_GC(__fpriv, __pgc, __pwin, __ppc, __drawop);	\
} while(0)

#define FFB_PPC_WINMASK	(FFB_PPC_APE_MASK | FFB_PPC_CS_MASK | FFB_PPC_XS_MASK)

extern void __FFB_Attr_FastfillWin(FFBPtr pFfb, WindowPtr pWin,
				   unsigned int ppc, unsigned int pixel);

#define FFB_ATTR_FFWIN(__fpriv, __pwin, __ppc, __pixel) \
do {	CreatorPrivWinPtr __winpriv = CreatorGetWindowPrivate(__pwin);	\
	unsigned int ___ppc = (__ppc) | FFB_PPC_XS_WID;			\
	unsigned int __fbc = (__winpriv)->fbc_base; \
	unsigned int __rop = (FFB_ROP_NEW|(FFB_ROP_NEW<<8)); \
	if((__fpriv)->has_double_buffer) { \
		__fbc &= ~FFB_FBC_WB_MASK; \
		__fbc |= FFB_FBC_WB_AB; \
	} \
	__fbc &= ~(FFB_FBC_XE_MASK | FFB_FBC_RGBE_MASK); \
	__fbc |= FFB_FBC_XE_ON | FFB_FBC_RGBE_ON; \
	if (pFfb->ffb_res == ffb_res_high) \
		__fbc |= FFB_FBC_WB_B; \
	if ((((__fpriv)->ppc_cache & FFB_PPC_WINMASK) != (___ppc))||	\
	    ((__fpriv)->pmask_cache != 0x00ffffff)		||	\
	    ((__fpriv)->rop_cache!= __rop)			||	\
	    ((__fpriv)->drawop_cache != FFB_DRAWOP_FASTFILL)	||	\
	    ((__fpriv)->fg_cache != (__pixel))			||	\
	    ((__fpriv)->fbc_cache != __fbc)			||	\
	    ((__fpriv)->wid_cache != ((__winpriv)->wid)))		\
		__FFB_Attr_FastfillWin(__fpriv, __pwin, ___ppc, __pixel);\
} while (0)

/* We have to be careful when copying windows around.  For that
 * case we will use either VIS copies or hw accelerated VSCROLL.
 * All of the planes needs to be copied in the framebuffer from
 * src to dst in order to handle child windows using different WIDs
 * than the parent window being copied.
 */

/* Setup to access the smart frame buffer (SFB) directly where the
 * pixel color comes from the cpu on writes.
 */
#define FFB_PPC_WINCOPY		(FFB_PPC_APE_DISABLE | FFB_PPC_XS_VAR | FFB_PPC_CS_VAR)
#define FFB_PPC_WINCOPY_MASK	(FFB_PPC_APE_MASK | FFB_PPC_XS_MASK | FFB_PPC_CS_MASK)
#define FFB_FBC_WINCOPY		(FFB_FBC_WB_A | FFB_FBC_WM_COMBINED | FFB_FBC_WE_FORCEON | \
				 FFB_FBC_RB_A | FFB_FBC_SB_BOTH | FFB_FBC_XE_ON | \
				 FFB_FBC_ZE_OFF | FFB_FBC_YE_OFF | FFB_FBC_RGBE_ON)

#define FFB_ATTR_SFB_VAR_WINCOPY(__fpriv) \
do {	unsigned int __ppc = FFB_PPC_WINCOPY; \
	unsigned int __ppc_mask = FFB_PPC_WINCOPY_MASK; \
	unsigned int __rop = FFB_ROP_NEW|(FFB_ROP_NEW<<8); \
	unsigned int __fbc = FFB_FBC_WINCOPY; \
	if((__fpriv)->has_double_buffer) { \
		__fbc &= ~FFB_FBC_WB_MASK; \
		__fbc |= FFB_FBC_WB_AB; \
	} \
	if (((__fpriv)->ppc_cache & __ppc_mask) != __ppc || \
	    (__fpriv)->fbc_cache != __fbc || \
	    (__fpriv)->rop_cache != __rop || \
	    (__fpriv)->pmask_cache != 0xffffffff) { \
		ffb_fbcPtr __ffb = (__fpriv)->regs; \
		(__fpriv)->ppc_cache &= ~__ppc_mask; \
		(__fpriv)->ppc_cache |= __ppc; \
		(__fpriv)->fbc_cache = __fbc; \
		(__fpriv)->rop_cache = __rop; \
		(__fpriv)->pmask_cache = 0xffffffff; \
		(__fpriv)->rp_active = 1; \
		FFBFifo(__fpriv, 4); \
		(__ffb)->ppc = __ppc; \
		(__ffb)->fbc = __fbc; \
		(__ffb)->rop = __rop; \
		(__ffb)->pmask = 0xffffffff; \
		(__fpriv)->rp_active = 1; \
	} \
} while(0)

extern void __FFB_Attr_SFB_VAR(FFBPtr pFfb, unsigned int ppc, unsigned int ppc_mask, unsigned int fbc,
			       unsigned int wid, unsigned int rop, unsigned int pmask);

#define FFB_ATTR_SFB_VAR_WIN(__fpriv, __pmask, __alu, __pwin) \
do {	unsigned int __ppc = FFB_PPC_APE_DISABLE | FFB_PPC_CS_VAR | FFB_PPC_XS_WID; \
	unsigned int __ppc_mask = FFB_PPC_APE_MASK | FFB_PPC_CS_MASK | FFB_PPC_XS_MASK; \
	unsigned int __rop = (FFB_ROP_EDIT_BIT | (__alu))|(FFB_ROP_NEW<<8); \
	unsigned int __fbc = FFB_FBC_WIN(__pwin); \
	if((__fpriv)->has_double_buffer) { \
		__fbc &= ~FFB_FBC_WB_MASK; \
		__fbc |= FFB_FBC_WB_AB; \
	} \
	if(((__fpriv)->ppc_cache & __ppc_mask) != __ppc || \
	   (__fpriv)->fbc_cache != __fbc || \
	   (__fpriv)->wid_cache != FFB_WID_WIN(__pwin) || \
	   (__fpriv)->rop_cache != __rop || \
	   (__fpriv)->pmask_cache != (__pmask)) \
		__FFB_Attr_SFB_VAR(__fpriv, __ppc, __ppc_mask, __fbc, \
				   FFB_WID_WIN(__pwin), __rop, (__pmask)); \
} while(0)

/* VSCROLL Attributes:
 *
 * PPC) VCE_DISABLE must be set, all other attributes are effectively
 *      ignored since this drawop just copies pixels within the ram
 *      chips and bypasses the pixel processor entirely.  So you
 *	end up with a PPC color source behavior of {ZS,YS,XS,CS}_VAR.
 * FBC) all options are allowed, but the SRC/DST buffers are determined
 *      solely by the WB_* setting, that is, the RB_* setting is effectively
 *      ignored since the pixels are copied directly through the write buffer
 * ROP) must be FFB_ROP_OLD (even for the X plane!)
 * PMASK) all options allowed
 */
#define FFB_ATTR_VSCROLL_WINCOPY(__fpriv) \
do {	unsigned int __rop = (FFB_ROP_OLD | (FFB_ROP_OLD << 8)); \
	unsigned int __fbc = FFB_FBC_WINCOPY; \
	if((__fpriv)->has_double_buffer) { \
		__fbc &= ~FFB_FBC_WB_MASK; \
		__fbc |= FFB_FBC_WB_AB; \
	} \
	if((__fpriv)->fbc_cache != __fbc || \
	   (__fpriv)->rop_cache != __rop || \
	   (__fpriv)->pmask_cache != 0xffffffff || \
	   (__fpriv)->drawop_cache != FFB_DRAWOP_VSCROLL) { \
		ffb_fbcPtr __ffb = (__fpriv)->regs; \
		(__fpriv)->fbc_cache = __fbc; \
		(__fpriv)->rop_cache = __rop; \
		(__fpriv)->pmask_cache = 0xffffffff; \
		(__fpriv)->drawop_cache = FFB_DRAWOP_VSCROLL; \
		(__fpriv)->rp_active = 1; \
		FFBFifo(__fpriv, 4); \
		(__ffb)->fbc = __fbc; \
		(__ffb)->rop = __rop; \
		(__ffb)->pmask = 0xffffffff; \
		(__ffb)->drawop = FFB_DRAWOP_VSCROLL; \
		(__fpriv)->rp_active = 1; \
	} \
} while(0)

#define FFB_ATTR_VSCROLL_WIN(__fpriv, __pmask, __pwin) \
do {	unsigned int __rop = (FFB_ROP_OLD | (FFB_ROP_OLD << 8)); \
	unsigned int __fbc = FFB_FBC_WIN(__pwin); \
	if((__fpriv)->has_double_buffer) { \
		__fbc &= ~FFB_FBC_WB_MASK; \
		__fbc |= FFB_FBC_WB_AB; \
	} \
	if((__fpriv)->fbc_cache != __fbc || \
	   (__fpriv)->rop_cache != __rop || \
	   (__fpriv)->pmask_cache != (__pmask) || \
	   (__fpriv)->drawop_cache != FFB_DRAWOP_VSCROLL) { \
		ffb_fbcPtr __ffb = (__fpriv)->regs; \
		(__fpriv)->fbc_cache = __fbc; \
		(__fpriv)->rop_cache = __rop; \
		(__fpriv)->pmask_cache = (__pmask); \
		(__fpriv)->drawop_cache = FFB_DRAWOP_VSCROLL; \
		(__fpriv)->rp_active = 1; \
		FFBFifo(__fpriv, 4); \
		(__ffb)->fbc = __fbc; \
		(__ffb)->rop = __rop; \
		(__ffb)->pmask = (__pmask); \
		(__ffb)->drawop = FFB_DRAWOP_VSCROLL; \
	} \
} while(0)

#define FFB_FBC_WIN(pWin)	CreatorGetWindowPrivate(pWin)->fbc_base
#define FFB_WID_WIN(pWin)	CreatorGetWindowPrivate(pWin)->wid

#endif /* FFBRCACHE_H */