1 /***************************************************************************\
3 |* Copyright 1993-1999 NVIDIA, Corporation. All rights reserved. *|
5 |* NOTICE TO USER: The source code is copyrighted under U.S. and *|
6 |* international laws. Users and possessors of this source code are *|
7 |* hereby granted a nonexclusive, royalty-free copyright license to *|
8 |* use this code in individual and commercial software. *|
10 |* Any use of this source code must include, in the user documenta- *|
11 |* tion and internal comments to the code, notices to the end user *|
14 |* Copyright 1993-1999 NVIDIA, Corporation. All rights reserved. *|
16 |* NVIDIA, CORPORATION MAKES NO REPRESENTATION ABOUT THE SUITABILITY *|
17 |* OF THIS SOURCE CODE FOR ANY PURPOSE. IT IS PROVIDED "AS IS" *|
18 |* WITHOUT EXPRESS OR IMPLIED WARRANTY OF ANY KIND. NVIDIA, CORPOR- *|
19 |* ATION DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOURCE CODE, *|
20 |* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGE- *|
21 |* MENT, AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL *|
22 |* NVIDIA, CORPORATION BE LIABLE FOR ANY SPECIAL, INDIRECT, INCI- *|
23 |* DENTAL, OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RE- *|
24 |* SULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION *|
25 |* OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF *|
26 |* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOURCE CODE. *|
28 |* U.S. Government End Users. This source code is a "commercial *|
29 |* item," as that term is defined at 48 C.F.R. 2.101 (OCT 1995), *|
30 |* consisting of "commercial computer software" and "commercial *|
31 |* computer software documentation," as such terms are used in *|
32 |* 48 C.F.R. 12.212 (SEPT 1995) and is provided to the U.S. Govern- *|
33 |* ment only as a commercial end item. Consistent with 48 C.F.R. *|
34 |* 12.212 and 48 C.F.R. 227.7202-1 through 227.7202-4 (JUNE 1995), *|
35 |* all U.S. Government End Users acquire the source code with only *|
36 |* those rights set forth herein. *|
38 \***************************************************************************/
41 * GPL licensing note -- nVidia is allowing a liberal interpretation of
42 * the documentation restriction above, to merely say that this nVidia's
43 * copyright and disclaimer should be included with all code derived
44 * from this source. -- Jeff Garzik <jgarzik@pobox.com>, 01/Nov/99
47 /* $XFree86: xc/programs/Xserver/hw/xfree86/drivers/nv/riva_hw.c,v 1.33 2002/08/05 20:47:06 mvojkovi Exp $ */
49 #include <linux/kernel.h>
50 #include <linux/pci.h>
51 #include <linux/pci_ids.h>
57 * This file is an OS-agnostic file used to make RIVA 128 and RIVA TNT
58 * operate identically (except TNT has more memory and better 3D quality.
65 return ((NV_RD32(&chip->Rop->FifoFree, 0) < chip->FifoEmptyCount) ||
66 NV_RD32(&chip->PGRAPH[0x000006B0/4], 0) & 0x01);
73 return ((NV_RD32(&chip->Rop->FifoFree, 0) < chip->FifoEmptyCount) ||
74 NV_RD32(&chip->PGRAPH[0x00000700/4], 0) & 0x01);
81 return ((NV_RD32(&chip->Rop->FifoFree, 0) < chip->FifoEmptyCount) ||
82 NV_RD32(&chip->PGRAPH[0x00000700/4], 0) & 0x01);
85 static void vgaLockUnlock
92 VGA_WR08(chip->PCIO, 0x3D4, 0x11);
93 cr11 = VGA_RD08(chip->PCIO, 0x3D5);
94 if(Lock) cr11 |= 0x80;
96 VGA_WR08(chip->PCIO, 0x3D5, cr11);
98 static void nv3LockUnlock
104 VGA_WR08(chip->PVIO, 0x3C4, 0x06);
105 VGA_WR08(chip->PVIO, 0x3C5, Lock ? 0x99 : 0x57);
106 vgaLockUnlock(chip, Lock);
108 static void nv4LockUnlock
114 VGA_WR08(chip->PCIO, 0x3D4, 0x1F);
115 VGA_WR08(chip->PCIO, 0x3D5, Lock ? 0x99 : 0x57);
116 vgaLockUnlock(chip, Lock);
119 static int ShowHideCursor
126 cursor = chip->CurrentState->cursor1;
127 chip->CurrentState->cursor1 = (chip->CurrentState->cursor1 & 0xFE) |
129 VGA_WR08(chip->PCIO, 0x3D4, 0x31);
130 VGA_WR08(chip->PCIO, 0x3D5, chip->CurrentState->cursor1);
131 return (cursor & 0x01);
134 /****************************************************************************\
136 * The video arbitration routines calculate some "magic" numbers. Fixes *
137 * the snow seen when accessing the framebuffer without it. *
138 * It just works (I hope). *
140 \****************************************************************************/
142 #define DEFAULT_GR_LWM 100
143 #define DEFAULT_VID_LWM 100
144 #define DEFAULT_GR_BURST_SIZE 256
145 #define DEFAULT_VID_BURST_SIZE 128
150 #define GFIFO_SIZE 320
151 #define GFIFO_SIZE_128 256
152 #define MFIFO_SIZE 120
153 #define VFIFO_SIZE 256
163 int wcmocc, wcgocc, wcvocc, wcvlwm, wcglwm;
181 int graphics_burst_size;
182 int video_burst_size;
183 int graphics_hi_priority;
184 int media_hi_priority;
204 int graphics_burst_size;
205 int video_burst_size;
224 int graphics_burst_size;
225 int video_burst_size;
242 static int nv3_iterate(nv3_fifo_info *res_info, nv3_sim_state * state, nv3_arb_info *ainfo)
246 int vfsize, mfsize, gfsize;
247 int mburst_size = 32;
248 int mmisses, gmisses, vmisses;
250 int vlwm, glwm, mlwm;
264 if (ainfo->gburst_size == 128) max_gfsize = GFIFO_SIZE_128;
265 else max_gfsize = GFIFO_SIZE;
266 max_gfsize = GFIFO_SIZE;
271 if (ainfo->wcvocc > ainfo->vocc) ainfo->wcvocc = ainfo->vocc;
272 if (ainfo->wcvlwm > vlwm) ainfo->wcvlwm = vlwm ;
273 ns = 1000000 * ainfo->vburst_size/(state->memory_width/8)/state->mclk_khz;
274 vfsize = ns * ainfo->vdrain_rate / 1000000;
275 vfsize = ainfo->wcvlwm - ainfo->vburst_size + vfsize;
277 if (state->enable_mp)
279 if (ainfo->wcmocc > ainfo->mocc) ainfo->wcmocc = ainfo->mocc;
283 if (ainfo->wcglwm > glwm) ainfo->wcglwm = glwm ;
284 if (ainfo->wcgocc > ainfo->gocc) ainfo->wcgocc = ainfo->gocc;
285 ns = 1000000 * (ainfo->gburst_size/(state->memory_width/8))/state->mclk_khz;
286 gfsize = (ns * (long) ainfo->gdrain_rate)/1000000;
287 gfsize = ainfo->wcglwm - ainfo->gburst_size + gfsize;
290 if (!state->gr_during_vid && ainfo->vid_en)
291 if (ainfo->vid_en && (ainfo->vocc < 0) && !ainfo->vid_only_once)
293 else if (ainfo->mocc < 0)
295 else if (ainfo->gocc< ainfo->by_gfacc)
298 else switch (ainfo->priority)
301 if (ainfo->vid_en && ainfo->vocc<0 && !ainfo->vid_only_once)
303 else if (ainfo->gr_en && ainfo->gocc<0 && !ainfo->gr_only_once)
305 else if (ainfo->mocc<0)
310 if (ainfo->gr_en && ainfo->gocc<0 && !ainfo->gr_only_once)
312 else if (ainfo->vid_en && ainfo->vocc<0 && !ainfo->vid_only_once)
314 else if (ainfo->mocc<0)
321 else if (ainfo->gr_en && ainfo->gocc<0 && !ainfo->gr_only_once)
323 else if (ainfo->vid_en && ainfo->vocc<0 && !ainfo->vid_only_once)
334 if (last==cur) misses = 0;
335 else if (ainfo->first_vacc) misses = vmisses;
337 ainfo->first_vacc = 0;
340 ns = 1000000 * (vmisses*state->mem_page_miss + state->mem_latency)/state->mclk_khz;
341 vlwm = ns * ainfo->vdrain_rate/ 1000000;
342 vlwm = ainfo->vocc - vlwm;
344 ns = 1000000*(misses*state->mem_page_miss + ainfo->vburst_size)/(state->memory_width/8)/state->mclk_khz;
345 ainfo->vocc = ainfo->vocc + ainfo->vburst_size - ns*ainfo->vdrain_rate/1000000;
346 ainfo->gocc = ainfo->gocc - ns*ainfo->gdrain_rate/1000000;
347 ainfo->mocc = ainfo->mocc - ns*ainfo->mdrain_rate/1000000;
350 if (last==cur) misses = 0;
351 else if (ainfo->first_gacc) misses = gmisses;
353 ainfo->first_gacc = 0;
356 ns = 1000000*(gmisses*state->mem_page_miss + state->mem_latency)/state->mclk_khz ;
357 glwm = ns * ainfo->gdrain_rate/1000000;
358 glwm = ainfo->gocc - glwm;
360 ns = 1000000*(misses*state->mem_page_miss + ainfo->gburst_size/(state->memory_width/8))/state->mclk_khz;
361 ainfo->vocc = ainfo->vocc + 0 - ns*ainfo->vdrain_rate/1000000;
362 ainfo->gocc = ainfo->gocc + ainfo->gburst_size - ns*ainfo->gdrain_rate/1000000;
363 ainfo->mocc = ainfo->mocc + 0 - ns*ainfo->mdrain_rate/1000000;
366 if (last==cur) misses = 0;
367 else if (ainfo->first_macc) misses = mmisses;
369 ainfo->first_macc = 0;
370 ns = 1000000*(misses*state->mem_page_miss + mburst_size/(state->memory_width/8))/state->mclk_khz;
371 ainfo->vocc = ainfo->vocc + 0 - ns*ainfo->vdrain_rate/1000000;
372 ainfo->gocc = ainfo->gocc + 0 - ns*ainfo->gdrain_rate/1000000;
373 ainfo->mocc = ainfo->mocc + mburst_size - ns*ainfo->mdrain_rate/1000000;
378 ainfo->converged = 0;
381 ns = 1000000*ainfo->gburst_size/(state->memory_width/8)/state->mclk_khz;
382 tmp = ns * ainfo->gdrain_rate/1000000;
383 if (abs(ainfo->gburst_size) + ((abs(ainfo->wcglwm) + 16 ) & ~0x7) - tmp > max_gfsize)
385 ainfo->converged = 0;
388 ns = 1000000*ainfo->vburst_size/(state->memory_width/8)/state->mclk_khz;
389 tmp = ns * ainfo->vdrain_rate/1000000;
390 if (abs(ainfo->vburst_size) + (abs(ainfo->wcvlwm + 32) & ~0xf) - tmp> VFIFO_SIZE)
392 ainfo->converged = 0;
395 if (abs(ainfo->gocc) > max_gfsize)
397 ainfo->converged = 0;
400 if (abs(ainfo->vocc) > VFIFO_SIZE)
402 ainfo->converged = 0;
405 if (abs(ainfo->mocc) > MFIFO_SIZE)
407 ainfo->converged = 0;
410 if (abs(vfsize) > VFIFO_SIZE)
412 ainfo->converged = 0;
415 if (abs(gfsize) > max_gfsize)
417 ainfo->converged = 0;
420 if (abs(mfsize) > MFIFO_SIZE)
422 ainfo->converged = 0;
427 static char nv3_arb(nv3_fifo_info * res_info, nv3_sim_state * state, nv3_arb_info *ainfo)
429 long ens, vns, mns, gns;
430 int mmisses, gmisses, vmisses, eburst_size, mburst_size;
434 refresh_cycle = 2*(state->mclk_khz/state->pclk_khz) + 5;
436 if (state->mem_aligned) gmisses = 2;
439 eburst_size = state->memory_width * 1;
441 gns = 1000000 * (gmisses*state->mem_page_miss + state->mem_latency)/state->mclk_khz;
442 ainfo->by_gfacc = gns*ainfo->gdrain_rate/1000000;
448 ainfo->engine_en = 1;
449 ainfo->converged = 1;
450 if (ainfo->engine_en)
452 ens = 1000000*(state->mem_page_miss + eburst_size/(state->memory_width/8) +refresh_cycle)/state->mclk_khz;
453 ainfo->mocc = state->enable_mp ? 0-ens*ainfo->mdrain_rate/1000000 : 0;
454 ainfo->vocc = ainfo->vid_en ? 0-ens*ainfo->vdrain_rate/1000000 : 0;
455 ainfo->gocc = ainfo->gr_en ? 0-ens*ainfo->gdrain_rate/1000000 : 0;
457 ainfo->first_vacc = 1;
458 ainfo->first_gacc = 1;
459 ainfo->first_macc = 1;
460 nv3_iterate(res_info, state,ainfo);
462 if (state->enable_mp)
464 mns = 1000000 * (mmisses*state->mem_page_miss + mburst_size/(state->memory_width/8) + refresh_cycle)/state->mclk_khz;
465 ainfo->mocc = state->enable_mp ? 0 : mburst_size - mns*ainfo->mdrain_rate/1000000;
466 ainfo->vocc = ainfo->vid_en ? 0 : 0- mns*ainfo->vdrain_rate/1000000;
467 ainfo->gocc = ainfo->gr_en ? 0: 0- mns*ainfo->gdrain_rate/1000000;
469 ainfo->first_vacc = 1;
470 ainfo->first_gacc = 1;
471 ainfo->first_macc = 0;
472 nv3_iterate(res_info, state,ainfo);
476 ainfo->first_vacc = 1;
477 ainfo->first_gacc = 0;
478 ainfo->first_macc = 1;
479 gns = 1000000*(gmisses*state->mem_page_miss + ainfo->gburst_size/(state->memory_width/8) + refresh_cycle)/state->mclk_khz;
480 ainfo->gocc = ainfo->gburst_size - gns*ainfo->gdrain_rate/1000000;
481 ainfo->vocc = ainfo->vid_en? 0-gns*ainfo->vdrain_rate/1000000 : 0;
482 ainfo->mocc = state->enable_mp ? 0-gns*ainfo->mdrain_rate/1000000: 0;
483 ainfo->cur = GRAPHICS;
484 nv3_iterate(res_info, state,ainfo);
488 ainfo->first_vacc = 0;
489 ainfo->first_gacc = 1;
490 ainfo->first_macc = 1;
491 vns = 1000000*(vmisses*state->mem_page_miss + ainfo->vburst_size/(state->memory_width/8) + refresh_cycle)/state->mclk_khz;
492 ainfo->vocc = ainfo->vburst_size - vns*ainfo->vdrain_rate/1000000;
493 ainfo->gocc = ainfo->gr_en? (0-vns*ainfo->gdrain_rate/1000000) : 0;
494 ainfo->mocc = state->enable_mp? 0-vns*ainfo->mdrain_rate/1000000 :0 ;
496 nv3_iterate(res_info, state, ainfo);
498 if (ainfo->converged)
500 res_info->graphics_lwm = (int)abs(ainfo->wcglwm) + 16;
501 res_info->video_lwm = (int)abs(ainfo->wcvlwm) + 32;
502 res_info->graphics_burst_size = ainfo->gburst_size;
503 res_info->video_burst_size = ainfo->vburst_size;
504 res_info->graphics_hi_priority = (ainfo->priority == GRAPHICS);
505 res_info->media_hi_priority = (ainfo->priority == MPORT);
506 if (res_info->video_lwm > 160)
508 res_info->graphics_lwm = 256;
509 res_info->video_lwm = 128;
510 res_info->graphics_burst_size = 64;
511 res_info->video_burst_size = 64;
512 res_info->graphics_hi_priority = 0;
513 res_info->media_hi_priority = 0;
514 ainfo->converged = 0;
517 if (res_info->video_lwm > 128)
519 res_info->video_lwm = 128;
525 res_info->graphics_lwm = 256;
526 res_info->video_lwm = 128;
527 res_info->graphics_burst_size = 64;
528 res_info->video_burst_size = 64;
529 res_info->graphics_hi_priority = 0;
530 res_info->media_hi_priority = 0;
534 static char nv3_get_param(nv3_fifo_info *res_info, nv3_sim_state * state, nv3_arb_info *ainfo)
539 for (p=0; p < 2; p++)
541 for (g=128 ; g > 32; g= g>> 1)
543 for (v=128; v >=32; v = v>> 1)
546 ainfo->gburst_size = g;
547 ainfo->vburst_size = v;
548 done = nv3_arb(res_info, state,ainfo);
549 if (done && (g==128))
550 if ((res_info->graphics_lwm + g) > 256)
561 static void nv3CalcArbitration
563 nv3_fifo_info * res_info,
564 nv3_sim_state * state
567 nv3_fifo_info save_info;
569 char res_gr, res_vid;
572 ainfo.vid_en = state->enable_video;
573 ainfo.vid_only_once = 0;
574 ainfo.gr_only_once = 0;
575 ainfo.gdrain_rate = (int) state->pclk_khz * (state->pix_bpp/8);
576 ainfo.vdrain_rate = (int) state->pclk_khz * 2;
577 if (state->video_scale != 0)
578 ainfo.vdrain_rate = ainfo.vdrain_rate/state->video_scale;
579 ainfo.mdrain_rate = 33000;
580 res_info->rtl_values = 0;
581 if (!state->gr_during_vid && state->enable_video)
583 ainfo.gr_only_once = 1;
585 ainfo.gdrain_rate = 0;
586 res_vid = nv3_get_param(res_info, state, &ainfo);
587 res_vid = ainfo.converged;
588 save_info.video_lwm = res_info->video_lwm;
589 save_info.video_burst_size = res_info->video_burst_size;
591 ainfo.vid_only_once = 1;
593 ainfo.gdrain_rate = (int) state->pclk_khz * (state->pix_bpp/8);
594 ainfo.vdrain_rate = 0;
595 res_gr = nv3_get_param(res_info, state, &ainfo);
596 res_gr = ainfo.converged;
597 res_info->video_lwm = save_info.video_lwm;
598 res_info->video_burst_size = save_info.video_burst_size;
599 res_info->valid = res_gr & res_vid;
603 if (!ainfo.gr_en) ainfo.gdrain_rate = 0;
604 if (!ainfo.vid_en) ainfo.vdrain_rate = 0;
605 res_gr = nv3_get_param(res_info, state, &ainfo);
606 res_info->valid = ainfo.converged;
609 static void nv3UpdateArbitrationSettings
618 nv3_fifo_info fifo_data;
619 nv3_sim_state sim_data;
620 unsigned int M, N, P, pll, MClk;
622 pll = NV_RD32(&chip->PRAMDAC0[0x00000504/4], 0);
623 M = (pll >> 0) & 0xFF; N = (pll >> 8) & 0xFF; P = (pll >> 16) & 0x0F;
624 MClk = (N * chip->CrystalFreqKHz / M) >> P;
625 sim_data.pix_bpp = (char)pixelDepth;
626 sim_data.enable_video = 0;
627 sim_data.enable_mp = 0;
628 sim_data.video_scale = 1;
629 sim_data.memory_width = (NV_RD32(&chip->PEXTDEV[0x00000000/4], 0) & 0x10) ?
631 sim_data.memory_width = 128;
633 sim_data.mem_latency = 9;
634 sim_data.mem_aligned = 1;
635 sim_data.mem_page_miss = 11;
636 sim_data.gr_during_vid = 0;
637 sim_data.pclk_khz = VClk;
638 sim_data.mclk_khz = MClk;
639 nv3CalcArbitration(&fifo_data, &sim_data);
642 int b = fifo_data.graphics_burst_size >> 4;
646 *lwm = fifo_data.graphics_lwm >> 3;
654 static void nv4CalcArbitration
660 int data, pagemiss, cas,width, video_enable, color_key_enable, bpp, align;
661 int nvclks, mclks, pclks, vpagemiss, crtpagemiss, vbs;
662 int found, mclk_extra, mclk_loop, cbs, m1, p1;
663 int mclk_freq, pclk_freq, nvclk_freq, mp_enable;
664 int us_m, us_n, us_p, video_drain_rate, crtc_drain_rate;
665 int vpm_us, us_video, vlwm, video_fill_us, cpm_us, us_crt,clwm;
669 pclk_freq = arb->pclk_khz;
670 mclk_freq = arb->mclk_khz;
671 nvclk_freq = arb->nvclk_khz;
672 pagemiss = arb->mem_page_miss;
673 cas = arb->mem_latency;
674 width = arb->memory_width >> 6;
675 video_enable = arb->enable_video;
676 color_key_enable = arb->gr_during_vid;
678 align = arb->mem_aligned;
679 mp_enable = arb->enable_mp;
710 mclk_loop = mclks+mclk_extra;
711 us_m = mclk_loop *1000*1000 / mclk_freq;
712 us_n = nvclks*1000*1000 / nvclk_freq;
713 us_p = nvclks*1000*1000 / pclk_freq;
716 video_drain_rate = pclk_freq * 2;
717 crtc_drain_rate = pclk_freq * bpp/8;
721 vpm_us = (vpagemiss * pagemiss)*1000*1000/mclk_freq;
722 if (nvclk_freq * 2 > mclk_freq * width)
723 video_fill_us = cbs*1000*1000 / 16 / nvclk_freq ;
725 video_fill_us = cbs*1000*1000 / (8 * width) / mclk_freq;
726 us_video = vpm_us + us_m + us_n + us_p + video_fill_us;
727 vlwm = us_video * video_drain_rate/(1000*1000);
730 if (vlwm > 128) vbs = 64;
731 if (vlwm > (256-64)) vbs = 32;
732 if (nvclk_freq * 2 > mclk_freq * width)
733 video_fill_us = vbs *1000*1000/ 16 / nvclk_freq ;
735 video_fill_us = vbs*1000*1000 / (8 * width) / mclk_freq;
736 cpm_us = crtpagemiss * pagemiss *1000*1000/ mclk_freq;
743 clwm = us_crt * crtc_drain_rate/(1000*1000);
748 crtc_drain_rate = pclk_freq * bpp/8;
751 cpm_us = crtpagemiss * pagemiss *1000*1000/ mclk_freq;
752 us_crt = cpm_us + us_m + us_n + us_p ;
753 clwm = us_crt * crtc_drain_rate/(1000*1000);
756 m1 = clwm + cbs - 512;
757 p1 = m1 * pclk_freq / mclk_freq;
759 if ((p1 < m1) && (m1 > 0))
763 if (mclk_extra ==0) found = 1;
766 else if (video_enable)
768 if ((clwm > 511) || (vlwm > 255))
772 if (mclk_extra ==0) found = 1;
782 if (mclk_extra ==0) found = 1;
788 if (clwm < 384) clwm = 384;
789 if (vlwm < 128) vlwm = 128;
791 fifo->graphics_lwm = data;
792 fifo->graphics_burst_size = 128;
793 data = (int)((vlwm+15));
794 fifo->video_lwm = data;
795 fifo->video_burst_size = vbs;
798 static void nv4UpdateArbitrationSettings
807 nv4_fifo_info fifo_data;
808 nv4_sim_state sim_data;
809 unsigned int M, N, P, pll, MClk, NVClk, cfg1;
811 pll = NV_RD32(&chip->PRAMDAC0[0x00000504/4], 0);
812 M = (pll >> 0) & 0xFF; N = (pll >> 8) & 0xFF; P = (pll >> 16) & 0x0F;
813 MClk = (N * chip->CrystalFreqKHz / M) >> P;
814 pll = NV_RD32(&chip->PRAMDAC0[0x00000500/4], 0);
815 M = (pll >> 0) & 0xFF; N = (pll >> 8) & 0xFF; P = (pll >> 16) & 0x0F;
816 NVClk = (N * chip->CrystalFreqKHz / M) >> P;
817 cfg1 = NV_RD32(&chip->PFB[0x00000204/4], 0);
818 sim_data.pix_bpp = (char)pixelDepth;
819 sim_data.enable_video = 0;
820 sim_data.enable_mp = 0;
821 sim_data.memory_width = (NV_RD32(&chip->PEXTDEV[0x00000000/4], 0) & 0x10) ?
823 sim_data.mem_latency = (char)cfg1 & 0x0F;
824 sim_data.mem_aligned = 1;
825 sim_data.mem_page_miss = (char)(((cfg1 >> 4) &0x0F) + ((cfg1 >> 31) & 0x01));
826 sim_data.gr_during_vid = 0;
827 sim_data.pclk_khz = VClk;
828 sim_data.mclk_khz = MClk;
829 sim_data.nvclk_khz = NVClk;
830 nv4CalcArbitration(&fifo_data, &sim_data);
833 int b = fifo_data.graphics_burst_size >> 4;
837 *lwm = fifo_data.graphics_lwm >> 3;
840 static void nv10CalcArbitration
842 nv10_fifo_info *fifo,
846 int data, pagemiss, cas,width, video_enable, color_key_enable, bpp, align;
847 int nvclks, mclks, pclks, vpagemiss, crtpagemiss, vbs;
848 int nvclk_fill, us_extra;
849 int found, mclk_extra, mclk_loop, cbs, m1;
850 int mclk_freq, pclk_freq, nvclk_freq, mp_enable;
851 int us_m, us_m_min, us_n, us_p, video_drain_rate, crtc_drain_rate;
852 int vus_m, vus_n, vus_p;
853 int vpm_us, us_video, vlwm, cpm_us, us_crt,clwm;
855 int craw, m2us, us_pipe, us_pipe_min, vus_pipe, p1clk, p2;
856 int pclks_2_top_fifo, min_mclk_extra;
857 int us_min_mclk_extra;
860 pclk_freq = arb->pclk_khz; /* freq in KHz */
861 mclk_freq = arb->mclk_khz;
862 nvclk_freq = arb->nvclk_khz;
863 pagemiss = arb->mem_page_miss;
864 cas = arb->mem_latency;
865 width = arb->memory_width/64;
866 video_enable = arb->enable_video;
867 color_key_enable = arb->gr_during_vid;
869 align = arb->mem_aligned;
870 mp_enable = arb->enable_mp;
877 pclks = 4; /* lwm detect. */
879 nvclks = 3; /* lwm -> sync. */
880 nvclks += 2; /* fbi bus cycles (1 req + 1 busy) */
882 mclks = 1; /* 2 edge sync. may be very close to edge so just put one. */
884 mclks += 1; /* arb_hp_req */
885 mclks += 5; /* ap_hp_req tiling pipeline */
887 mclks += 2; /* tc_req latency fifo */
888 mclks += 2; /* fb_cas_n_ memory request to fbio block */
889 mclks += 7; /* sm_d_rdv data returned from fbio block */
891 /* fb.rd.d.Put_gc need to accumulate 256 bits for read */
892 if (arb->memory_type == 0)
893 if (arb->memory_width == 64) /* 64 bit bus */
898 if (arb->memory_width == 64) /* 64 bit bus */
903 if ((!video_enable) && (arb->memory_width == 128))
905 mclk_extra = (bpp == 32) ? 31 : 42; /* Margin of error */
910 mclk_extra = (bpp == 32) ? 8 : 4; /* Margin of error */
911 /* mclk_extra = 4; */ /* Margin of error */
915 nvclks += 1; /* 2 edge sync. may be very close to edge so just put one. */
916 nvclks += 1; /* fbi_d_rdv_n */
917 nvclks += 1; /* Fbi_d_rdata */
918 nvclks += 1; /* crtfifo load */
921 mclks+=4; /* Mp can get in with a burst of 8. */
922 /* Extra clocks determined by heuristics */
930 mclk_loop = mclks+mclk_extra;
931 us_m = mclk_loop *1000*1000 / mclk_freq; /* Mclk latency in us */
932 us_m_min = mclks * 1000*1000 / mclk_freq; /* Minimum Mclk latency in us */
933 us_min_mclk_extra = min_mclk_extra *1000*1000 / mclk_freq;
934 us_n = nvclks*1000*1000 / nvclk_freq;/* nvclk latency in us */
935 us_p = pclks*1000*1000 / pclk_freq;/* nvclk latency in us */
936 us_pipe = us_m + us_n + us_p;
937 us_pipe_min = us_m_min + us_n + us_p;
940 vus_m = mclk_loop *1000*1000 / mclk_freq; /* Mclk latency in us */
941 vus_n = (4)*1000*1000 / nvclk_freq;/* nvclk latency in us */
942 vus_p = 0*1000*1000 / pclk_freq;/* pclk latency in us */
943 vus_pipe = vus_m + vus_n + vus_p;
946 video_drain_rate = pclk_freq * 4; /* MB/s */
947 crtc_drain_rate = pclk_freq * bpp/8; /* MB/s */
949 vpagemiss = 1; /* self generating page miss */
950 vpagemiss += 1; /* One higher priority before */
952 crtpagemiss = 2; /* self generating page miss */
954 crtpagemiss += 1; /* if MA0 conflict */
956 vpm_us = (vpagemiss * pagemiss)*1000*1000/mclk_freq;
958 us_video = vpm_us + vus_m; /* Video has separate read return path */
960 cpm_us = crtpagemiss * pagemiss *1000*1000/ mclk_freq;
962 us_video /* Wait for video */
963 +cpm_us /* CRT Page miss */
964 +us_m + us_n +us_p /* other latency */
967 clwm = us_crt * crtc_drain_rate/(1000*1000);
968 clwm++; /* fixed point <= float_point - 1. Fixes that */
970 crtc_drain_rate = pclk_freq * bpp/8; /* bpp * pclk/8 */
972 crtpagemiss = 1; /* self generating page miss */
973 crtpagemiss += 1; /* MA0 page miss */
975 crtpagemiss += 1; /* if MA0 conflict */
976 cpm_us = crtpagemiss * pagemiss *1000*1000/ mclk_freq;
977 us_crt = cpm_us + us_m + us_n + us_p ;
978 clwm = us_crt * crtc_drain_rate/(1000*1000);
979 clwm++; /* fixed point <= float_point - 1. Fixes that */
983 // Another concern, only for high pclks so don't do this
985 // What happens if the latency to fetch the cbs is so large that
986 // fifo empties. In that case we need to have an alternate clwm value
987 // based off the total burst fetch
989 us_crt = (cbs * 1000 * 1000)/ (8*width)/mclk_freq ;
990 us_crt = us_crt + us_m + us_n + us_p + (4 * 1000 * 1000)/mclk_freq;
991 clwm_mt = us_crt * crtc_drain_rate/(1000*1000);
996 /* Finally, a heuristic check when width == 64 bits */
998 nvclk_fill = nvclk_freq * 8;
999 if(crtc_drain_rate * 100 >= nvclk_fill * 102)
1000 clwm = 0xfff; /*Large number to fail */
1002 else if(crtc_drain_rate * 100 >= nvclk_fill * 98) {
1005 us_extra = (cbs * 1000 * 1000)/ (8*width)/mclk_freq ;
1016 clwm_rnd_down = ((int)clwm/8)*8;
1017 if (clwm_rnd_down < clwm)
1020 m1 = clwm + cbs - 1024; /* Amount of overfill */
1021 m2us = us_pipe_min + us_min_mclk_extra;
1022 pclks_2_top_fifo = (1024-clwm)/(8*width);
1024 /* pclk cycles to drain */
1025 p1clk = m2us * pclk_freq/(1000*1000);
1026 p2 = p1clk * bpp / 8; /* bytes drained. */
1028 if((p2 < m1) && (m1 > 0)) {
1031 if(min_mclk_extra == 0) {
1033 found = 1; /* Can't adjust anymore! */
1035 cbs = cbs/2; /* reduce the burst size */
1041 if (clwm > 1023){ /* Have some margin */
1044 if(min_mclk_extra == 0)
1045 found = 1; /* Can't adjust anymore! */
1052 if(clwm < (1024-cbs+8)) clwm = 1024-cbs+8;
1054 /* printf("CRT LWM: %f bytes, prog: 0x%x, bs: 256\n", clwm, data ); */
1055 fifo->graphics_lwm = data; fifo->graphics_burst_size = cbs;
1057 /* printf("VID LWM: %f bytes, prog: 0x%x, bs: %d\n, ", vlwm, data, vbs ); */
1058 fifo->video_lwm = 1024; fifo->video_burst_size = 512;
1061 static void nv10UpdateArbitrationSettings
1064 unsigned pixelDepth,
1070 nv10_fifo_info fifo_data;
1071 nv10_sim_state sim_data;
1072 unsigned int M, N, P, pll, MClk, NVClk, cfg1;
1074 pll = NV_RD32(&chip->PRAMDAC0[0x00000504/4], 0);
1075 M = (pll >> 0) & 0xFF; N = (pll >> 8) & 0xFF; P = (pll >> 16) & 0x0F;
1076 MClk = (N * chip->CrystalFreqKHz / M) >> P;
1077 pll = NV_RD32(&chip->PRAMDAC0[0x00000500/4], 0);
1078 M = (pll >> 0) & 0xFF; N = (pll >> 8) & 0xFF; P = (pll >> 16) & 0x0F;
1079 NVClk = (N * chip->CrystalFreqKHz / M) >> P;
1080 cfg1 = NV_RD32(&chip->PFB[0x00000204/4], 0);
1081 sim_data.pix_bpp = (char)pixelDepth;
1082 sim_data.enable_video = 0;
1083 sim_data.enable_mp = 0;
1084 sim_data.memory_type = (NV_RD32(&chip->PFB[0x00000200/4], 0) & 0x01) ?
1086 sim_data.memory_width = (NV_RD32(&chip->PEXTDEV[0x00000000/4], 0) & 0x10) ?
1088 sim_data.mem_latency = (char)cfg1 & 0x0F;
1089 sim_data.mem_aligned = 1;
1090 sim_data.mem_page_miss = (char)(((cfg1 >> 4) &0x0F) + ((cfg1 >> 31) & 0x01));
1091 sim_data.gr_during_vid = 0;
1092 sim_data.pclk_khz = VClk;
1093 sim_data.mclk_khz = MClk;
1094 sim_data.nvclk_khz = NVClk;
1095 nv10CalcArbitration(&fifo_data, &sim_data);
1096 if (fifo_data.valid)
1098 int b = fifo_data.graphics_burst_size >> 4;
1102 *lwm = fifo_data.graphics_lwm >> 3;
1106 static void nForceUpdateArbitrationSettings
1109 unsigned pixelDepth,
1115 nv10_fifo_info fifo_data;
1116 nv10_sim_state sim_data;
1117 unsigned int M, N, P, pll, MClk, NVClk;
1118 unsigned int uMClkPostDiv;
1119 struct pci_dev *dev;
1121 dev = pci_get_bus_and_slot(0, 3);
1122 pci_read_config_dword(dev, 0x6C, &uMClkPostDiv);
1124 uMClkPostDiv = (uMClkPostDiv >> 8) & 0xf;
1126 if(!uMClkPostDiv) uMClkPostDiv = 4;
1127 MClk = 400000 / uMClkPostDiv;
1129 pll = NV_RD32(&chip->PRAMDAC0[0x00000500/4], 0);
1130 M = (pll >> 0) & 0xFF; N = (pll >> 8) & 0xFF; P = (pll >> 16) & 0x0F;
1131 NVClk = (N * chip->CrystalFreqKHz / M) >> P;
1132 sim_data.pix_bpp = (char)pixelDepth;
1133 sim_data.enable_video = 0;
1134 sim_data.enable_mp = 0;
1136 dev = pci_get_bus_and_slot(0, 1);
1137 pci_read_config_dword(dev, 0x7C, &sim_data.memory_type);
1139 sim_data.memory_type = (sim_data.memory_type >> 12) & 1;
1141 sim_data.memory_width = 64;
1142 sim_data.mem_latency = 3;
1143 sim_data.mem_aligned = 1;
1144 sim_data.mem_page_miss = 10;
1145 sim_data.gr_during_vid = 0;
1146 sim_data.pclk_khz = VClk;
1147 sim_data.mclk_khz = MClk;
1148 sim_data.nvclk_khz = NVClk;
1149 nv10CalcArbitration(&fifo_data, &sim_data);
1150 if (fifo_data.valid)
1152 int b = fifo_data.graphics_burst_size >> 4;
1156 *lwm = fifo_data.graphics_lwm >> 3;
1160 /****************************************************************************\
1162 * RIVA Mode State Routines *
1164 \****************************************************************************/
1167 * Calculate the Video Clock parameters for the PLL.
1169 static int CalcVClock
1179 unsigned lowM, highM, highP;
1180 unsigned DeltaNew, DeltaOld;
1181 unsigned VClk, Freq;
1184 DeltaOld = 0xFFFFFFFF;
1186 VClk = (unsigned)clockIn;
1188 if (chip->CrystalFreqKHz == 13500)
1191 highM = 13 - (chip->Architecture == NV_ARCH_03);
1196 highM = 14 - (chip->Architecture == NV_ARCH_03);
1199 highP = 4 - (chip->Architecture == NV_ARCH_03);
1200 for (P = 0; P <= highP; P ++)
1203 if ((Freq >= 128000) && (Freq <= chip->MaxVClockFreqKHz))
1205 for (M = lowM; M <= highM; M++)
1207 N = (VClk << P) * M / chip->CrystalFreqKHz;
1209 Freq = (chip->CrystalFreqKHz * N / M) >> P;
1211 DeltaNew = Freq - VClk;
1213 DeltaNew = VClk - Freq;
1214 if (DeltaNew < DeltaOld)
1220 DeltaOld = DeltaNew;
1226 return (DeltaOld != 0xFFFFFFFF);
1229 * Calculate extended mode parameters (SVGA) and save in a
1230 * mode state structure.
1235 RIVA_HW_STATE *state,
1243 int pixelDepth, VClk, m, n, p;
1245 * Save mode parameters.
1247 state->bpp = bpp; /* this is not bitsPerPixel, it's 8,15,16,32 */
1248 state->width = width;
1249 state->height = height;
1251 * Extended RIVA registers.
1253 pixelDepth = (bpp + 1)/8;
1254 if (!CalcVClock(dotClock, &VClk, &m, &n, &p, chip))
1257 switch (chip->Architecture)
1260 nv3UpdateArbitrationSettings(VClk,
1262 &(state->arbitration0),
1263 &(state->arbitration1),
1265 state->cursor0 = 0x00;
1266 state->cursor1 = 0x78;
1267 state->cursor2 = 0x00000000;
1268 state->pllsel = 0x10010100;
1269 state->config = ((width + 31)/32)
1270 | (((pixelDepth > 2) ? 3 : pixelDepth) << 8)
1272 state->general = 0x00100100;
1273 state->repaint1 = hDisplaySize < 1280 ? 0x06 : 0x02;
1276 nv4UpdateArbitrationSettings(VClk,
1278 &(state->arbitration0),
1279 &(state->arbitration1),
1281 state->cursor0 = 0x00;
1282 state->cursor1 = 0xFC;
1283 state->cursor2 = 0x00000000;
1284 state->pllsel = 0x10000700;
1285 state->config = 0x00001114;
1286 state->general = bpp == 16 ? 0x00101100 : 0x00100100;
1287 state->repaint1 = hDisplaySize < 1280 ? 0x04 : 0x00;
1292 if((chip->Chipset == NV_CHIP_IGEFORCE2) ||
1293 (chip->Chipset == NV_CHIP_0x01F0))
1295 nForceUpdateArbitrationSettings(VClk,
1297 &(state->arbitration0),
1298 &(state->arbitration1),
1301 nv10UpdateArbitrationSettings(VClk,
1303 &(state->arbitration0),
1304 &(state->arbitration1),
1307 state->cursor0 = 0x80 | (chip->CursorStart >> 17);
1308 state->cursor1 = (chip->CursorStart >> 11) << 2;
1309 state->cursor2 = chip->CursorStart >> 24;
1310 state->pllsel = 0x10000700;
1311 state->config = NV_RD32(&chip->PFB[0x00000200/4], 0);
1312 state->general = bpp == 16 ? 0x00101100 : 0x00100100;
1313 state->repaint1 = hDisplaySize < 1280 ? 0x04 : 0x00;
1317 /* Paul Richards: below if block borks things in kernel for some reason */
1318 /* Tony: Below is needed to set hardware in DirectColor */
1319 if((bpp != 8) && (chip->Architecture != NV_ARCH_03))
1320 state->general |= 0x00000030;
1322 state->vpll = (p << 16) | (n << 8) | m;
1323 state->repaint0 = (((width/8)*pixelDepth) & 0x700) >> 3;
1324 state->pixel = pixelDepth > 2 ? 3 : pixelDepth;
1332 state->pitch3 = pixelDepth * width;
1337 * Load fixed function state and pre-calculated/stored state.
1340 #define LOAD_FIXED_STATE(tbl,dev) \
1341 for (i = 0; i < sizeof(tbl##Table##dev)/8; i++) \
1342 chip->dev[tbl##Table##dev[i][0]] = tbl##Table##dev[i][1]
1343 #define LOAD_FIXED_STATE_8BPP(tbl,dev) \
1344 for (i = 0; i < sizeof(tbl##Table##dev##_8BPP)/8; i++) \
1345 chip->dev[tbl##Table##dev##_8BPP[i][0]] = tbl##Table##dev##_8BPP[i][1]
1346 #define LOAD_FIXED_STATE_15BPP(tbl,dev) \
1347 for (i = 0; i < sizeof(tbl##Table##dev##_15BPP)/8; i++) \
1348 chip->dev[tbl##Table##dev##_15BPP[i][0]] = tbl##Table##dev##_15BPP[i][1]
1349 #define LOAD_FIXED_STATE_16BPP(tbl,dev) \
1350 for (i = 0; i < sizeof(tbl##Table##dev##_16BPP)/8; i++) \
1351 chip->dev[tbl##Table##dev##_16BPP[i][0]] = tbl##Table##dev##_16BPP[i][1]
1352 #define LOAD_FIXED_STATE_32BPP(tbl,dev) \
1353 for (i = 0; i < sizeof(tbl##Table##dev##_32BPP)/8; i++) \
1354 chip->dev[tbl##Table##dev##_32BPP[i][0]] = tbl##Table##dev##_32BPP[i][1]
1357 #define LOAD_FIXED_STATE(tbl,dev) \
1358 for (i = 0; i < sizeof(tbl##Table##dev)/8; i++) \
1359 NV_WR32(&chip->dev[tbl##Table##dev[i][0]], 0, tbl##Table##dev[i][1])
1360 #define LOAD_FIXED_STATE_8BPP(tbl,dev) \
1361 for (i = 0; i < sizeof(tbl##Table##dev##_8BPP)/8; i++) \
1362 NV_WR32(&chip->dev[tbl##Table##dev##_8BPP[i][0]], 0, tbl##Table##dev##_8BPP[i][1])
1363 #define LOAD_FIXED_STATE_15BPP(tbl,dev) \
1364 for (i = 0; i < sizeof(tbl##Table##dev##_15BPP)/8; i++) \
1365 NV_WR32(&chip->dev[tbl##Table##dev##_15BPP[i][0]], 0, tbl##Table##dev##_15BPP[i][1])
1366 #define LOAD_FIXED_STATE_16BPP(tbl,dev) \
1367 for (i = 0; i < sizeof(tbl##Table##dev##_16BPP)/8; i++) \
1368 NV_WR32(&chip->dev[tbl##Table##dev##_16BPP[i][0]], 0, tbl##Table##dev##_16BPP[i][1])
1369 #define LOAD_FIXED_STATE_32BPP(tbl,dev) \
1370 for (i = 0; i < sizeof(tbl##Table##dev##_32BPP)/8; i++) \
1371 NV_WR32(&chip->dev[tbl##Table##dev##_32BPP[i][0]], 0, tbl##Table##dev##_32BPP[i][1])
1373 static void UpdateFifoState
1380 switch (chip->Architecture)
1383 LOAD_FIXED_STATE(nv4,FIFO);
1385 chip->Tri05 = (RivaTexturedTriangle05 __iomem *)&(chip->FIFO[0x0000E000/4]);
1391 * Initialize state for the RivaTriangle3D05 routines.
1393 LOAD_FIXED_STATE(nv10tri05,PGRAPH);
1394 LOAD_FIXED_STATE(nv10,FIFO);
1396 chip->Tri05 = (RivaTexturedTriangle05 __iomem *)&(chip->FIFO[0x0000E000/4]);
1400 static void LoadStateExt
1403 RIVA_HW_STATE *state
1409 * Load HW fixed function state.
1411 LOAD_FIXED_STATE(Riva,PMC);
1412 LOAD_FIXED_STATE(Riva,PTIMER);
1413 switch (chip->Architecture)
1417 * Make sure frame buffer config gets set before loading PRAMIN.
1419 NV_WR32(chip->PFB, 0x00000200, state->config);
1420 LOAD_FIXED_STATE(nv3,PFIFO);
1421 LOAD_FIXED_STATE(nv3,PRAMIN);
1422 LOAD_FIXED_STATE(nv3,PGRAPH);
1427 LOAD_FIXED_STATE_15BPP(nv3,PRAMIN);
1428 LOAD_FIXED_STATE_15BPP(nv3,PGRAPH);
1429 chip->Tri03 = (RivaTexturedTriangle03 __iomem *)&(chip->FIFO[0x0000E000/4]);
1433 LOAD_FIXED_STATE_32BPP(nv3,PRAMIN);
1434 LOAD_FIXED_STATE_32BPP(nv3,PGRAPH);
1439 LOAD_FIXED_STATE_8BPP(nv3,PRAMIN);
1440 LOAD_FIXED_STATE_8BPP(nv3,PGRAPH);
1444 for (i = 0x00000; i < 0x00800; i++)
1445 NV_WR32(&chip->PRAMIN[0x00000502 + i], 0, (i << 12) | 0x03);
1446 NV_WR32(chip->PGRAPH, 0x00000630, state->offset0);
1447 NV_WR32(chip->PGRAPH, 0x00000634, state->offset1);
1448 NV_WR32(chip->PGRAPH, 0x00000638, state->offset2);
1449 NV_WR32(chip->PGRAPH, 0x0000063C, state->offset3);
1450 NV_WR32(chip->PGRAPH, 0x00000650, state->pitch0);
1451 NV_WR32(chip->PGRAPH, 0x00000654, state->pitch1);
1452 NV_WR32(chip->PGRAPH, 0x00000658, state->pitch2);
1453 NV_WR32(chip->PGRAPH, 0x0000065C, state->pitch3);
1457 * Make sure frame buffer config gets set before loading PRAMIN.
1459 NV_WR32(chip->PFB, 0x00000200, state->config);
1460 LOAD_FIXED_STATE(nv4,PFIFO);
1461 LOAD_FIXED_STATE(nv4,PRAMIN);
1462 LOAD_FIXED_STATE(nv4,PGRAPH);
1466 LOAD_FIXED_STATE_15BPP(nv4,PRAMIN);
1467 LOAD_FIXED_STATE_15BPP(nv4,PGRAPH);
1468 chip->Tri03 = (RivaTexturedTriangle03 __iomem *)&(chip->FIFO[0x0000E000/4]);
1471 LOAD_FIXED_STATE_16BPP(nv4,PRAMIN);
1472 LOAD_FIXED_STATE_16BPP(nv4,PGRAPH);
1473 chip->Tri03 = (RivaTexturedTriangle03 __iomem *)&(chip->FIFO[0x0000E000/4]);
1477 LOAD_FIXED_STATE_32BPP(nv4,PRAMIN);
1478 LOAD_FIXED_STATE_32BPP(nv4,PGRAPH);
1483 LOAD_FIXED_STATE_8BPP(nv4,PRAMIN);
1484 LOAD_FIXED_STATE_8BPP(nv4,PGRAPH);
1488 NV_WR32(chip->PGRAPH, 0x00000640, state->offset0);
1489 NV_WR32(chip->PGRAPH, 0x00000644, state->offset1);
1490 NV_WR32(chip->PGRAPH, 0x00000648, state->offset2);
1491 NV_WR32(chip->PGRAPH, 0x0000064C, state->offset3);
1492 NV_WR32(chip->PGRAPH, 0x00000670, state->pitch0);
1493 NV_WR32(chip->PGRAPH, 0x00000674, state->pitch1);
1494 NV_WR32(chip->PGRAPH, 0x00000678, state->pitch2);
1495 NV_WR32(chip->PGRAPH, 0x0000067C, state->pitch3);
1500 if(chip->twoHeads) {
1501 VGA_WR08(chip->PCIO, 0x03D4, 0x44);
1502 VGA_WR08(chip->PCIO, 0x03D5, state->crtcOwner);
1503 chip->LockUnlock(chip, 0);
1506 LOAD_FIXED_STATE(nv10,PFIFO);
1507 LOAD_FIXED_STATE(nv10,PRAMIN);
1508 LOAD_FIXED_STATE(nv10,PGRAPH);
1512 LOAD_FIXED_STATE_15BPP(nv10,PRAMIN);
1513 LOAD_FIXED_STATE_15BPP(nv10,PGRAPH);
1514 chip->Tri03 = (RivaTexturedTriangle03 __iomem *)&(chip->FIFO[0x0000E000/4]);
1517 LOAD_FIXED_STATE_16BPP(nv10,PRAMIN);
1518 LOAD_FIXED_STATE_16BPP(nv10,PGRAPH);
1519 chip->Tri03 = (RivaTexturedTriangle03 __iomem *)&(chip->FIFO[0x0000E000/4]);
1523 LOAD_FIXED_STATE_32BPP(nv10,PRAMIN);
1524 LOAD_FIXED_STATE_32BPP(nv10,PGRAPH);
1529 LOAD_FIXED_STATE_8BPP(nv10,PRAMIN);
1530 LOAD_FIXED_STATE_8BPP(nv10,PGRAPH);
1535 if(chip->Architecture == NV_ARCH_10) {
1536 NV_WR32(chip->PGRAPH, 0x00000640, state->offset0);
1537 NV_WR32(chip->PGRAPH, 0x00000644, state->offset1);
1538 NV_WR32(chip->PGRAPH, 0x00000648, state->offset2);
1539 NV_WR32(chip->PGRAPH, 0x0000064C, state->offset3);
1540 NV_WR32(chip->PGRAPH, 0x00000670, state->pitch0);
1541 NV_WR32(chip->PGRAPH, 0x00000674, state->pitch1);
1542 NV_WR32(chip->PGRAPH, 0x00000678, state->pitch2);
1543 NV_WR32(chip->PGRAPH, 0x0000067C, state->pitch3);
1544 NV_WR32(chip->PGRAPH, 0x00000680, state->pitch3);
1546 NV_WR32(chip->PGRAPH, 0x00000820, state->offset0);
1547 NV_WR32(chip->PGRAPH, 0x00000824, state->offset1);
1548 NV_WR32(chip->PGRAPH, 0x00000828, state->offset2);
1549 NV_WR32(chip->PGRAPH, 0x0000082C, state->offset3);
1550 NV_WR32(chip->PGRAPH, 0x00000850, state->pitch0);
1551 NV_WR32(chip->PGRAPH, 0x00000854, state->pitch1);
1552 NV_WR32(chip->PGRAPH, 0x00000858, state->pitch2);
1553 NV_WR32(chip->PGRAPH, 0x0000085C, state->pitch3);
1554 NV_WR32(chip->PGRAPH, 0x00000860, state->pitch3);
1555 NV_WR32(chip->PGRAPH, 0x00000864, state->pitch3);
1556 NV_WR32(chip->PGRAPH, 0x000009A4, NV_RD32(chip->PFB, 0x00000200));
1557 NV_WR32(chip->PGRAPH, 0x000009A8, NV_RD32(chip->PFB, 0x00000204));
1559 if(chip->twoHeads) {
1560 NV_WR32(chip->PCRTC0, 0x00000860, state->head);
1561 NV_WR32(chip->PCRTC0, 0x00002860, state->head2);
1563 NV_WR32(chip->PRAMDAC, 0x00000404, NV_RD32(chip->PRAMDAC, 0x00000404) | (1 << 25));
1565 NV_WR32(chip->PMC, 0x00008704, 1);
1566 NV_WR32(chip->PMC, 0x00008140, 0);
1567 NV_WR32(chip->PMC, 0x00008920, 0);
1568 NV_WR32(chip->PMC, 0x00008924, 0);
1569 NV_WR32(chip->PMC, 0x00008908, 0x01ffffff);
1570 NV_WR32(chip->PMC, 0x0000890C, 0x01ffffff);
1571 NV_WR32(chip->PMC, 0x00001588, 0);
1573 NV_WR32(chip->PFB, 0x00000240, 0);
1574 NV_WR32(chip->PFB, 0x00000250, 0);
1575 NV_WR32(chip->PFB, 0x00000260, 0);
1576 NV_WR32(chip->PFB, 0x00000270, 0);
1577 NV_WR32(chip->PFB, 0x00000280, 0);
1578 NV_WR32(chip->PFB, 0x00000290, 0);
1579 NV_WR32(chip->PFB, 0x000002A0, 0);
1580 NV_WR32(chip->PFB, 0x000002B0, 0);
1582 NV_WR32(chip->PGRAPH, 0x00000B00, NV_RD32(chip->PFB, 0x00000240));
1583 NV_WR32(chip->PGRAPH, 0x00000B04, NV_RD32(chip->PFB, 0x00000244));
1584 NV_WR32(chip->PGRAPH, 0x00000B08, NV_RD32(chip->PFB, 0x00000248));
1585 NV_WR32(chip->PGRAPH, 0x00000B0C, NV_RD32(chip->PFB, 0x0000024C));
1586 NV_WR32(chip->PGRAPH, 0x00000B10, NV_RD32(chip->PFB, 0x00000250));
1587 NV_WR32(chip->PGRAPH, 0x00000B14, NV_RD32(chip->PFB, 0x00000254));
1588 NV_WR32(chip->PGRAPH, 0x00000B18, NV_RD32(chip->PFB, 0x00000258));
1589 NV_WR32(chip->PGRAPH, 0x00000B1C, NV_RD32(chip->PFB, 0x0000025C));
1590 NV_WR32(chip->PGRAPH, 0x00000B20, NV_RD32(chip->PFB, 0x00000260));
1591 NV_WR32(chip->PGRAPH, 0x00000B24, NV_RD32(chip->PFB, 0x00000264));
1592 NV_WR32(chip->PGRAPH, 0x00000B28, NV_RD32(chip->PFB, 0x00000268));
1593 NV_WR32(chip->PGRAPH, 0x00000B2C, NV_RD32(chip->PFB, 0x0000026C));
1594 NV_WR32(chip->PGRAPH, 0x00000B30, NV_RD32(chip->PFB, 0x00000270));
1595 NV_WR32(chip->PGRAPH, 0x00000B34, NV_RD32(chip->PFB, 0x00000274));
1596 NV_WR32(chip->PGRAPH, 0x00000B38, NV_RD32(chip->PFB, 0x00000278));
1597 NV_WR32(chip->PGRAPH, 0x00000B3C, NV_RD32(chip->PFB, 0x0000027C));
1598 NV_WR32(chip->PGRAPH, 0x00000B40, NV_RD32(chip->PFB, 0x00000280));
1599 NV_WR32(chip->PGRAPH, 0x00000B44, NV_RD32(chip->PFB, 0x00000284));
1600 NV_WR32(chip->PGRAPH, 0x00000B48, NV_RD32(chip->PFB, 0x00000288));
1601 NV_WR32(chip->PGRAPH, 0x00000B4C, NV_RD32(chip->PFB, 0x0000028C));
1602 NV_WR32(chip->PGRAPH, 0x00000B50, NV_RD32(chip->PFB, 0x00000290));
1603 NV_WR32(chip->PGRAPH, 0x00000B54, NV_RD32(chip->PFB, 0x00000294));
1604 NV_WR32(chip->PGRAPH, 0x00000B58, NV_RD32(chip->PFB, 0x00000298));
1605 NV_WR32(chip->PGRAPH, 0x00000B5C, NV_RD32(chip->PFB, 0x0000029C));
1606 NV_WR32(chip->PGRAPH, 0x00000B60, NV_RD32(chip->PFB, 0x000002A0));
1607 NV_WR32(chip->PGRAPH, 0x00000B64, NV_RD32(chip->PFB, 0x000002A4));
1608 NV_WR32(chip->PGRAPH, 0x00000B68, NV_RD32(chip->PFB, 0x000002A8));
1609 NV_WR32(chip->PGRAPH, 0x00000B6C, NV_RD32(chip->PFB, 0x000002AC));
1610 NV_WR32(chip->PGRAPH, 0x00000B70, NV_RD32(chip->PFB, 0x000002B0));
1611 NV_WR32(chip->PGRAPH, 0x00000B74, NV_RD32(chip->PFB, 0x000002B4));
1612 NV_WR32(chip->PGRAPH, 0x00000B78, NV_RD32(chip->PFB, 0x000002B8));
1613 NV_WR32(chip->PGRAPH, 0x00000B7C, NV_RD32(chip->PFB, 0x000002BC));
1614 NV_WR32(chip->PGRAPH, 0x00000F40, 0x10000000);
1615 NV_WR32(chip->PGRAPH, 0x00000F44, 0x00000000);
1616 NV_WR32(chip->PGRAPH, 0x00000F50, 0x00000040);
1617 NV_WR32(chip->PGRAPH, 0x00000F54, 0x00000008);
1618 NV_WR32(chip->PGRAPH, 0x00000F50, 0x00000200);
1619 for (i = 0; i < (3*16); i++)
1620 NV_WR32(chip->PGRAPH, 0x00000F54, 0x00000000);
1621 NV_WR32(chip->PGRAPH, 0x00000F50, 0x00000040);
1622 NV_WR32(chip->PGRAPH, 0x00000F54, 0x00000000);
1623 NV_WR32(chip->PGRAPH, 0x00000F50, 0x00000800);
1624 for (i = 0; i < (16*16); i++)
1625 NV_WR32(chip->PGRAPH, 0x00000F54, 0x00000000);
1626 NV_WR32(chip->PGRAPH, 0x00000F40, 0x30000000);
1627 NV_WR32(chip->PGRAPH, 0x00000F44, 0x00000004);
1628 NV_WR32(chip->PGRAPH, 0x00000F50, 0x00006400);
1629 for (i = 0; i < (59*4); i++)
1630 NV_WR32(chip->PGRAPH, 0x00000F54, 0x00000000);
1631 NV_WR32(chip->PGRAPH, 0x00000F50, 0x00006800);
1632 for (i = 0; i < (47*4); i++)
1633 NV_WR32(chip->PGRAPH, 0x00000F54, 0x00000000);
1634 NV_WR32(chip->PGRAPH, 0x00000F50, 0x00006C00);
1635 for (i = 0; i < (3*4); i++)
1636 NV_WR32(chip->PGRAPH, 0x00000F54, 0x00000000);
1637 NV_WR32(chip->PGRAPH, 0x00000F50, 0x00007000);
1638 for (i = 0; i < (19*4); i++)
1639 NV_WR32(chip->PGRAPH, 0x00000F54, 0x00000000);
1640 NV_WR32(chip->PGRAPH, 0x00000F50, 0x00007400);
1641 for (i = 0; i < (12*4); i++)
1642 NV_WR32(chip->PGRAPH, 0x00000F54, 0x00000000);
1643 NV_WR32(chip->PGRAPH, 0x00000F50, 0x00007800);
1644 for (i = 0; i < (12*4); i++)
1645 NV_WR32(chip->PGRAPH, 0x00000F54, 0x00000000);
1646 NV_WR32(chip->PGRAPH, 0x00000F50, 0x00004400);
1647 for (i = 0; i < (8*4); i++)
1648 NV_WR32(chip->PGRAPH, 0x00000F54, 0x00000000);
1649 NV_WR32(chip->PGRAPH, 0x00000F50, 0x00000000);
1650 for (i = 0; i < 16; i++)
1651 NV_WR32(chip->PGRAPH, 0x00000F54, 0x00000000);
1652 NV_WR32(chip->PGRAPH, 0x00000F50, 0x00000040);
1653 for (i = 0; i < 4; i++)
1654 NV_WR32(chip->PGRAPH, 0x00000F54, 0x00000000);
1656 NV_WR32(chip->PCRTC, 0x00000810, state->cursorConfig);
1658 if(chip->flatPanel) {
1659 if((chip->Chipset & 0x0ff0) == 0x0110) {
1660 NV_WR32(chip->PRAMDAC, 0x0528, state->dither);
1662 if((chip->Chipset & 0x0ff0) >= 0x0170) {
1663 NV_WR32(chip->PRAMDAC, 0x083C, state->dither);
1666 VGA_WR08(chip->PCIO, 0x03D4, 0x53);
1667 VGA_WR08(chip->PCIO, 0x03D5, 0);
1668 VGA_WR08(chip->PCIO, 0x03D4, 0x54);
1669 VGA_WR08(chip->PCIO, 0x03D5, 0);
1670 VGA_WR08(chip->PCIO, 0x03D4, 0x21);
1671 VGA_WR08(chip->PCIO, 0x03D5, 0xfa);
1674 VGA_WR08(chip->PCIO, 0x03D4, 0x41);
1675 VGA_WR08(chip->PCIO, 0x03D5, state->extra);
1677 LOAD_FIXED_STATE(Riva,FIFO);
1678 UpdateFifoState(chip);
1680 * Load HW mode state.
1682 VGA_WR08(chip->PCIO, 0x03D4, 0x19);
1683 VGA_WR08(chip->PCIO, 0x03D5, state->repaint0);
1684 VGA_WR08(chip->PCIO, 0x03D4, 0x1A);
1685 VGA_WR08(chip->PCIO, 0x03D5, state->repaint1);
1686 VGA_WR08(chip->PCIO, 0x03D4, 0x25);
1687 VGA_WR08(chip->PCIO, 0x03D5, state->screen);
1688 VGA_WR08(chip->PCIO, 0x03D4, 0x28);
1689 VGA_WR08(chip->PCIO, 0x03D5, state->pixel);
1690 VGA_WR08(chip->PCIO, 0x03D4, 0x2D);
1691 VGA_WR08(chip->PCIO, 0x03D5, state->horiz);
1692 VGA_WR08(chip->PCIO, 0x03D4, 0x1B);
1693 VGA_WR08(chip->PCIO, 0x03D5, state->arbitration0);
1694 VGA_WR08(chip->PCIO, 0x03D4, 0x20);
1695 VGA_WR08(chip->PCIO, 0x03D5, state->arbitration1);
1696 VGA_WR08(chip->PCIO, 0x03D4, 0x30);
1697 VGA_WR08(chip->PCIO, 0x03D5, state->cursor0);
1698 VGA_WR08(chip->PCIO, 0x03D4, 0x31);
1699 VGA_WR08(chip->PCIO, 0x03D5, state->cursor1);
1700 VGA_WR08(chip->PCIO, 0x03D4, 0x2F);
1701 VGA_WR08(chip->PCIO, 0x03D5, state->cursor2);
1702 VGA_WR08(chip->PCIO, 0x03D4, 0x39);
1703 VGA_WR08(chip->PCIO, 0x03D5, state->interlace);
1705 if(!chip->flatPanel) {
1706 NV_WR32(chip->PRAMDAC0, 0x00000508, state->vpll);
1707 NV_WR32(chip->PRAMDAC0, 0x0000050C, state->pllsel);
1709 NV_WR32(chip->PRAMDAC0, 0x00000520, state->vpll2);
1711 NV_WR32(chip->PRAMDAC, 0x00000848 , state->scale);
1713 NV_WR32(chip->PRAMDAC, 0x00000600 , state->general);
1716 * Turn off VBlank enable and reset.
1718 NV_WR32(chip->PCRTC, 0x00000140, 0);
1719 NV_WR32(chip->PCRTC, 0x00000100, chip->VBlankBit);
1721 * Set interrupt enable.
1723 NV_WR32(chip->PMC, 0x00000140, chip->EnableIRQ & 0x01);
1725 * Set current state pointer.
1727 chip->CurrentState = state;
1729 * Reset FIFO free and empty counts.
1731 chip->FifoFreeCount = 0;
1732 /* Free count from first subchannel */
1733 chip->FifoEmptyCount = NV_RD32(&chip->Rop->FifoFree, 0);
1735 static void UnloadStateExt
1738 RIVA_HW_STATE *state
1742 * Save current HW state.
1744 VGA_WR08(chip->PCIO, 0x03D4, 0x19);
1745 state->repaint0 = VGA_RD08(chip->PCIO, 0x03D5);
1746 VGA_WR08(chip->PCIO, 0x03D4, 0x1A);
1747 state->repaint1 = VGA_RD08(chip->PCIO, 0x03D5);
1748 VGA_WR08(chip->PCIO, 0x03D4, 0x25);
1749 state->screen = VGA_RD08(chip->PCIO, 0x03D5);
1750 VGA_WR08(chip->PCIO, 0x03D4, 0x28);
1751 state->pixel = VGA_RD08(chip->PCIO, 0x03D5);
1752 VGA_WR08(chip->PCIO, 0x03D4, 0x2D);
1753 state->horiz = VGA_RD08(chip->PCIO, 0x03D5);
1754 VGA_WR08(chip->PCIO, 0x03D4, 0x1B);
1755 state->arbitration0 = VGA_RD08(chip->PCIO, 0x03D5);
1756 VGA_WR08(chip->PCIO, 0x03D4, 0x20);
1757 state->arbitration1 = VGA_RD08(chip->PCIO, 0x03D5);
1758 VGA_WR08(chip->PCIO, 0x03D4, 0x30);
1759 state->cursor0 = VGA_RD08(chip->PCIO, 0x03D5);
1760 VGA_WR08(chip->PCIO, 0x03D4, 0x31);
1761 state->cursor1 = VGA_RD08(chip->PCIO, 0x03D5);
1762 VGA_WR08(chip->PCIO, 0x03D4, 0x2F);
1763 state->cursor2 = VGA_RD08(chip->PCIO, 0x03D5);
1764 VGA_WR08(chip->PCIO, 0x03D4, 0x39);
1765 state->interlace = VGA_RD08(chip->PCIO, 0x03D5);
1766 state->vpll = NV_RD32(chip->PRAMDAC0, 0x00000508);
1767 state->vpll2 = NV_RD32(chip->PRAMDAC0, 0x00000520);
1768 state->pllsel = NV_RD32(chip->PRAMDAC0, 0x0000050C);
1769 state->general = NV_RD32(chip->PRAMDAC, 0x00000600);
1770 state->scale = NV_RD32(chip->PRAMDAC, 0x00000848);
1771 state->config = NV_RD32(chip->PFB, 0x00000200);
1772 switch (chip->Architecture)
1775 state->offset0 = NV_RD32(chip->PGRAPH, 0x00000630);
1776 state->offset1 = NV_RD32(chip->PGRAPH, 0x00000634);
1777 state->offset2 = NV_RD32(chip->PGRAPH, 0x00000638);
1778 state->offset3 = NV_RD32(chip->PGRAPH, 0x0000063C);
1779 state->pitch0 = NV_RD32(chip->PGRAPH, 0x00000650);
1780 state->pitch1 = NV_RD32(chip->PGRAPH, 0x00000654);
1781 state->pitch2 = NV_RD32(chip->PGRAPH, 0x00000658);
1782 state->pitch3 = NV_RD32(chip->PGRAPH, 0x0000065C);
1785 state->offset0 = NV_RD32(chip->PGRAPH, 0x00000640);
1786 state->offset1 = NV_RD32(chip->PGRAPH, 0x00000644);
1787 state->offset2 = NV_RD32(chip->PGRAPH, 0x00000648);
1788 state->offset3 = NV_RD32(chip->PGRAPH, 0x0000064C);
1789 state->pitch0 = NV_RD32(chip->PGRAPH, 0x00000670);
1790 state->pitch1 = NV_RD32(chip->PGRAPH, 0x00000674);
1791 state->pitch2 = NV_RD32(chip->PGRAPH, 0x00000678);
1792 state->pitch3 = NV_RD32(chip->PGRAPH, 0x0000067C);
1797 state->offset0 = NV_RD32(chip->PGRAPH, 0x00000640);
1798 state->offset1 = NV_RD32(chip->PGRAPH, 0x00000644);
1799 state->offset2 = NV_RD32(chip->PGRAPH, 0x00000648);
1800 state->offset3 = NV_RD32(chip->PGRAPH, 0x0000064C);
1801 state->pitch0 = NV_RD32(chip->PGRAPH, 0x00000670);
1802 state->pitch1 = NV_RD32(chip->PGRAPH, 0x00000674);
1803 state->pitch2 = NV_RD32(chip->PGRAPH, 0x00000678);
1804 state->pitch3 = NV_RD32(chip->PGRAPH, 0x0000067C);
1805 if(chip->twoHeads) {
1806 state->head = NV_RD32(chip->PCRTC0, 0x00000860);
1807 state->head2 = NV_RD32(chip->PCRTC0, 0x00002860);
1808 VGA_WR08(chip->PCIO, 0x03D4, 0x44);
1809 state->crtcOwner = VGA_RD08(chip->PCIO, 0x03D5);
1811 VGA_WR08(chip->PCIO, 0x03D4, 0x41);
1812 state->extra = VGA_RD08(chip->PCIO, 0x03D5);
1813 state->cursorConfig = NV_RD32(chip->PCRTC, 0x00000810);
1815 if((chip->Chipset & 0x0ff0) == 0x0110) {
1816 state->dither = NV_RD32(chip->PRAMDAC, 0x0528);
1818 if((chip->Chipset & 0x0ff0) >= 0x0170) {
1819 state->dither = NV_RD32(chip->PRAMDAC, 0x083C);
1824 static void SetStartAddress
1830 NV_WR32(chip->PCRTC, 0x800, start);
1833 static void SetStartAddress3
1839 int offset = start >> 2;
1840 int pan = (start & 3) << 1;
1844 * Unlock extended registers.
1846 chip->LockUnlock(chip, 0);
1848 * Set start address.
1850 VGA_WR08(chip->PCIO, 0x3D4, 0x0D); VGA_WR08(chip->PCIO, 0x3D5, offset);
1852 VGA_WR08(chip->PCIO, 0x3D4, 0x0C); VGA_WR08(chip->PCIO, 0x3D5, offset);
1854 VGA_WR08(chip->PCIO, 0x3D4, 0x19); tmp = VGA_RD08(chip->PCIO, 0x3D5);
1855 VGA_WR08(chip->PCIO, 0x3D5, (offset & 0x01F) | (tmp & ~0x1F));
1856 VGA_WR08(chip->PCIO, 0x3D4, 0x2D); tmp = VGA_RD08(chip->PCIO, 0x3D5);
1857 VGA_WR08(chip->PCIO, 0x3D5, (offset & 0x60) | (tmp & ~0x60));
1859 * 4 pixel pan register.
1861 offset = VGA_RD08(chip->PCIO, chip->IO + 0x0A);
1862 VGA_WR08(chip->PCIO, 0x3C0, 0x13);
1863 VGA_WR08(chip->PCIO, 0x3C0, pan);
1865 static void nv3SetSurfaces2D
1872 RivaSurface __iomem *Surface =
1873 (RivaSurface __iomem *)&(chip->FIFO[0x0000E000/4]);
1875 RIVA_FIFO_FREE(*chip,Tri03,5);
1876 NV_WR32(&chip->FIFO[0x00003800], 0, 0x80000003);
1877 NV_WR32(&Surface->Offset, 0, surf0);
1878 NV_WR32(&chip->FIFO[0x00003800], 0, 0x80000004);
1879 NV_WR32(&Surface->Offset, 0, surf1);
1880 NV_WR32(&chip->FIFO[0x00003800], 0, 0x80000013);
1882 static void nv4SetSurfaces2D
1889 RivaSurface __iomem *Surface =
1890 (RivaSurface __iomem *)&(chip->FIFO[0x0000E000/4]);
1892 NV_WR32(&chip->FIFO[0x00003800], 0, 0x80000003);
1893 NV_WR32(&Surface->Offset, 0, surf0);
1894 NV_WR32(&chip->FIFO[0x00003800], 0, 0x80000004);
1895 NV_WR32(&Surface->Offset, 0, surf1);
1896 NV_WR32(&chip->FIFO[0x00003800], 0, 0x80000014);
1898 static void nv10SetSurfaces2D
1905 RivaSurface __iomem *Surface =
1906 (RivaSurface __iomem *)&(chip->FIFO[0x0000E000/4]);
1908 NV_WR32(&chip->FIFO[0x00003800], 0, 0x80000003);
1909 NV_WR32(&Surface->Offset, 0, surf0);
1910 NV_WR32(&chip->FIFO[0x00003800], 0, 0x80000004);
1911 NV_WR32(&Surface->Offset, 0, surf1);
1912 NV_WR32(&chip->FIFO[0x00003800], 0, 0x80000014);
1914 static void nv3SetSurfaces3D
1921 RivaSurface __iomem *Surface =
1922 (RivaSurface __iomem *)&(chip->FIFO[0x0000E000/4]);
1924 RIVA_FIFO_FREE(*chip,Tri03,5);
1925 NV_WR32(&chip->FIFO[0x00003800], 0, 0x80000005);
1926 NV_WR32(&Surface->Offset, 0, surf0);
1927 NV_WR32(&chip->FIFO[0x00003800], 0, 0x80000006);
1928 NV_WR32(&Surface->Offset, 0, surf1);
1929 NV_WR32(&chip->FIFO[0x00003800], 0, 0x80000013);
1931 static void nv4SetSurfaces3D
1938 RivaSurface __iomem *Surface =
1939 (RivaSurface __iomem *)&(chip->FIFO[0x0000E000/4]);
1941 NV_WR32(&chip->FIFO[0x00003800], 0, 0x80000005);
1942 NV_WR32(&Surface->Offset, 0, surf0);
1943 NV_WR32(&chip->FIFO[0x00003800], 0, 0x80000006);
1944 NV_WR32(&Surface->Offset, 0, surf1);
1945 NV_WR32(&chip->FIFO[0x00003800], 0, 0x80000014);
1947 static void nv10SetSurfaces3D
1954 RivaSurface3D __iomem *Surfaces3D =
1955 (RivaSurface3D __iomem *)&(chip->FIFO[0x0000E000/4]);
1957 RIVA_FIFO_FREE(*chip,Tri03,4);
1958 NV_WR32(&chip->FIFO[0x00003800], 0, 0x80000007);
1959 NV_WR32(&Surfaces3D->RenderBufferOffset, 0, surf0);
1960 NV_WR32(&Surfaces3D->ZBufferOffset, 0, surf1);
1961 NV_WR32(&chip->FIFO[0x00003800], 0, 0x80000014);
1964 /****************************************************************************\
1966 * Probe RIVA Chip Configuration *
1968 \****************************************************************************/
1970 static void nv3GetConfig
1976 * Fill in chip configuration.
1978 if (NV_RD32(&chip->PFB[0x00000000/4], 0) & 0x00000020)
1980 if (((NV_RD32(chip->PMC, 0x00000000) & 0xF0) == 0x20)
1981 && ((NV_RD32(chip->PMC, 0x00000000) & 0x0F) >= 0x02))
1986 chip->RamBandwidthKBytesPerSec = 800000;
1987 switch (NV_RD32(chip->PFB, 0x00000000) & 0x03)
1990 chip->RamAmountKBytes = 1024 * 4;
1993 chip->RamAmountKBytes = 1024 * 2;
1996 chip->RamAmountKBytes = 1024 * 8;
2002 chip->RamBandwidthKBytesPerSec = 1000000;
2003 chip->RamAmountKBytes = 1024 * 8;
2011 chip->RamBandwidthKBytesPerSec = 1000000;
2012 switch (NV_RD32(chip->PFB, 0x00000000) & 0x00000003)
2015 chip->RamAmountKBytes = 1024 * 8;
2018 chip->RamAmountKBytes = 1024 * 4;
2021 chip->RamAmountKBytes = 1024 * 2;
2025 chip->CrystalFreqKHz = (NV_RD32(chip->PEXTDEV, 0x00000000) & 0x00000040) ? 14318 : 13500;
2026 chip->CURSOR = &(chip->PRAMIN[0x00008000/4 - 0x0800/4]);
2027 chip->VBlankBit = 0x00000100;
2028 chip->MaxVClockFreqKHz = 256000;
2030 * Set chip functions.
2032 chip->Busy = nv3Busy;
2033 chip->ShowHideCursor = ShowHideCursor;
2034 chip->LoadStateExt = LoadStateExt;
2035 chip->UnloadStateExt = UnloadStateExt;
2036 chip->SetStartAddress = SetStartAddress3;
2037 chip->SetSurfaces2D = nv3SetSurfaces2D;
2038 chip->SetSurfaces3D = nv3SetSurfaces3D;
2039 chip->LockUnlock = nv3LockUnlock;
2041 static void nv4GetConfig
2047 * Fill in chip configuration.
2049 if (NV_RD32(chip->PFB, 0x00000000) & 0x00000100)
2051 chip->RamAmountKBytes = ((NV_RD32(chip->PFB, 0x00000000) >> 12) & 0x0F) * 1024 * 2
2056 switch (NV_RD32(chip->PFB, 0x00000000) & 0x00000003)
2059 chip->RamAmountKBytes = 1024 * 32;
2062 chip->RamAmountKBytes = 1024 * 4;
2065 chip->RamAmountKBytes = 1024 * 8;
2069 chip->RamAmountKBytes = 1024 * 16;
2073 switch ((NV_RD32(chip->PFB, 0x00000000) >> 3) & 0x00000003)
2076 chip->RamBandwidthKBytesPerSec = 800000;
2079 chip->RamBandwidthKBytesPerSec = 1000000;
2082 chip->CrystalFreqKHz = (NV_RD32(chip->PEXTDEV, 0x00000000) & 0x00000040) ? 14318 : 13500;
2083 chip->CURSOR = &(chip->PRAMIN[0x00010000/4 - 0x0800/4]);
2084 chip->VBlankBit = 0x00000001;
2085 chip->MaxVClockFreqKHz = 350000;
2087 * Set chip functions.
2089 chip->Busy = nv4Busy;
2090 chip->ShowHideCursor = ShowHideCursor;
2091 chip->LoadStateExt = LoadStateExt;
2092 chip->UnloadStateExt = UnloadStateExt;
2093 chip->SetStartAddress = SetStartAddress;
2094 chip->SetSurfaces2D = nv4SetSurfaces2D;
2095 chip->SetSurfaces3D = nv4SetSurfaces3D;
2096 chip->LockUnlock = nv4LockUnlock;
2098 static void nv10GetConfig
2101 unsigned int chipset
2104 struct pci_dev* dev;
2108 /* turn on big endian register access */
2109 if(!(NV_RD32(chip->PMC, 0x00000004) & 0x01000001))
2110 NV_WR32(chip->PMC, 0x00000004, 0x01000001);
2114 * Fill in chip configuration.
2116 if(chipset == NV_CHIP_IGEFORCE2) {
2117 dev = pci_get_bus_and_slot(0, 1);
2118 pci_read_config_dword(dev, 0x7C, &amt);
2120 chip->RamAmountKBytes = (((amt >> 6) & 31) + 1) * 1024;
2121 } else if(chipset == NV_CHIP_0x01F0) {
2122 dev = pci_get_bus_and_slot(0, 1);
2123 pci_read_config_dword(dev, 0x84, &amt);
2125 chip->RamAmountKBytes = (((amt >> 4) & 127) + 1) * 1024;
2127 switch ((NV_RD32(chip->PFB, 0x0000020C) >> 20) & 0x000000FF)
2130 chip->RamAmountKBytes = 1024 * 2;
2133 chip->RamAmountKBytes = 1024 * 4;
2136 chip->RamAmountKBytes = 1024 * 8;
2139 chip->RamAmountKBytes = 1024 * 16;
2142 chip->RamAmountKBytes = 1024 * 32;
2145 chip->RamAmountKBytes = 1024 * 64;
2148 chip->RamAmountKBytes = 1024 * 128;
2151 chip->RamAmountKBytes = 1024 * 16;
2155 switch ((NV_RD32(chip->PFB, 0x00000000) >> 3) & 0x00000003)
2158 chip->RamBandwidthKBytesPerSec = 800000;
2161 chip->RamBandwidthKBytesPerSec = 1000000;
2164 chip->CrystalFreqKHz = (NV_RD32(chip->PEXTDEV, 0x0000) & (1 << 6)) ?
2167 switch (chipset & 0x0ff0) {
2178 if(NV_RD32(chip->PEXTDEV, 0x0000) & (1 << 22))
2179 chip->CrystalFreqKHz = 27000;
2185 chip->CursorStart = (chip->RamAmountKBytes - 128) * 1024;
2186 chip->CURSOR = NULL; /* can't set this here */
2187 chip->VBlankBit = 0x00000001;
2188 chip->MaxVClockFreqKHz = 350000;
2190 * Set chip functions.
2192 chip->Busy = nv10Busy;
2193 chip->ShowHideCursor = ShowHideCursor;
2194 chip->LoadStateExt = LoadStateExt;
2195 chip->UnloadStateExt = UnloadStateExt;
2196 chip->SetStartAddress = SetStartAddress;
2197 chip->SetSurfaces2D = nv10SetSurfaces2D;
2198 chip->SetSurfaces3D = nv10SetSurfaces3D;
2199 chip->LockUnlock = nv4LockUnlock;
2201 switch(chipset & 0x0ff0) {
2213 chip->twoHeads = TRUE;
2216 chip->twoHeads = FALSE;
2223 unsigned int chipset
2227 * Save this so future SW know whats it's dealing with.
2229 chip->Version = RIVA_SW_VERSION;
2231 * Chip specific configuration.
2233 switch (chip->Architecture)
2244 nv10GetConfig(chip, chipset);
2249 chip->Chipset = chipset;
2251 * Fill in FIFO pointers.
2253 chip->Rop = (RivaRop __iomem *)&(chip->FIFO[0x00000000/4]);
2254 chip->Clip = (RivaClip __iomem *)&(chip->FIFO[0x00002000/4]);
2255 chip->Patt = (RivaPattern __iomem *)&(chip->FIFO[0x00004000/4]);
2256 chip->Pixmap = (RivaPixmap __iomem *)&(chip->FIFO[0x00006000/4]);
2257 chip->Blt = (RivaScreenBlt __iomem *)&(chip->FIFO[0x00008000/4]);
2258 chip->Bitmap = (RivaBitmap __iomem *)&(chip->FIFO[0x0000A000/4]);
2259 chip->Line = (RivaLine __iomem *)&(chip->FIFO[0x0000C000/4]);
2260 chip->Tri03 = (RivaTexturedTriangle03 __iomem *)&(chip->FIFO[0x0000E000/4]);