xref: /OK3568_Linux_fs/kernel/drivers/video/fbdev/nvidia/nv_accel.c (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun  /***************************************************************************\
2*4882a593Smuzhiyun |*                                                                           *|
3*4882a593Smuzhiyun |*       Copyright 1993-2003 NVIDIA, Corporation.  All rights reserved.      *|
4*4882a593Smuzhiyun |*                                                                           *|
5*4882a593Smuzhiyun |*     NOTICE TO USER:   The source code  is copyrighted under  U.S. and     *|
6*4882a593Smuzhiyun |*     international laws.  Users and possessors of this source code are     *|
7*4882a593Smuzhiyun |*     hereby granted a nonexclusive,  royalty-free copyright license to     *|
8*4882a593Smuzhiyun |*     use this code in individual and commercial software.                  *|
9*4882a593Smuzhiyun |*                                                                           *|
10*4882a593Smuzhiyun |*     Any use of this source code must include,  in the user documenta-     *|
11*4882a593Smuzhiyun |*     tion and  internal comments to the code,  notices to the end user     *|
12*4882a593Smuzhiyun |*     as follows:                                                           *|
13*4882a593Smuzhiyun |*                                                                           *|
14*4882a593Smuzhiyun |*       Copyright 1993-2003 NVIDIA, Corporation.  All rights reserved.      *|
15*4882a593Smuzhiyun |*                                                                           *|
16*4882a593Smuzhiyun |*     NVIDIA, CORPORATION MAKES NO REPRESENTATION ABOUT THE SUITABILITY     *|
17*4882a593Smuzhiyun |*     OF  THIS SOURCE  CODE  FOR ANY PURPOSE.  IT IS  PROVIDED  "AS IS"     *|
18*4882a593Smuzhiyun |*     WITHOUT EXPRESS OR IMPLIED WARRANTY OF ANY KIND.  NVIDIA, CORPOR-     *|
19*4882a593Smuzhiyun |*     ATION DISCLAIMS ALL WARRANTIES  WITH REGARD  TO THIS SOURCE CODE,     *|
20*4882a593Smuzhiyun |*     INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGE-     *|
21*4882a593Smuzhiyun |*     MENT,  AND FITNESS  FOR A PARTICULAR PURPOSE.   IN NO EVENT SHALL     *|
22*4882a593Smuzhiyun |*     NVIDIA, CORPORATION  BE LIABLE FOR ANY SPECIAL,  INDIRECT,  INCI-     *|
23*4882a593Smuzhiyun |*     DENTAL, OR CONSEQUENTIAL DAMAGES,  OR ANY DAMAGES  WHATSOEVER RE-     *|
24*4882a593Smuzhiyun |*     SULTING FROM LOSS OF USE,  DATA OR PROFITS,  WHETHER IN AN ACTION     *|
25*4882a593Smuzhiyun |*     OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,  ARISING OUT OF     *|
26*4882a593Smuzhiyun |*     OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOURCE CODE.     *|
27*4882a593Smuzhiyun |*                                                                           *|
28*4882a593Smuzhiyun |*     U.S. Government  End  Users.   This source code  is a "commercial     *|
29*4882a593Smuzhiyun |*     item,"  as that  term is  defined at  48 C.F.R. 2.101 (OCT 1995),     *|
30*4882a593Smuzhiyun |*     consisting  of "commercial  computer  software"  and  "commercial     *|
31*4882a593Smuzhiyun |*     computer  software  documentation,"  as such  terms  are  used in     *|
32*4882a593Smuzhiyun |*     48 C.F.R. 12.212 (SEPT 1995)  and is provided to the U.S. Govern-     *|
33*4882a593Smuzhiyun |*     ment only as  a commercial end item.   Consistent with  48 C.F.R.     *|
34*4882a593Smuzhiyun |*     12.212 and  48 C.F.R. 227.7202-1 through  227.7202-4 (JUNE 1995),     *|
35*4882a593Smuzhiyun |*     all U.S. Government End Users  acquire the source code  with only     *|
36*4882a593Smuzhiyun |*     those rights set forth herein.                                        *|
37*4882a593Smuzhiyun |*                                                                           *|
38*4882a593Smuzhiyun  \***************************************************************************/
39*4882a593Smuzhiyun 
40*4882a593Smuzhiyun /*
41*4882a593Smuzhiyun  * GPL Licensing Note - According to Mark Vojkovich, author of the Xorg/
42*4882a593Smuzhiyun  * XFree86 'nv' driver, this source code is provided under MIT-style licensing
43*4882a593Smuzhiyun  * where the source code is provided "as is" without warranty of any kind.
44*4882a593Smuzhiyun  * The only usage restriction is for the copyright notices to be retained
45*4882a593Smuzhiyun  * whenever code is used.
46*4882a593Smuzhiyun  *
47*4882a593Smuzhiyun  * Antonino Daplas <adaplas@pol.net> 2005-03-11
48*4882a593Smuzhiyun  */
49*4882a593Smuzhiyun 
50*4882a593Smuzhiyun #include <linux/fb.h>
51*4882a593Smuzhiyun #include <linux/nmi.h>
52*4882a593Smuzhiyun 
53*4882a593Smuzhiyun #include "nv_type.h"
54*4882a593Smuzhiyun #include "nv_proto.h"
55*4882a593Smuzhiyun #include "nv_dma.h"
56*4882a593Smuzhiyun #include "nv_local.h"
57*4882a593Smuzhiyun 
58*4882a593Smuzhiyun /* There is a HW race condition with videoram command buffers.
59*4882a593Smuzhiyun    You can't jump to the location of your put offset.  We write put
60*4882a593Smuzhiyun    at the jump offset + SKIPS dwords with noop padding in between
61*4882a593Smuzhiyun    to solve this problem */
62*4882a593Smuzhiyun #define SKIPS  8
63*4882a593Smuzhiyun 
64*4882a593Smuzhiyun static const int NVCopyROP[16] = {
65*4882a593Smuzhiyun 	0xCC,			/* copy   */
66*4882a593Smuzhiyun 	0x55			/* invert */
67*4882a593Smuzhiyun };
68*4882a593Smuzhiyun 
69*4882a593Smuzhiyun static const int NVCopyROP_PM[16] = {
70*4882a593Smuzhiyun 	0xCA,			/* copy  */
71*4882a593Smuzhiyun 	0x5A,			/* invert */
72*4882a593Smuzhiyun };
73*4882a593Smuzhiyun 
nvidiafb_safe_mode(struct fb_info * info)74*4882a593Smuzhiyun static inline void nvidiafb_safe_mode(struct fb_info *info)
75*4882a593Smuzhiyun {
76*4882a593Smuzhiyun 	struct nvidia_par *par = info->par;
77*4882a593Smuzhiyun 
78*4882a593Smuzhiyun 	touch_softlockup_watchdog();
79*4882a593Smuzhiyun 	info->pixmap.scan_align = 1;
80*4882a593Smuzhiyun 	par->lockup = 1;
81*4882a593Smuzhiyun }
82*4882a593Smuzhiyun 
NVFlush(struct fb_info * info)83*4882a593Smuzhiyun static inline void NVFlush(struct fb_info *info)
84*4882a593Smuzhiyun {
85*4882a593Smuzhiyun 	struct nvidia_par *par = info->par;
86*4882a593Smuzhiyun 	int count = 1000000000;
87*4882a593Smuzhiyun 
88*4882a593Smuzhiyun 	while (--count && READ_GET(par) != par->dmaPut) ;
89*4882a593Smuzhiyun 
90*4882a593Smuzhiyun 	if (!count) {
91*4882a593Smuzhiyun 		printk("nvidiafb: DMA Flush lockup\n");
92*4882a593Smuzhiyun 		nvidiafb_safe_mode(info);
93*4882a593Smuzhiyun 	}
94*4882a593Smuzhiyun }
95*4882a593Smuzhiyun 
NVSync(struct fb_info * info)96*4882a593Smuzhiyun static inline void NVSync(struct fb_info *info)
97*4882a593Smuzhiyun {
98*4882a593Smuzhiyun 	struct nvidia_par *par = info->par;
99*4882a593Smuzhiyun 	int count = 1000000000;
100*4882a593Smuzhiyun 
101*4882a593Smuzhiyun 	while (--count && NV_RD32(par->PGRAPH, 0x0700)) ;
102*4882a593Smuzhiyun 
103*4882a593Smuzhiyun 	if (!count) {
104*4882a593Smuzhiyun 		printk("nvidiafb: DMA Sync lockup\n");
105*4882a593Smuzhiyun 		nvidiafb_safe_mode(info);
106*4882a593Smuzhiyun 	}
107*4882a593Smuzhiyun }
108*4882a593Smuzhiyun 
NVDmaKickoff(struct nvidia_par * par)109*4882a593Smuzhiyun static void NVDmaKickoff(struct nvidia_par *par)
110*4882a593Smuzhiyun {
111*4882a593Smuzhiyun 	if (par->dmaCurrent != par->dmaPut) {
112*4882a593Smuzhiyun 		par->dmaPut = par->dmaCurrent;
113*4882a593Smuzhiyun 		WRITE_PUT(par, par->dmaPut);
114*4882a593Smuzhiyun 	}
115*4882a593Smuzhiyun }
116*4882a593Smuzhiyun 
NVDmaWait(struct fb_info * info,int size)117*4882a593Smuzhiyun static void NVDmaWait(struct fb_info *info, int size)
118*4882a593Smuzhiyun {
119*4882a593Smuzhiyun 	struct nvidia_par *par = info->par;
120*4882a593Smuzhiyun 	int dmaGet;
121*4882a593Smuzhiyun 	int count = 1000000000, cnt;
122*4882a593Smuzhiyun 	size++;
123*4882a593Smuzhiyun 
124*4882a593Smuzhiyun 	while (par->dmaFree < size && --count && !par->lockup) {
125*4882a593Smuzhiyun 		dmaGet = READ_GET(par);
126*4882a593Smuzhiyun 
127*4882a593Smuzhiyun 		if (par->dmaPut >= dmaGet) {
128*4882a593Smuzhiyun 			par->dmaFree = par->dmaMax - par->dmaCurrent;
129*4882a593Smuzhiyun 			if (par->dmaFree < size) {
130*4882a593Smuzhiyun 				NVDmaNext(par, 0x20000000);
131*4882a593Smuzhiyun 				if (dmaGet <= SKIPS) {
132*4882a593Smuzhiyun 					if (par->dmaPut <= SKIPS)
133*4882a593Smuzhiyun 						WRITE_PUT(par, SKIPS + 1);
134*4882a593Smuzhiyun 					cnt = 1000000000;
135*4882a593Smuzhiyun 					do {
136*4882a593Smuzhiyun 						dmaGet = READ_GET(par);
137*4882a593Smuzhiyun 					} while (--cnt && dmaGet <= SKIPS);
138*4882a593Smuzhiyun 					if (!cnt) {
139*4882a593Smuzhiyun 						printk("DMA Get lockup\n");
140*4882a593Smuzhiyun 						par->lockup = 1;
141*4882a593Smuzhiyun 					}
142*4882a593Smuzhiyun 				}
143*4882a593Smuzhiyun 				WRITE_PUT(par, SKIPS);
144*4882a593Smuzhiyun 				par->dmaCurrent = par->dmaPut = SKIPS;
145*4882a593Smuzhiyun 				par->dmaFree = dmaGet - (SKIPS + 1);
146*4882a593Smuzhiyun 			}
147*4882a593Smuzhiyun 		} else
148*4882a593Smuzhiyun 			par->dmaFree = dmaGet - par->dmaCurrent - 1;
149*4882a593Smuzhiyun 	}
150*4882a593Smuzhiyun 
151*4882a593Smuzhiyun 	if (!count) {
152*4882a593Smuzhiyun 		printk("nvidiafb: DMA Wait Lockup\n");
153*4882a593Smuzhiyun 		nvidiafb_safe_mode(info);
154*4882a593Smuzhiyun 	}
155*4882a593Smuzhiyun }
156*4882a593Smuzhiyun 
NVSetPattern(struct fb_info * info,u32 clr0,u32 clr1,u32 pat0,u32 pat1)157*4882a593Smuzhiyun static void NVSetPattern(struct fb_info *info, u32 clr0, u32 clr1,
158*4882a593Smuzhiyun 			 u32 pat0, u32 pat1)
159*4882a593Smuzhiyun {
160*4882a593Smuzhiyun 	struct nvidia_par *par = info->par;
161*4882a593Smuzhiyun 
162*4882a593Smuzhiyun 	NVDmaStart(info, par, PATTERN_COLOR_0, 4);
163*4882a593Smuzhiyun 	NVDmaNext(par, clr0);
164*4882a593Smuzhiyun 	NVDmaNext(par, clr1);
165*4882a593Smuzhiyun 	NVDmaNext(par, pat0);
166*4882a593Smuzhiyun 	NVDmaNext(par, pat1);
167*4882a593Smuzhiyun }
168*4882a593Smuzhiyun 
NVSetRopSolid(struct fb_info * info,u32 rop,u32 planemask)169*4882a593Smuzhiyun static void NVSetRopSolid(struct fb_info *info, u32 rop, u32 planemask)
170*4882a593Smuzhiyun {
171*4882a593Smuzhiyun 	struct nvidia_par *par = info->par;
172*4882a593Smuzhiyun 
173*4882a593Smuzhiyun 	if (planemask != ~0) {
174*4882a593Smuzhiyun 		NVSetPattern(info, 0, planemask, ~0, ~0);
175*4882a593Smuzhiyun 		if (par->currentRop != (rop + 32)) {
176*4882a593Smuzhiyun 			NVDmaStart(info, par, ROP_SET, 1);
177*4882a593Smuzhiyun 			NVDmaNext(par, NVCopyROP_PM[rop]);
178*4882a593Smuzhiyun 			par->currentRop = rop + 32;
179*4882a593Smuzhiyun 		}
180*4882a593Smuzhiyun 	} else if (par->currentRop != rop) {
181*4882a593Smuzhiyun 		if (par->currentRop >= 16)
182*4882a593Smuzhiyun 			NVSetPattern(info, ~0, ~0, ~0, ~0);
183*4882a593Smuzhiyun 		NVDmaStart(info, par, ROP_SET, 1);
184*4882a593Smuzhiyun 		NVDmaNext(par, NVCopyROP[rop]);
185*4882a593Smuzhiyun 		par->currentRop = rop;
186*4882a593Smuzhiyun 	}
187*4882a593Smuzhiyun }
188*4882a593Smuzhiyun 
NVSetClippingRectangle(struct fb_info * info,int x1,int y1,int x2,int y2)189*4882a593Smuzhiyun static void NVSetClippingRectangle(struct fb_info *info, int x1, int y1,
190*4882a593Smuzhiyun 				   int x2, int y2)
191*4882a593Smuzhiyun {
192*4882a593Smuzhiyun 	struct nvidia_par *par = info->par;
193*4882a593Smuzhiyun 	int h = y2 - y1 + 1;
194*4882a593Smuzhiyun 	int w = x2 - x1 + 1;
195*4882a593Smuzhiyun 
196*4882a593Smuzhiyun 	NVDmaStart(info, par, CLIP_POINT, 2);
197*4882a593Smuzhiyun 	NVDmaNext(par, (y1 << 16) | x1);
198*4882a593Smuzhiyun 	NVDmaNext(par, (h << 16) | w);
199*4882a593Smuzhiyun }
200*4882a593Smuzhiyun 
NVResetGraphics(struct fb_info * info)201*4882a593Smuzhiyun void NVResetGraphics(struct fb_info *info)
202*4882a593Smuzhiyun {
203*4882a593Smuzhiyun 	struct nvidia_par *par = info->par;
204*4882a593Smuzhiyun 	u32 surfaceFormat, patternFormat, rectFormat, lineFormat;
205*4882a593Smuzhiyun 	int pitch, i;
206*4882a593Smuzhiyun 
207*4882a593Smuzhiyun 	pitch = info->fix.line_length;
208*4882a593Smuzhiyun 
209*4882a593Smuzhiyun 	par->dmaBase = (u32 __iomem *) (&par->FbStart[par->FbUsableSize]);
210*4882a593Smuzhiyun 
211*4882a593Smuzhiyun 	for (i = 0; i < SKIPS; i++)
212*4882a593Smuzhiyun 		NV_WR32(&par->dmaBase[i], 0, 0x00000000);
213*4882a593Smuzhiyun 
214*4882a593Smuzhiyun 	NV_WR32(&par->dmaBase[0x0 + SKIPS], 0, 0x00040000);
215*4882a593Smuzhiyun 	NV_WR32(&par->dmaBase[0x1 + SKIPS], 0, 0x80000010);
216*4882a593Smuzhiyun 	NV_WR32(&par->dmaBase[0x2 + SKIPS], 0, 0x00042000);
217*4882a593Smuzhiyun 	NV_WR32(&par->dmaBase[0x3 + SKIPS], 0, 0x80000011);
218*4882a593Smuzhiyun 	NV_WR32(&par->dmaBase[0x4 + SKIPS], 0, 0x00044000);
219*4882a593Smuzhiyun 	NV_WR32(&par->dmaBase[0x5 + SKIPS], 0, 0x80000012);
220*4882a593Smuzhiyun 	NV_WR32(&par->dmaBase[0x6 + SKIPS], 0, 0x00046000);
221*4882a593Smuzhiyun 	NV_WR32(&par->dmaBase[0x7 + SKIPS], 0, 0x80000013);
222*4882a593Smuzhiyun 	NV_WR32(&par->dmaBase[0x8 + SKIPS], 0, 0x00048000);
223*4882a593Smuzhiyun 	NV_WR32(&par->dmaBase[0x9 + SKIPS], 0, 0x80000014);
224*4882a593Smuzhiyun 	NV_WR32(&par->dmaBase[0xA + SKIPS], 0, 0x0004A000);
225*4882a593Smuzhiyun 	NV_WR32(&par->dmaBase[0xB + SKIPS], 0, 0x80000015);
226*4882a593Smuzhiyun 	NV_WR32(&par->dmaBase[0xC + SKIPS], 0, 0x0004C000);
227*4882a593Smuzhiyun 	NV_WR32(&par->dmaBase[0xD + SKIPS], 0, 0x80000016);
228*4882a593Smuzhiyun 	NV_WR32(&par->dmaBase[0xE + SKIPS], 0, 0x0004E000);
229*4882a593Smuzhiyun 	NV_WR32(&par->dmaBase[0xF + SKIPS], 0, 0x80000017);
230*4882a593Smuzhiyun 
231*4882a593Smuzhiyun 	par->dmaPut = 0;
232*4882a593Smuzhiyun 	par->dmaCurrent = 16 + SKIPS;
233*4882a593Smuzhiyun 	par->dmaMax = 8191;
234*4882a593Smuzhiyun 	par->dmaFree = par->dmaMax - par->dmaCurrent;
235*4882a593Smuzhiyun 
236*4882a593Smuzhiyun 	switch (info->var.bits_per_pixel) {
237*4882a593Smuzhiyun 	case 32:
238*4882a593Smuzhiyun 	case 24:
239*4882a593Smuzhiyun 		surfaceFormat = SURFACE_FORMAT_DEPTH24;
240*4882a593Smuzhiyun 		patternFormat = PATTERN_FORMAT_DEPTH24;
241*4882a593Smuzhiyun 		rectFormat = RECT_FORMAT_DEPTH24;
242*4882a593Smuzhiyun 		lineFormat = LINE_FORMAT_DEPTH24;
243*4882a593Smuzhiyun 		break;
244*4882a593Smuzhiyun 	case 16:
245*4882a593Smuzhiyun 		surfaceFormat = SURFACE_FORMAT_DEPTH16;
246*4882a593Smuzhiyun 		patternFormat = PATTERN_FORMAT_DEPTH16;
247*4882a593Smuzhiyun 		rectFormat = RECT_FORMAT_DEPTH16;
248*4882a593Smuzhiyun 		lineFormat = LINE_FORMAT_DEPTH16;
249*4882a593Smuzhiyun 		break;
250*4882a593Smuzhiyun 	default:
251*4882a593Smuzhiyun 		surfaceFormat = SURFACE_FORMAT_DEPTH8;
252*4882a593Smuzhiyun 		patternFormat = PATTERN_FORMAT_DEPTH8;
253*4882a593Smuzhiyun 		rectFormat = RECT_FORMAT_DEPTH8;
254*4882a593Smuzhiyun 		lineFormat = LINE_FORMAT_DEPTH8;
255*4882a593Smuzhiyun 		break;
256*4882a593Smuzhiyun 	}
257*4882a593Smuzhiyun 
258*4882a593Smuzhiyun 	NVDmaStart(info, par, SURFACE_FORMAT, 4);
259*4882a593Smuzhiyun 	NVDmaNext(par, surfaceFormat);
260*4882a593Smuzhiyun 	NVDmaNext(par, pitch | (pitch << 16));
261*4882a593Smuzhiyun 	NVDmaNext(par, 0);
262*4882a593Smuzhiyun 	NVDmaNext(par, 0);
263*4882a593Smuzhiyun 
264*4882a593Smuzhiyun 	NVDmaStart(info, par, PATTERN_FORMAT, 1);
265*4882a593Smuzhiyun 	NVDmaNext(par, patternFormat);
266*4882a593Smuzhiyun 
267*4882a593Smuzhiyun 	NVDmaStart(info, par, RECT_FORMAT, 1);
268*4882a593Smuzhiyun 	NVDmaNext(par, rectFormat);
269*4882a593Smuzhiyun 
270*4882a593Smuzhiyun 	NVDmaStart(info, par, LINE_FORMAT, 1);
271*4882a593Smuzhiyun 	NVDmaNext(par, lineFormat);
272*4882a593Smuzhiyun 
273*4882a593Smuzhiyun 	par->currentRop = ~0;	/* set to something invalid */
274*4882a593Smuzhiyun 	NVSetRopSolid(info, ROP_COPY, ~0);
275*4882a593Smuzhiyun 
276*4882a593Smuzhiyun 	NVSetClippingRectangle(info, 0, 0, info->var.xres_virtual,
277*4882a593Smuzhiyun 			       info->var.yres_virtual);
278*4882a593Smuzhiyun 
279*4882a593Smuzhiyun 	NVDmaKickoff(par);
280*4882a593Smuzhiyun }
281*4882a593Smuzhiyun 
nvidiafb_sync(struct fb_info * info)282*4882a593Smuzhiyun int nvidiafb_sync(struct fb_info *info)
283*4882a593Smuzhiyun {
284*4882a593Smuzhiyun 	struct nvidia_par *par = info->par;
285*4882a593Smuzhiyun 
286*4882a593Smuzhiyun 	if (info->state != FBINFO_STATE_RUNNING)
287*4882a593Smuzhiyun 		return 0;
288*4882a593Smuzhiyun 
289*4882a593Smuzhiyun 	if (!par->lockup)
290*4882a593Smuzhiyun 		NVFlush(info);
291*4882a593Smuzhiyun 
292*4882a593Smuzhiyun 	if (!par->lockup)
293*4882a593Smuzhiyun 		NVSync(info);
294*4882a593Smuzhiyun 
295*4882a593Smuzhiyun 	return 0;
296*4882a593Smuzhiyun }
297*4882a593Smuzhiyun 
nvidiafb_copyarea(struct fb_info * info,const struct fb_copyarea * region)298*4882a593Smuzhiyun void nvidiafb_copyarea(struct fb_info *info, const struct fb_copyarea *region)
299*4882a593Smuzhiyun {
300*4882a593Smuzhiyun 	struct nvidia_par *par = info->par;
301*4882a593Smuzhiyun 
302*4882a593Smuzhiyun 	if (info->state != FBINFO_STATE_RUNNING)
303*4882a593Smuzhiyun 		return;
304*4882a593Smuzhiyun 
305*4882a593Smuzhiyun 	if (par->lockup) {
306*4882a593Smuzhiyun 		cfb_copyarea(info, region);
307*4882a593Smuzhiyun 		return;
308*4882a593Smuzhiyun 	}
309*4882a593Smuzhiyun 
310*4882a593Smuzhiyun 	NVDmaStart(info, par, BLIT_POINT_SRC, 3);
311*4882a593Smuzhiyun 	NVDmaNext(par, (region->sy << 16) | region->sx);
312*4882a593Smuzhiyun 	NVDmaNext(par, (region->dy << 16) | region->dx);
313*4882a593Smuzhiyun 	NVDmaNext(par, (region->height << 16) | region->width);
314*4882a593Smuzhiyun 
315*4882a593Smuzhiyun 	NVDmaKickoff(par);
316*4882a593Smuzhiyun }
317*4882a593Smuzhiyun 
nvidiafb_fillrect(struct fb_info * info,const struct fb_fillrect * rect)318*4882a593Smuzhiyun void nvidiafb_fillrect(struct fb_info *info, const struct fb_fillrect *rect)
319*4882a593Smuzhiyun {
320*4882a593Smuzhiyun 	struct nvidia_par *par = info->par;
321*4882a593Smuzhiyun 	u32 color;
322*4882a593Smuzhiyun 
323*4882a593Smuzhiyun 	if (info->state != FBINFO_STATE_RUNNING)
324*4882a593Smuzhiyun 		return;
325*4882a593Smuzhiyun 
326*4882a593Smuzhiyun 	if (par->lockup) {
327*4882a593Smuzhiyun 		cfb_fillrect(info, rect);
328*4882a593Smuzhiyun 		return;
329*4882a593Smuzhiyun 	}
330*4882a593Smuzhiyun 
331*4882a593Smuzhiyun 	if (info->var.bits_per_pixel == 8)
332*4882a593Smuzhiyun 		color = rect->color;
333*4882a593Smuzhiyun 	else
334*4882a593Smuzhiyun 		color = ((u32 *) info->pseudo_palette)[rect->color];
335*4882a593Smuzhiyun 
336*4882a593Smuzhiyun 	if (rect->rop != ROP_COPY)
337*4882a593Smuzhiyun 		NVSetRopSolid(info, rect->rop, ~0);
338*4882a593Smuzhiyun 
339*4882a593Smuzhiyun 	NVDmaStart(info, par, RECT_SOLID_COLOR, 1);
340*4882a593Smuzhiyun 	NVDmaNext(par, color);
341*4882a593Smuzhiyun 
342*4882a593Smuzhiyun 	NVDmaStart(info, par, RECT_SOLID_RECTS(0), 2);
343*4882a593Smuzhiyun 	NVDmaNext(par, (rect->dx << 16) | rect->dy);
344*4882a593Smuzhiyun 	NVDmaNext(par, (rect->width << 16) | rect->height);
345*4882a593Smuzhiyun 
346*4882a593Smuzhiyun 	NVDmaKickoff(par);
347*4882a593Smuzhiyun 
348*4882a593Smuzhiyun 	if (rect->rop != ROP_COPY)
349*4882a593Smuzhiyun 		NVSetRopSolid(info, ROP_COPY, ~0);
350*4882a593Smuzhiyun }
351*4882a593Smuzhiyun 
nvidiafb_mono_color_expand(struct fb_info * info,const struct fb_image * image)352*4882a593Smuzhiyun static void nvidiafb_mono_color_expand(struct fb_info *info,
353*4882a593Smuzhiyun 				       const struct fb_image *image)
354*4882a593Smuzhiyun {
355*4882a593Smuzhiyun 	struct nvidia_par *par = info->par;
356*4882a593Smuzhiyun 	u32 fg, bg, mask = ~(~0 >> (32 - info->var.bits_per_pixel));
357*4882a593Smuzhiyun 	u32 dsize, width, *data = (u32 *) image->data, tmp;
358*4882a593Smuzhiyun 	int j, k = 0;
359*4882a593Smuzhiyun 
360*4882a593Smuzhiyun 	width = (image->width + 31) & ~31;
361*4882a593Smuzhiyun 	dsize = (width * image->height) >> 5;
362*4882a593Smuzhiyun 
363*4882a593Smuzhiyun 	if (info->var.bits_per_pixel == 8) {
364*4882a593Smuzhiyun 		fg = image->fg_color | mask;
365*4882a593Smuzhiyun 		bg = image->bg_color | mask;
366*4882a593Smuzhiyun 	} else {
367*4882a593Smuzhiyun 		fg = ((u32 *) info->pseudo_palette)[image->fg_color] | mask;
368*4882a593Smuzhiyun 		bg = ((u32 *) info->pseudo_palette)[image->bg_color] | mask;
369*4882a593Smuzhiyun 	}
370*4882a593Smuzhiyun 
371*4882a593Smuzhiyun 	NVDmaStart(info, par, RECT_EXPAND_TWO_COLOR_CLIP, 7);
372*4882a593Smuzhiyun 	NVDmaNext(par, (image->dy << 16) | (image->dx & 0xffff));
373*4882a593Smuzhiyun 	NVDmaNext(par, ((image->dy + image->height) << 16) |
374*4882a593Smuzhiyun 		  ((image->dx + image->width) & 0xffff));
375*4882a593Smuzhiyun 	NVDmaNext(par, bg);
376*4882a593Smuzhiyun 	NVDmaNext(par, fg);
377*4882a593Smuzhiyun 	NVDmaNext(par, (image->height << 16) | width);
378*4882a593Smuzhiyun 	NVDmaNext(par, (image->height << 16) | width);
379*4882a593Smuzhiyun 	NVDmaNext(par, (image->dy << 16) | (image->dx & 0xffff));
380*4882a593Smuzhiyun 
381*4882a593Smuzhiyun 	while (dsize >= RECT_EXPAND_TWO_COLOR_DATA_MAX_DWORDS) {
382*4882a593Smuzhiyun 		NVDmaStart(info, par, RECT_EXPAND_TWO_COLOR_DATA(0),
383*4882a593Smuzhiyun 			   RECT_EXPAND_TWO_COLOR_DATA_MAX_DWORDS);
384*4882a593Smuzhiyun 
385*4882a593Smuzhiyun 		for (j = RECT_EXPAND_TWO_COLOR_DATA_MAX_DWORDS; j--;) {
386*4882a593Smuzhiyun 			tmp = data[k++];
387*4882a593Smuzhiyun 			reverse_order(&tmp);
388*4882a593Smuzhiyun 			NVDmaNext(par, tmp);
389*4882a593Smuzhiyun 		}
390*4882a593Smuzhiyun 
391*4882a593Smuzhiyun 		dsize -= RECT_EXPAND_TWO_COLOR_DATA_MAX_DWORDS;
392*4882a593Smuzhiyun 	}
393*4882a593Smuzhiyun 
394*4882a593Smuzhiyun 	if (dsize) {
395*4882a593Smuzhiyun 		NVDmaStart(info, par, RECT_EXPAND_TWO_COLOR_DATA(0), dsize);
396*4882a593Smuzhiyun 
397*4882a593Smuzhiyun 		for (j = dsize; j--;) {
398*4882a593Smuzhiyun 			tmp = data[k++];
399*4882a593Smuzhiyun 			reverse_order(&tmp);
400*4882a593Smuzhiyun 			NVDmaNext(par, tmp);
401*4882a593Smuzhiyun 		}
402*4882a593Smuzhiyun 	}
403*4882a593Smuzhiyun 
404*4882a593Smuzhiyun 	NVDmaKickoff(par);
405*4882a593Smuzhiyun }
406*4882a593Smuzhiyun 
nvidiafb_imageblit(struct fb_info * info,const struct fb_image * image)407*4882a593Smuzhiyun void nvidiafb_imageblit(struct fb_info *info, const struct fb_image *image)
408*4882a593Smuzhiyun {
409*4882a593Smuzhiyun 	struct nvidia_par *par = info->par;
410*4882a593Smuzhiyun 
411*4882a593Smuzhiyun 	if (info->state != FBINFO_STATE_RUNNING)
412*4882a593Smuzhiyun 		return;
413*4882a593Smuzhiyun 
414*4882a593Smuzhiyun 	if (image->depth == 1 && !par->lockup)
415*4882a593Smuzhiyun 		nvidiafb_mono_color_expand(info, image);
416*4882a593Smuzhiyun 	else
417*4882a593Smuzhiyun 		cfb_imageblit(info, image);
418*4882a593Smuzhiyun }
419