riva_hw.c
上传用户:lgb322
上传日期:2013-02-24
资源大小:30529k
文件大小:68k
源码类别:

嵌入式Linux

开发平台:

Unix_Linux

  1.  /***************************************************************************
  2. |*                                                                           *|
  3. |*       Copyright 1993-1999 NVIDIA, Corporation.  All rights reserved.      *|
  4. |*                                                                           *|
  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.                  *|
  9. |*                                                                           *|
  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     *|
  12. |*     as follows:                                                           *|
  13. |*                                                                           *|
  14. |*       Copyright 1993-1999 NVIDIA, Corporation.  All rights reserved.      *|
  15. |*                                                                           *|
  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.     *|
  27. |*                                                                           *|
  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.                                        *|
  37. |*                                                                           *|
  38.  ***************************************************************************/
  39. /*
  40.  * GPL licensing note -- nVidia is allowing a liberal interpretation of
  41.  * the documentation restriction above, to merely say that this nVidia's
  42.  * copyright and disclaimer should be included with all code derived
  43.  * from this source.  -- Jeff Garzik <jgarzik@mandrakesoft.com>, 01/Nov/99 
  44.  */
  45. /* $XFree86: xc/programs/Xserver/hw/xfree86/drivers/nv/riva_hw.c,v 1.8 2000/02/08 17:19:11 dawes Exp $ */
  46. #include "riva_hw.h"
  47. #include "riva_tbl.h"
  48. /*
  49.  * This file is an OS-agnostic file used to make RIVA 128 and RIVA TNT
  50.  * operate identically (except TNT has more memory and better 3D quality.
  51.  */
  52. static int nv3Busy
  53. (
  54.     RIVA_HW_INST *chip
  55. )
  56. {
  57.     return ((chip->Rop->FifoFree < chip->FifoEmptyCount) || (chip->PGRAPH[0x000006B0/4] & 0x01));
  58. }
  59. static int nv4Busy
  60. (
  61.     RIVA_HW_INST *chip
  62. )
  63. {
  64.     return ((chip->Rop->FifoFree < chip->FifoEmptyCount) || (chip->PGRAPH[0x00000700/4] & 0x01));
  65. }
  66. static int nv10Busy
  67. (
  68.     RIVA_HW_INST *chip
  69. )
  70. {
  71.     return ((chip->Rop->FifoFree < chip->FifoEmptyCount) || (chip->PGRAPH[0x00000700/4] & 0x01));
  72. }
  73. static void nv3LockUnlock
  74. (
  75.     RIVA_HW_INST *chip,
  76.     int           LockUnlock
  77. )
  78. {
  79.     VGA_WR08(chip->PVIO, 0x3C4, 0x06);
  80.     VGA_WR08(chip->PVIO, 0x3C5, LockUnlock ? 0x99 : 0x57);
  81. }
  82. static void nv4LockUnlock
  83. (
  84.     RIVA_HW_INST *chip,
  85.     int           LockUnlock
  86. )
  87. {
  88.     VGA_WR08(chip->PCIO, 0x3D4, 0x1F);
  89.     VGA_WR08(chip->PCIO, 0x3D5, LockUnlock ? 0x99 : 0x57);
  90. }
  91. static void nv10LockUnlock
  92. (
  93.     RIVA_HW_INST *chip,
  94.     int           LockUnlock
  95. )
  96. {
  97.     VGA_WR08(chip->PCIO, 0x3D4, 0x1F);
  98.     VGA_WR08(chip->PCIO, 0x3D5, LockUnlock ? 0x99 : 0x57);
  99. }
  100. static int ShowHideCursor
  101. (
  102.     RIVA_HW_INST *chip,
  103.     int           ShowHide
  104. )
  105. {
  106.     int current;
  107.     current                     =  chip->CurrentState->cursor1;
  108.     chip->CurrentState->cursor1 = (chip->CurrentState->cursor1 & 0xFE) |
  109.                           (ShowHide & 0x01);
  110.     VGA_WR08(chip->PCIO, 0x3D4, 0x31);
  111.     VGA_WR08(chip->PCIO, 0x3D5, chip->CurrentState->cursor1);
  112.     return (current & 0x01);
  113. }
  114. /****************************************************************************
  115. *                                                                            *
  116. * The video arbitration routines calculate some "magic" numbers.  Fixes      *
  117. * the snow seen when accessing the framebuffer without it.                   *
  118. * It just works (I hope).                                                    *
  119. *                                                                            *
  120. ****************************************************************************/
  121. #define DEFAULT_GR_LWM 100
  122. #define DEFAULT_VID_LWM 100
  123. #define DEFAULT_GR_BURST_SIZE 256
  124. #define DEFAULT_VID_BURST_SIZE 128
  125. #define VIDEO 0
  126. #define GRAPHICS 1
  127. #define MPORT 2
  128. #define ENGINE 3
  129. #define GFIFO_SIZE 320
  130. #define GFIFO_SIZE_128 256
  131. #define MFIFO_SIZE 120
  132. #define VFIFO_SIZE 256
  133. #define ABS(a) (a>0?a:-a)
  134. typedef struct {
  135.   int gdrain_rate;
  136.   int vdrain_rate;
  137.   int mdrain_rate;
  138.   int gburst_size;
  139.   int vburst_size;
  140.   char vid_en;
  141.   char gr_en;
  142.   int wcmocc, wcgocc, wcvocc, wcvlwm, wcglwm;
  143.   int by_gfacc;
  144.   char vid_only_once;
  145.   char gr_only_once;
  146.   char first_vacc;
  147.   char first_gacc;
  148.   char first_macc;
  149.   int vocc;
  150.   int gocc;
  151.   int mocc;
  152.   char cur;
  153.   char engine_en;
  154.   char converged;
  155.   int priority;
  156. } nv3_arb_info;
  157. typedef struct {
  158.   int graphics_lwm;
  159.   int video_lwm;
  160.   int graphics_burst_size;
  161.   int video_burst_size;
  162.   int graphics_hi_priority;
  163.   int media_hi_priority;
  164.   int rtl_values;
  165.   int valid;
  166. } nv3_fifo_info;
  167. typedef struct {
  168.   char pix_bpp;
  169.   char enable_video;
  170.   char gr_during_vid;
  171.   char enable_mp;
  172.   int memory_width;
  173.   int video_scale;
  174.   int pclk_khz;
  175.   int mclk_khz;
  176.   int mem_page_miss;
  177.   int mem_latency;
  178.   char mem_aligned;
  179. } nv3_sim_state;
  180. typedef struct {
  181.   int graphics_lwm;
  182.   int video_lwm;
  183.   int graphics_burst_size;
  184.   int video_burst_size;
  185.   int valid;
  186. } nv4_fifo_info;
  187. typedef struct {
  188.   int pclk_khz;
  189.   int mclk_khz;
  190.   int nvclk_khz;
  191.   char mem_page_miss;
  192.   char mem_latency;
  193.   int memory_width;
  194.   char enable_video;
  195.   char gr_during_vid;
  196.   char pix_bpp;
  197.   char mem_aligned;
  198.   char enable_mp;
  199. } nv4_sim_state;
  200. typedef struct {
  201.   int graphics_lwm;
  202.   int video_lwm;
  203.   int graphics_burst_size;
  204.   int video_burst_size;
  205.   int valid;
  206. } nv10_fifo_info;
  207. typedef struct {
  208.   int pclk_khz;
  209.   int mclk_khz;
  210.   int nvclk_khz;
  211.   char mem_page_miss;
  212.   char mem_latency;
  213.   int memory_type;
  214.   int memory_width;
  215.   char enable_video;
  216.   char gr_during_vid;
  217.   char pix_bpp;
  218.   char mem_aligned;
  219.   char enable_mp;
  220. } nv10_sim_state;
  221. static int nv3_iterate(nv3_fifo_info *res_info, nv3_sim_state * state, nv3_arb_info *ainfo)
  222. {
  223.     int iter = 0;
  224.     int tmp;
  225.     int vfsize, mfsize, gfsize;
  226.     int mburst_size = 32;
  227.     int mmisses, gmisses, vmisses;
  228.     int misses;
  229.     int vlwm, glwm, mlwm;
  230.     int last, next, cur;
  231.     int max_gfsize ;
  232.     long ns;
  233.     vlwm = 0;
  234.     glwm = 0;
  235.     mlwm = 0;
  236.     vfsize = 0;
  237.     gfsize = 0;
  238.     cur = ainfo->cur;
  239.     mmisses = 2;
  240.     gmisses = 2;
  241.     vmisses = 2;
  242.     if (ainfo->gburst_size == 128) max_gfsize = GFIFO_SIZE_128;
  243.     else  max_gfsize = GFIFO_SIZE;
  244.     max_gfsize = GFIFO_SIZE;
  245.     while (1)
  246.     {
  247.         if (ainfo->vid_en)
  248.         {
  249.             if (ainfo->wcvocc > ainfo->vocc) ainfo->wcvocc = ainfo->vocc;
  250.             if (ainfo->wcvlwm > vlwm) ainfo->wcvlwm = vlwm ;
  251.             ns = 1000000 * ainfo->vburst_size/(state->memory_width/8)/state->mclk_khz;
  252.             vfsize = ns * ainfo->vdrain_rate / 1000000;
  253.             vfsize =  ainfo->wcvlwm - ainfo->vburst_size + vfsize;
  254.         }
  255.         if (state->enable_mp)
  256.         {
  257.             if (ainfo->wcmocc > ainfo->mocc) ainfo->wcmocc = ainfo->mocc;
  258.         }
  259.         if (ainfo->gr_en)
  260.         {
  261.             if (ainfo->wcglwm > glwm) ainfo->wcglwm = glwm ;
  262.             if (ainfo->wcgocc > ainfo->gocc) ainfo->wcgocc = ainfo->gocc;
  263.             ns = 1000000 * (ainfo->gburst_size/(state->memory_width/8))/state->mclk_khz;
  264.             gfsize = (ns * (long) ainfo->gdrain_rate)/1000000;
  265.             gfsize = ainfo->wcglwm - ainfo->gburst_size + gfsize;
  266.         }
  267.         mfsize = 0;
  268.         if (!state->gr_during_vid && ainfo->vid_en)
  269.             if (ainfo->vid_en && (ainfo->vocc < 0) && !ainfo->vid_only_once)
  270.                 next = VIDEO;
  271.             else if (ainfo->mocc < 0)
  272.                 next = MPORT;
  273.             else if (ainfo->gocc< ainfo->by_gfacc)
  274.                 next = GRAPHICS;
  275.             else return (0);
  276.         else switch (ainfo->priority)
  277.             {
  278.                 case VIDEO:
  279.                     if (ainfo->vid_en && ainfo->vocc<0 && !ainfo->vid_only_once)
  280.                         next = VIDEO;
  281.                     else if (ainfo->gr_en && ainfo->gocc<0 && !ainfo->gr_only_once)
  282.                         next = GRAPHICS;
  283.                     else if (ainfo->mocc<0)
  284.                         next = MPORT;
  285.                     else    return (0);
  286.                     break;
  287.                 case GRAPHICS:
  288.                     if (ainfo->gr_en && ainfo->gocc<0 && !ainfo->gr_only_once)
  289.                         next = GRAPHICS;
  290.                     else if (ainfo->vid_en && ainfo->vocc<0 && !ainfo->vid_only_once)
  291.                         next = VIDEO;
  292.                     else if (ainfo->mocc<0)
  293.                         next = MPORT;
  294.                     else    return (0);
  295.                     break;
  296.                 default:
  297.                     if (ainfo->mocc<0)
  298.                         next = MPORT;
  299.                     else if (ainfo->gr_en && ainfo->gocc<0 && !ainfo->gr_only_once)
  300.                         next = GRAPHICS;
  301.                     else if (ainfo->vid_en && ainfo->vocc<0 && !ainfo->vid_only_once)
  302.                         next = VIDEO;
  303.                     else    return (0);
  304.                     break;
  305.             }
  306.         last = cur;
  307.         cur = next;
  308.         iter++;
  309.         switch (cur)
  310.         {
  311.             case VIDEO:
  312.                 if (last==cur)    misses = 0;
  313.                 else if (ainfo->first_vacc)   misses = vmisses;
  314.                 else    misses = 1;
  315.                 ainfo->first_vacc = 0;
  316.                 if (last!=cur)
  317.                 {
  318.                     ns =  1000000 * (vmisses*state->mem_page_miss + state->mem_latency)/state->mclk_khz; 
  319.                     vlwm = ns * ainfo->vdrain_rate/ 1000000;
  320.                     vlwm = ainfo->vocc - vlwm;
  321.                 }
  322.                 ns = 1000000*(misses*state->mem_page_miss + ainfo->vburst_size)/(state->memory_width/8)/state->mclk_khz;
  323.                 ainfo->vocc = ainfo->vocc + ainfo->vburst_size - ns*ainfo->vdrain_rate/1000000;
  324.                 ainfo->gocc = ainfo->gocc - ns*ainfo->gdrain_rate/1000000;
  325.                 ainfo->mocc = ainfo->mocc - ns*ainfo->mdrain_rate/1000000;
  326.                 break;
  327.             case GRAPHICS:
  328.                 if (last==cur)    misses = 0;
  329.                 else if (ainfo->first_gacc)   misses = gmisses;
  330.                 else    misses = 1;
  331.                 ainfo->first_gacc = 0;
  332.                 if (last!=cur)
  333.                 {
  334.                     ns = 1000000*(gmisses*state->mem_page_miss + state->mem_latency)/state->mclk_khz ;
  335.                     glwm = ns * ainfo->gdrain_rate/1000000;
  336.                     glwm = ainfo->gocc - glwm;
  337.                 }
  338.                 ns = 1000000*(misses*state->mem_page_miss + ainfo->gburst_size/(state->memory_width/8))/state->mclk_khz;
  339.                 ainfo->vocc = ainfo->vocc + 0 - ns*ainfo->vdrain_rate/1000000;
  340.                 ainfo->gocc = ainfo->gocc + ainfo->gburst_size - ns*ainfo->gdrain_rate/1000000;
  341.                 ainfo->mocc = ainfo->mocc + 0 - ns*ainfo->mdrain_rate/1000000;
  342.                 break;
  343.             default:
  344.                 if (last==cur)    misses = 0;
  345.                 else if (ainfo->first_macc)   misses = mmisses;
  346.                 else    misses = 1;
  347.                 ainfo->first_macc = 0;
  348.                 ns = 1000000*(misses*state->mem_page_miss + mburst_size/(state->memory_width/8))/state->mclk_khz;
  349.                 ainfo->vocc = ainfo->vocc + 0 - ns*ainfo->vdrain_rate/1000000;
  350.                 ainfo->gocc = ainfo->gocc + 0 - ns*ainfo->gdrain_rate/1000000;
  351.                 ainfo->mocc = ainfo->mocc + mburst_size - ns*ainfo->mdrain_rate/1000000;
  352.                 break;
  353.         }
  354.         if (iter>100)
  355.         {
  356.             ainfo->converged = 0;
  357.             return (1);
  358.         }
  359.         ns = 1000000*ainfo->gburst_size/(state->memory_width/8)/state->mclk_khz;
  360.         tmp = ns * ainfo->gdrain_rate/1000000;
  361.         if (ABS(ainfo->gburst_size) + ((ABS(ainfo->wcglwm) + 16 ) & ~0x7) - tmp > max_gfsize)
  362.         {
  363.             ainfo->converged = 0;
  364.             return (1);
  365.         }
  366.         ns = 1000000*ainfo->vburst_size/(state->memory_width/8)/state->mclk_khz;
  367.         tmp = ns * ainfo->vdrain_rate/1000000;
  368.         if (ABS(ainfo->vburst_size) + (ABS(ainfo->wcvlwm + 32) & ~0xf)  - tmp> VFIFO_SIZE)
  369.         {
  370.             ainfo->converged = 0;
  371.             return (1);
  372.         }
  373.         if (ABS(ainfo->gocc) > max_gfsize)
  374.         {
  375.             ainfo->converged = 0;
  376.             return (1);
  377.         }
  378.         if (ABS(ainfo->vocc) > VFIFO_SIZE)
  379.         {
  380.             ainfo->converged = 0;
  381.             return (1);
  382.         }
  383.         if (ABS(ainfo->mocc) > MFIFO_SIZE)
  384.         {
  385.             ainfo->converged = 0;
  386.             return (1);
  387.         }
  388.         if (ABS(vfsize) > VFIFO_SIZE)
  389.         {
  390.             ainfo->converged = 0;
  391.             return (1);
  392.         }
  393.         if (ABS(gfsize) > max_gfsize)
  394.         {
  395.             ainfo->converged = 0;
  396.             return (1);
  397.         }
  398.         if (ABS(mfsize) > MFIFO_SIZE)
  399.         {
  400.             ainfo->converged = 0;
  401.             return (1);
  402.         }
  403.     }
  404. }
  405. static char nv3_arb(nv3_fifo_info * res_info, nv3_sim_state * state,  nv3_arb_info *ainfo) 
  406. {
  407.     long ens, vns, mns, gns;
  408.     int mmisses, gmisses, vmisses, eburst_size, mburst_size;
  409.     int refresh_cycle;
  410.     refresh_cycle = 0;
  411.     refresh_cycle = 2*(state->mclk_khz/state->pclk_khz) + 5;
  412.     mmisses = 2;
  413.     if (state->mem_aligned) gmisses = 2;
  414.     else    gmisses = 3;
  415.     vmisses = 2;
  416.     eburst_size = state->memory_width * 1;
  417.     mburst_size = 32;
  418.     gns = 1000000 * (gmisses*state->mem_page_miss + state->mem_latency)/state->mclk_khz;
  419.     ainfo->by_gfacc = gns*ainfo->gdrain_rate/1000000;
  420.     ainfo->wcmocc = 0;
  421.     ainfo->wcgocc = 0;
  422.     ainfo->wcvocc = 0;
  423.     ainfo->wcvlwm = 0;
  424.     ainfo->wcglwm = 0;
  425.     ainfo->engine_en = 1;
  426.     ainfo->converged = 1;
  427.     if (ainfo->engine_en)
  428.     {
  429.         ens =  1000000*(state->mem_page_miss + eburst_size/(state->memory_width/8) +refresh_cycle)/state->mclk_khz;
  430.         ainfo->mocc = state->enable_mp ? 0-ens*ainfo->mdrain_rate/1000000 : 0;
  431.         ainfo->vocc = ainfo->vid_en ? 0-ens*ainfo->vdrain_rate/1000000 : 0;
  432.         ainfo->gocc = ainfo->gr_en ? 0-ens*ainfo->gdrain_rate/1000000 : 0;
  433.         ainfo->cur = ENGINE;
  434.         ainfo->first_vacc = 1;
  435.         ainfo->first_gacc = 1;
  436.         ainfo->first_macc = 1;
  437.         nv3_iterate(res_info, state,ainfo);
  438.     }
  439.     if (state->enable_mp)
  440.     {
  441.         mns = 1000000 * (mmisses*state->mem_page_miss + mburst_size/(state->memory_width/8) + refresh_cycle)/state->mclk_khz;
  442.         ainfo->mocc = state->enable_mp ? 0 : mburst_size - mns*ainfo->mdrain_rate/1000000;
  443.         ainfo->vocc = ainfo->vid_en ? 0 : 0- mns*ainfo->vdrain_rate/1000000;
  444.         ainfo->gocc = ainfo->gr_en ? 0: 0- mns*ainfo->gdrain_rate/1000000;
  445.         ainfo->cur = MPORT;
  446.         ainfo->first_vacc = 1;
  447.         ainfo->first_gacc = 1;
  448.         ainfo->first_macc = 0;
  449.         nv3_iterate(res_info, state,ainfo);
  450.     }
  451.     if (ainfo->gr_en)
  452.     {
  453.         ainfo->first_vacc = 1;
  454.         ainfo->first_gacc = 0;
  455.         ainfo->first_macc = 1;
  456.         gns = 1000000*(gmisses*state->mem_page_miss + ainfo->gburst_size/(state->memory_width/8) + refresh_cycle)/state->mclk_khz;
  457.         ainfo->gocc = ainfo->gburst_size - gns*ainfo->gdrain_rate/1000000;
  458.         ainfo->vocc = ainfo->vid_en? 0-gns*ainfo->vdrain_rate/1000000 : 0;
  459.         ainfo->mocc = state->enable_mp ?  0-gns*ainfo->mdrain_rate/1000000: 0;
  460.         ainfo->cur = GRAPHICS;
  461.         nv3_iterate(res_info, state,ainfo);
  462.     }
  463.     if (ainfo->vid_en)
  464.     {
  465.         ainfo->first_vacc = 0;
  466.         ainfo->first_gacc = 1;
  467.         ainfo->first_macc = 1;
  468.         vns = 1000000*(vmisses*state->mem_page_miss + ainfo->vburst_size/(state->memory_width/8) + refresh_cycle)/state->mclk_khz;
  469.         ainfo->vocc = ainfo->vburst_size - vns*ainfo->vdrain_rate/1000000;
  470.         ainfo->gocc = ainfo->gr_en? (0-vns*ainfo->gdrain_rate/1000000) : 0;
  471.         ainfo->mocc = state->enable_mp? 0-vns*ainfo->mdrain_rate/1000000 :0 ;
  472.         ainfo->cur = VIDEO;
  473.         nv3_iterate(res_info, state, ainfo);
  474.     }
  475.     if (ainfo->converged)
  476.     {
  477.         res_info->graphics_lwm = (int)ABS(ainfo->wcglwm) + 16;
  478.         res_info->video_lwm = (int)ABS(ainfo->wcvlwm) + 32;
  479.         res_info->graphics_burst_size = ainfo->gburst_size;
  480.         res_info->video_burst_size = ainfo->vburst_size;
  481.         res_info->graphics_hi_priority = (ainfo->priority == GRAPHICS);
  482.         res_info->media_hi_priority = (ainfo->priority == MPORT);
  483.         if (res_info->video_lwm > 160)
  484.         {
  485.             res_info->graphics_lwm = 256;
  486.             res_info->video_lwm = 128;
  487.             res_info->graphics_burst_size = 64;
  488.             res_info->video_burst_size = 64;
  489.             res_info->graphics_hi_priority = 0;
  490.             res_info->media_hi_priority = 0;
  491.             ainfo->converged = 0;
  492.             return (0);
  493.         }
  494.         if (res_info->video_lwm > 128)
  495.         {
  496.             res_info->video_lwm = 128;
  497.         }
  498.         return (1);
  499.     }
  500.     else
  501.     {
  502.         res_info->graphics_lwm = 256;
  503.         res_info->video_lwm = 128;
  504.         res_info->graphics_burst_size = 64;
  505.         res_info->video_burst_size = 64;
  506.         res_info->graphics_hi_priority = 0;
  507.         res_info->media_hi_priority = 0;
  508.         return (0);
  509.     }
  510. }
  511. static char nv3_get_param(nv3_fifo_info *res_info, nv3_sim_state * state, nv3_arb_info *ainfo)
  512. {
  513.     int done, g,v, p;
  514.     
  515.     done = 0;
  516.     for (p=0; p < 2; p++)
  517.     {
  518.         for (g=128 ; g > 32; g= g>> 1)
  519.         {
  520.             for (v=128; v >=32; v = v>> 1)
  521.             {
  522.                 ainfo->priority = p;
  523.                 ainfo->gburst_size = g;     
  524.                 ainfo->vburst_size = v;
  525.                 done = nv3_arb(res_info, state,ainfo);
  526.                 if (done && (g==128))
  527.                     if ((res_info->graphics_lwm + g) > 256)
  528.                         done = 0;
  529.                 if (done)
  530.                     goto Done;
  531.             }
  532.         }
  533.     }
  534.  Done:
  535.     return done;
  536. }
  537. static void nv3CalcArbitration 
  538. (
  539.     nv3_fifo_info * res_info,
  540.     nv3_sim_state * state
  541. )
  542. {
  543.     nv3_fifo_info save_info;
  544.     nv3_arb_info ainfo;
  545.     char   res_gr, res_vid;
  546.     ainfo.gr_en = 1;
  547.     ainfo.vid_en = state->enable_video;
  548.     ainfo.vid_only_once = 0;
  549.     ainfo.gr_only_once = 0;
  550.     ainfo.gdrain_rate = (int) state->pclk_khz * (state->pix_bpp/8);
  551.     ainfo.vdrain_rate = (int) state->pclk_khz * 2;
  552.     if (state->video_scale != 0)
  553.         ainfo.vdrain_rate = ainfo.vdrain_rate/state->video_scale;
  554.     ainfo.mdrain_rate = 33000;
  555.     res_info->rtl_values = 0;
  556.     if (!state->gr_during_vid && state->enable_video)
  557.     {
  558.         ainfo.gr_only_once = 1;
  559.         ainfo.gr_en = 1;
  560.         ainfo.gdrain_rate = 0;
  561.         res_vid = nv3_get_param(res_info, state,  &ainfo);
  562.         res_vid = ainfo.converged;
  563.         save_info.video_lwm = res_info->video_lwm;
  564.         save_info.video_burst_size = res_info->video_burst_size;
  565.         ainfo.vid_en = 1;
  566.         ainfo.vid_only_once = 1;
  567.         ainfo.gr_en = 1;
  568.         ainfo.gdrain_rate = (int) state->pclk_khz * (state->pix_bpp/8);
  569.         ainfo.vdrain_rate = 0;
  570.         res_gr = nv3_get_param(res_info, state,  &ainfo);
  571.         res_gr = ainfo.converged;
  572.         res_info->video_lwm = save_info.video_lwm;
  573.         res_info->video_burst_size = save_info.video_burst_size;
  574.         res_info->valid = res_gr & res_vid;
  575.     }
  576.     else
  577.     {
  578.         if (!ainfo.gr_en) ainfo.gdrain_rate = 0;
  579.         if (!ainfo.vid_en) ainfo.vdrain_rate = 0;
  580.         res_gr = nv3_get_param(res_info, state,  &ainfo);
  581.         res_info->valid = ainfo.converged;
  582.     }
  583. }
  584. static void nv3UpdateArbitrationSettings
  585. (
  586.     unsigned      VClk, 
  587.     unsigned      pixelDepth, 
  588.     unsigned     *burst,
  589.     unsigned     *lwm,
  590.     RIVA_HW_INST *chip
  591. )
  592. {
  593.     nv3_fifo_info fifo_data;
  594.     nv3_sim_state sim_data;
  595.     unsigned int M, N, P, pll, MClk;
  596.     
  597.     pll = chip->PRAMDAC[0x00000504/4];
  598.     M = (pll >> 0) & 0xFF; N = (pll >> 8) & 0xFF; P = (pll >> 16) & 0x0F;
  599.     MClk = (N * chip->CrystalFreqKHz / M) >> P;
  600.     sim_data.pix_bpp        = (char)pixelDepth;
  601.     sim_data.enable_video   = 0;
  602.     sim_data.enable_mp      = 0;
  603.     sim_data.video_scale    = 1;
  604.     sim_data.memory_width   = (chip->PEXTDEV[0x00000000/4] & 0x10) ? 128 : 64;
  605.     sim_data.memory_width   = 128;
  606.     sim_data.mem_latency    = 9;
  607.     sim_data.mem_aligned    = 1;
  608.     sim_data.mem_page_miss  = 11;
  609.     sim_data.gr_during_vid  = 0;
  610.     sim_data.pclk_khz       = VClk;
  611.     sim_data.mclk_khz       = MClk;
  612.     nv3CalcArbitration(&fifo_data, &sim_data);
  613.     if (fifo_data.valid)
  614.     {
  615.         int  b = fifo_data.graphics_burst_size >> 4;
  616.         *burst = 0;
  617.         while (b >>= 1) (*burst)++;
  618.         *lwm   = fifo_data.graphics_lwm >> 3;
  619.     }
  620.     else
  621.     {
  622.         *lwm   = 0x24;
  623.         *burst = 0x2;
  624.     }
  625. }
  626. static void nv4CalcArbitration 
  627. (
  628.     nv4_fifo_info *fifo,
  629.     nv4_sim_state *arb
  630. )
  631. {
  632.     int data, pagemiss, cas,width, video_enable, color_key_enable, bpp, align;
  633.     int nvclks, mclks, pclks, vpagemiss, crtpagemiss, vbs;
  634.     int found, mclk_extra, mclk_loop, cbs, m1, p1;
  635.     int mclk_freq, pclk_freq, nvclk_freq, mp_enable;
  636.     int us_m, us_n, us_p, video_drain_rate, crtc_drain_rate;
  637.     int vpm_us, us_video, vlwm, video_fill_us, cpm_us, us_crt,clwm;
  638.     int craw, vraw;
  639.     fifo->valid = 1;
  640.     pclk_freq = arb->pclk_khz;
  641.     mclk_freq = arb->mclk_khz;
  642.     nvclk_freq = arb->nvclk_khz;
  643.     pagemiss = arb->mem_page_miss;
  644.     cas = arb->mem_latency;
  645.     width = arb->memory_width >> 6;
  646.     video_enable = arb->enable_video;
  647.     color_key_enable = arb->gr_during_vid;
  648.     bpp = arb->pix_bpp;
  649.     align = arb->mem_aligned;
  650.     mp_enable = arb->enable_mp;
  651.     clwm = 0;
  652.     vlwm = 0;
  653.     cbs = 128;
  654.     pclks = 2;
  655.     nvclks = 2;
  656.     nvclks += 2;
  657.     nvclks += 1;
  658.     mclks = 5;
  659.     mclks += 3;
  660.     mclks += 1;
  661.     mclks += cas;
  662.     mclks += 1;
  663.     mclks += 1;
  664.     mclks += 1;
  665.     mclks += 1;
  666.     mclk_extra = 3;
  667.     nvclks += 2;
  668.     nvclks += 1;
  669.     nvclks += 1;
  670.     nvclks += 1;
  671.     if (mp_enable)
  672.         mclks+=4;
  673.     nvclks += 0;
  674.     pclks += 0;
  675.     found = 0;
  676.     vbs = 0;
  677.     while (found != 1)
  678.     {
  679.         fifo->valid = 1;
  680.         found = 1;
  681.         mclk_loop = mclks+mclk_extra;
  682.         us_m = mclk_loop *1000*1000 / mclk_freq;
  683.         us_n = nvclks*1000*1000 / nvclk_freq;
  684.         us_p = nvclks*1000*1000 / pclk_freq;
  685.         if (video_enable)
  686.         {
  687.             video_drain_rate = pclk_freq * 2;
  688.             crtc_drain_rate = pclk_freq * bpp/8;
  689.             vpagemiss = 2;
  690.             vpagemiss += 1;
  691.             crtpagemiss = 2;
  692.             vpm_us = (vpagemiss * pagemiss)*1000*1000/mclk_freq;
  693.             if (nvclk_freq * 2 > mclk_freq * width)
  694.                 video_fill_us = cbs*1000*1000 / 16 / nvclk_freq ;
  695.             else
  696.                 video_fill_us = cbs*1000*1000 / (8 * width) / mclk_freq;
  697.             us_video = vpm_us + us_m + us_n + us_p + video_fill_us;
  698.             vlwm = us_video * video_drain_rate/(1000*1000);
  699.             vlwm++;
  700.             vbs = 128;
  701.             if (vlwm > 128) vbs = 64;
  702.             if (vlwm > (256-64)) vbs = 32;
  703.             if (nvclk_freq * 2 > mclk_freq * width)
  704.                 video_fill_us = vbs *1000*1000/ 16 / nvclk_freq ;
  705.             else
  706.                 video_fill_us = vbs*1000*1000 / (8 * width) / mclk_freq;
  707.             cpm_us = crtpagemiss  * pagemiss *1000*1000/ mclk_freq;
  708.             us_crt =
  709.             us_video
  710.             +video_fill_us
  711.             +cpm_us
  712.             +us_m + us_n +us_p
  713.             ;
  714.             clwm = us_crt * crtc_drain_rate/(1000*1000);
  715.             clwm++;
  716.         }
  717.         else
  718.         {
  719.             crtc_drain_rate = pclk_freq * bpp/8;
  720.             crtpagemiss = 2;
  721.             crtpagemiss += 1;
  722.             cpm_us = crtpagemiss  * pagemiss *1000*1000/ mclk_freq;
  723.             us_crt =  cpm_us + us_m + us_n + us_p ;
  724.             clwm = us_crt * crtc_drain_rate/(1000*1000);
  725.             clwm++;
  726.         }
  727.         m1 = clwm + cbs - 512;
  728.         p1 = m1 * pclk_freq / mclk_freq;
  729.         p1 = p1 * bpp / 8;
  730.         if ((p1 < m1) && (m1 > 0))
  731.         {
  732.             fifo->valid = 0;
  733.             found = 0;
  734.             if (mclk_extra ==0)   found = 1;
  735.             mclk_extra--;
  736.         }
  737.         else if (video_enable)
  738.         {
  739.             if ((clwm > 511) || (vlwm > 255))
  740.             {
  741.                 fifo->valid = 0;
  742.                 found = 0;
  743.                 if (mclk_extra ==0)   found = 1;
  744.                 mclk_extra--;
  745.             }
  746.         }
  747.         else
  748.         {
  749.             if (clwm > 519)
  750.             {
  751.                 fifo->valid = 0;
  752.                 found = 0;
  753.                 if (mclk_extra ==0)   found = 1;
  754.                 mclk_extra--;
  755.             }
  756.         }
  757.         craw = clwm;
  758.         vraw = vlwm;
  759.         if (clwm < 384) clwm = 384;
  760.         if (vlwm < 128) vlwm = 128;
  761.         data = (int)(clwm);
  762.         fifo->graphics_lwm = data;
  763.         fifo->graphics_burst_size = 128;
  764.         data = (int)((vlwm+15));
  765.         fifo->video_lwm = data;
  766.         fifo->video_burst_size = vbs;
  767.     }
  768. }
  769. static void nv4UpdateArbitrationSettings
  770. (
  771.     unsigned      VClk, 
  772.     unsigned      pixelDepth, 
  773.     unsigned     *burst,
  774.     unsigned     *lwm,
  775.     RIVA_HW_INST *chip
  776. )
  777. {
  778.     nv4_fifo_info fifo_data;
  779.     nv4_sim_state sim_data;
  780.     unsigned int M, N, P, pll, MClk, NVClk, cfg1;
  781.     pll = chip->PRAMDAC[0x00000504/4];
  782.     M = (pll >> 0)  & 0xFF; N = (pll >> 8)  & 0xFF; P = (pll >> 16) & 0x0F;
  783.     MClk  = (N * chip->CrystalFreqKHz / M) >> P;
  784.     pll = chip->PRAMDAC[0x00000500/4];
  785.     M = (pll >> 0)  & 0xFF; N = (pll >> 8)  & 0xFF; P = (pll >> 16) & 0x0F;
  786.     NVClk  = (N * chip->CrystalFreqKHz / M) >> P;
  787.     cfg1 = chip->PFB[0x00000204/4];
  788.     sim_data.pix_bpp        = (char)pixelDepth;
  789.     sim_data.enable_video   = 0;
  790.     sim_data.enable_mp      = 0;
  791.     sim_data.memory_width   = (chip->PEXTDEV[0x00000000/4] & 0x10) ? 128 : 64;
  792.     sim_data.mem_latency    = (char)cfg1 & 0x0F;
  793.     sim_data.mem_aligned    = 1;
  794.     sim_data.mem_page_miss  = (char)(((cfg1 >> 4) &0x0F) + ((cfg1 >> 31) & 0x01));
  795.     sim_data.gr_during_vid  = 0;
  796.     sim_data.pclk_khz       = VClk;
  797.     sim_data.mclk_khz       = MClk;
  798.     sim_data.nvclk_khz      = NVClk;
  799.     nv4CalcArbitration(&fifo_data, &sim_data);
  800.     if (fifo_data.valid)
  801.     {
  802.         int  b = fifo_data.graphics_burst_size >> 4;
  803.         *burst = 0;
  804.         while (b >>= 1) (*burst)++;
  805.         *lwm   = fifo_data.graphics_lwm >> 3;
  806.     }
  807. }
  808. static void nv10CalcArbitration 
  809. (
  810.     nv10_fifo_info *fifo,
  811.     nv10_sim_state *arb
  812. )
  813. {
  814.     int data, pagemiss, cas,width, video_enable, color_key_enable, bpp, align;
  815.     int nvclks, mclks, pclks, vpagemiss, crtpagemiss, vbs;
  816.     int nvclk_fill, us_extra;
  817.     int found, mclk_extra, mclk_loop, cbs, m1;
  818.     int mclk_freq, pclk_freq, nvclk_freq, mp_enable;
  819.     int us_m, us_m_min, us_n, us_p, video_drain_rate, crtc_drain_rate;
  820.     int vus_m, vus_n, vus_p;
  821.     int vpm_us, us_video, vlwm, cpm_us, us_crt,clwm;
  822.     int clwm_rnd_down;
  823.     int craw, m2us, us_pipe, us_pipe_min, vus_pipe, p1clk, p2;
  824.     int pclks_2_top_fifo, min_mclk_extra;
  825.     int us_min_mclk_extra;
  826.     fifo->valid = 1;
  827.     pclk_freq = arb->pclk_khz; /* freq in KHz */
  828.     mclk_freq = arb->mclk_khz;
  829.     nvclk_freq = arb->nvclk_khz;
  830.     pagemiss = arb->mem_page_miss;
  831.     cas = arb->mem_latency;
  832.     width = arb->memory_width/64;
  833.     video_enable = arb->enable_video;
  834.     color_key_enable = arb->gr_during_vid;
  835.     bpp = arb->pix_bpp;
  836.     align = arb->mem_aligned;
  837.     mp_enable = arb->enable_mp;
  838.     clwm = 0;
  839.     vlwm = 1024;
  840.     cbs = 512;
  841.     vbs = 512;
  842.     pclks = 4; /* lwm detect. */
  843.     nvclks = 3; /* lwm -> sync. */
  844.     nvclks += 2; /* fbi bus cycles (1 req + 1 busy) */
  845.     mclks  = 1;   /* 2 edge sync.  may be very close to edge so just put one. */
  846.     mclks += 1;   /* arb_hp_req */
  847.     mclks += 5;   /* ap_hp_req   tiling pipeline */
  848.     mclks += 2;    /* tc_req     latency fifo */
  849.     mclks += 2;    /* fb_cas_n_  memory request to fbio block */
  850.     mclks += 7;    /* sm_d_rdv   data returned from fbio block */
  851.     /* fb.rd.d.Put_gc   need to accumulate 256 bits for read */
  852.     if (arb->memory_type == 0)
  853.       if (arb->memory_width == 64) /* 64 bit bus */
  854.         mclks += 4;
  855.       else
  856.         mclks += 2;
  857.     else
  858.       if (arb->memory_width == 64) /* 64 bit bus */
  859.         mclks += 2;
  860.       else
  861.         mclks += 1;
  862.     if ((!video_enable) && (arb->memory_width == 128))
  863.     {  
  864.       mclk_extra = (bpp == 32) ? 31 : 42; /* Margin of error */
  865.       min_mclk_extra = 17;
  866.     }
  867.     else
  868.     {
  869.       mclk_extra = (bpp == 32) ? 8 : 4; /* Margin of error */
  870.       /* mclk_extra = 4; */ /* Margin of error */
  871.       min_mclk_extra = 18;
  872.     }
  873.     nvclks += 1; /* 2 edge sync.  may be very close to edge so just put one. */
  874.     nvclks += 1; /* fbi_d_rdv_n */
  875.     nvclks += 1; /* Fbi_d_rdata */
  876.     nvclks += 1; /* crtfifo load */
  877.     if(mp_enable)
  878.       mclks+=4; /* Mp can get in with a burst of 8. */
  879.     /* Extra clocks determined by heuristics */
  880.     nvclks += 0;
  881.     pclks += 0;
  882.     found = 0;
  883.     while(found != 1) {
  884.       fifo->valid = 1;
  885.       found = 1;
  886.       mclk_loop = mclks+mclk_extra;
  887.       us_m = mclk_loop *1000*1000 / mclk_freq; /* Mclk latency in us */
  888.       us_m_min = mclks * 1000*1000 / mclk_freq; /* Minimum Mclk latency in us */
  889.       us_min_mclk_extra = min_mclk_extra *1000*1000 / mclk_freq;
  890.       us_n = nvclks*1000*1000 / nvclk_freq;/* nvclk latency in us */
  891.       us_p = pclks*1000*1000 / pclk_freq;/* nvclk latency in us */
  892.       us_pipe = us_m + us_n + us_p;
  893.       us_pipe_min = us_m_min + us_n + us_p;
  894.       us_extra = 0;
  895.       vus_m = mclk_loop *1000*1000 / mclk_freq; /* Mclk latency in us */
  896.       vus_n = (4)*1000*1000 / nvclk_freq;/* nvclk latency in us */
  897.       vus_p = 0*1000*1000 / pclk_freq;/* pclk latency in us */
  898.       vus_pipe = vus_m + vus_n + vus_p;
  899.       if(video_enable) {
  900.         video_drain_rate = pclk_freq * 4; /* MB/s */
  901.         crtc_drain_rate = pclk_freq * bpp/8; /* MB/s */
  902.         vpagemiss = 1; /* self generating page miss */
  903.         vpagemiss += 1; /* One higher priority before */
  904.         crtpagemiss = 2; /* self generating page miss */
  905.         if(mp_enable)
  906.             crtpagemiss += 1; /* if MA0 conflict */
  907.         vpm_us = (vpagemiss * pagemiss)*1000*1000/mclk_freq;
  908.         us_video = vpm_us + vus_m; /* Video has separate read return path */
  909.         cpm_us = crtpagemiss  * pagemiss *1000*1000/ mclk_freq;
  910.         us_crt =
  911.           us_video  /* Wait for video */
  912.           +cpm_us /* CRT Page miss */
  913.           +us_m + us_n +us_p /* other latency */
  914.           ;
  915.         clwm = us_crt * crtc_drain_rate/(1000*1000);
  916.         clwm++; /* fixed point <= float_point - 1.  Fixes that */
  917.       } else {
  918.         crtc_drain_rate = pclk_freq * bpp/8; /* bpp * pclk/8 */
  919.         crtpagemiss = 1; /* self generating page miss */
  920.         crtpagemiss += 1; /* MA0 page miss */
  921.         if(mp_enable)
  922.             crtpagemiss += 1; /* if MA0 conflict */
  923.         cpm_us = crtpagemiss  * pagemiss *1000*1000/ mclk_freq;
  924.         us_crt =  cpm_us + us_m + us_n + us_p ;
  925.         clwm = us_crt * crtc_drain_rate/(1000*1000);
  926.         clwm++; /* fixed point <= float_point - 1.  Fixes that */
  927.   /*
  928.           //
  929.           // Another concern, only for high pclks so don't do this
  930.           // with video:
  931.           // What happens if the latency to fetch the cbs is so large that
  932.           // fifo empties.  In that case we need to have an alternate clwm value
  933.           // based off the total burst fetch
  934.           //
  935.           us_crt = (cbs * 1000 * 1000)/ (8*width)/mclk_freq ;
  936.           us_crt = us_crt + us_m + us_n + us_p + (4 * 1000 * 1000)/mclk_freq;
  937.           clwm_mt = us_crt * crtc_drain_rate/(1000*1000);
  938.           clwm_mt ++;
  939.           if(clwm_mt > clwm)
  940.               clwm = clwm_mt;
  941.   */
  942.           /* Finally, a heuristic check when width == 64 bits */
  943.           if(width == 1){
  944.               nvclk_fill = nvclk_freq * 8;
  945.               if(crtc_drain_rate * 100 >= nvclk_fill * 102)
  946.                       clwm = 0xfff; /*Large number to fail */
  947.               else if(crtc_drain_rate * 100  >= nvclk_fill * 98) {
  948.                   clwm = 1024;
  949.                   cbs = 512;
  950.                   us_extra = (cbs * 1000 * 1000)/ (8*width)/mclk_freq ;
  951.               }
  952.           }
  953.       }
  954.       /*
  955.         Overfill check:
  956.         */
  957.       clwm_rnd_down = ((int)clwm/8)*8;
  958.       if (clwm_rnd_down < clwm)
  959.           clwm += 8;
  960.       m1 = clwm + cbs -  1024; /* Amount of overfill */
  961.       m2us = us_pipe_min + us_min_mclk_extra;
  962.       pclks_2_top_fifo = (1024-clwm)/(8*width);
  963.       /* pclk cycles to drain */
  964.       p1clk = m2us * pclk_freq/(1000*1000); 
  965.       p2 = p1clk * bpp / 8; /* bytes drained. */
  966.       if((p2 < m1) && (m1 > 0)) {
  967.           fifo->valid = 0;
  968.           found = 0;
  969.           if(min_mclk_extra == 0)   {
  970.             if(cbs <= 32) {
  971.               found = 1; /* Can't adjust anymore! */
  972.             } else {
  973.               cbs = cbs/2;  /* reduce the burst size */
  974.             }
  975.           } else {
  976.             min_mclk_extra--;
  977.           }
  978.       } else {
  979.         if (clwm > 1023){ /* Have some margin */
  980.           fifo->valid = 0;
  981.           found = 0;
  982.           if(min_mclk_extra == 0)   
  983.               found = 1; /* Can't adjust anymore! */
  984.           else 
  985.               min_mclk_extra--;
  986.         }
  987.       }
  988.       craw = clwm;
  989.       if(clwm < (1024-cbs+8)) clwm = 1024-cbs+8;
  990.       data = (int)(clwm);
  991.       /*  printf("CRT LWM: %f bytes, prog: 0x%x, bs: 256n", clwm, data ); */
  992.       fifo->graphics_lwm = data;   fifo->graphics_burst_size = cbs;
  993.       /*  printf("VID LWM: %f bytes, prog: 0x%x, bs: %dn, ", vlwm, data, vbs ); */
  994.       fifo->video_lwm = 1024;  fifo->video_burst_size = 512;
  995.     }
  996. }
  997. static void nv10UpdateArbitrationSettings
  998. (
  999.     unsigned      VClk, 
  1000.     unsigned      pixelDepth, 
  1001.     unsigned     *burst,
  1002.     unsigned     *lwm,
  1003.     RIVA_HW_INST *chip
  1004. )
  1005. {
  1006.     nv10_fifo_info fifo_data;
  1007.     nv10_sim_state sim_data;
  1008.     unsigned int M, N, P, pll, MClk, NVClk, cfg1;
  1009.     pll = chip->PRAMDAC[0x00000504/4];
  1010.     M = (pll >> 0)  & 0xFF; N = (pll >> 8)  & 0xFF; P = (pll >> 16) & 0x0F;
  1011.     MClk  = (N * chip->CrystalFreqKHz / M) >> P;
  1012.     pll = chip->PRAMDAC[0x00000500/4];
  1013.     M = (pll >> 0)  & 0xFF; N = (pll >> 8)  & 0xFF; P = (pll >> 16) & 0x0F;
  1014.     NVClk  = (N * chip->CrystalFreqKHz / M) >> P;
  1015.     cfg1 = chip->PFB[0x00000204/4];
  1016.     sim_data.pix_bpp        = (char)pixelDepth;
  1017.     sim_data.enable_video   = 0;
  1018.     sim_data.enable_mp      = 0;
  1019.     sim_data.memory_type    = (chip->PFB[0x00000200/4] & 0x01) ? 1 : 0;
  1020.     sim_data.memory_width   = (chip->PEXTDEV[0x00000000/4] & 0x10) ? 128 : 64;
  1021.     sim_data.mem_latency    = (char)cfg1 & 0x0F;
  1022.     sim_data.mem_aligned    = 1;
  1023.     sim_data.mem_page_miss  = (char)(((cfg1 >> 4) &0x0F) + ((cfg1 >> 31) & 0x01));
  1024.     sim_data.gr_during_vid  = 0;
  1025.     sim_data.pclk_khz       = VClk;
  1026.     sim_data.mclk_khz       = MClk;
  1027.     sim_data.nvclk_khz      = NVClk;
  1028.     nv10CalcArbitration(&fifo_data, &sim_data);
  1029.     if (fifo_data.valid)
  1030.     {
  1031.         int  b = fifo_data.graphics_burst_size >> 4;
  1032.         *burst = 0;
  1033.         while (b >>= 1) (*burst)++;
  1034.         *lwm   = fifo_data.graphics_lwm >> 3;
  1035.     }
  1036. }
  1037. /****************************************************************************
  1038. *                                                                            *
  1039. *                          RIVA Mode State Routines                          *
  1040. *                                                                            *
  1041. ****************************************************************************/
  1042. /*
  1043.  * Calculate the Video Clock parameters for the PLL.
  1044.  */
  1045. static int CalcVClock
  1046. (
  1047.     int           clockIn,
  1048.     int           double_scan,
  1049.     int          *clockOut,
  1050.     int          *mOut,
  1051.     int          *nOut,
  1052.     int          *pOut,
  1053.     RIVA_HW_INST *chip
  1054. )
  1055. {
  1056.     unsigned lowM, highM, highP;
  1057.     unsigned DeltaNew, DeltaOld;
  1058.     unsigned VClk, Freq;
  1059.     unsigned M, N, P;
  1060.     
  1061.     DeltaOld = 0xFFFFFFFF;
  1062.     VClk     = (unsigned)clockIn;
  1063.     if (double_scan)
  1064.         VClk *= 2;
  1065.     
  1066.     if (chip->CrystalFreqKHz == 14318)
  1067.     {
  1068.         lowM  = 8;
  1069.         highM = 14 - (chip->Architecture == NV_ARCH_03);
  1070.     }
  1071.     else
  1072.     {
  1073.         lowM  = 7;
  1074.         highM = 13 - (chip->Architecture == NV_ARCH_03);
  1075.     }                      
  1076.     highP = 4 - (chip->Architecture == NV_ARCH_03);
  1077.     for (P = 0; P <= highP; P ++)
  1078.     {
  1079.         Freq = VClk << P;
  1080.         if ((Freq >= 128000) && (Freq <= chip->MaxVClockFreqKHz))
  1081.         {
  1082.             for (M = lowM; M <= highM; M++)
  1083.             {
  1084.                 N    = (VClk * M / chip->CrystalFreqKHz) << P;
  1085.                 Freq = (chip->CrystalFreqKHz * N / M) >> P;
  1086.                 if (Freq > VClk)
  1087.                     DeltaNew = Freq - VClk;
  1088.                 else
  1089.                     DeltaNew = VClk - Freq;
  1090.                 if (DeltaNew < DeltaOld)
  1091.                 {
  1092.                     *mOut     = M;
  1093.                     *nOut     = N;
  1094.                     *pOut     = P;
  1095.                     *clockOut = Freq;
  1096.                     DeltaOld  = DeltaNew;
  1097.                 }
  1098.             }
  1099.         }
  1100.     }
  1101.     return (DeltaOld != 0xFFFFFFFF);
  1102. }
  1103. /*
  1104.  * Calculate extended mode parameters (SVGA) and save in a 
  1105.  * mode state structure.
  1106.  */
  1107. static void CalcStateExt
  1108. (
  1109.     RIVA_HW_INST  *chip,
  1110.     RIVA_HW_STATE *state,
  1111.     int            bpp,
  1112.     int            width,
  1113.     int            hDisplaySize,
  1114.     int            hDisplay,
  1115.     int            hStart,
  1116.     int            hEnd,
  1117.     int            hTotal,
  1118.     int            height,
  1119.     int            vDisplay,
  1120.     int            vStart,
  1121.     int            vEnd,
  1122.     int            vTotal,
  1123.     int            dotClock
  1124. )
  1125. {
  1126.     int pixelDepth, VClk, m, n, p;
  1127.     /*
  1128.      * Save mode parameters.
  1129.      */
  1130.     state->bpp    = bpp;
  1131.     state->width  = width;
  1132.     state->height = height;
  1133.     /*
  1134.      * Extended RIVA registers.
  1135.      */
  1136.     pixelDepth = (bpp + 1)/8;
  1137.     CalcVClock(dotClock, hDisplaySize < 512,  /* double scan? */
  1138.                &VClk, &m, &n, &p, chip);
  1139.     switch (chip->Architecture)
  1140.     {
  1141.         case NV_ARCH_03:
  1142.             nv3UpdateArbitrationSettings(VClk, 
  1143.                                          pixelDepth * 8, 
  1144.                                         &(state->arbitration0),
  1145.                                         &(state->arbitration1),
  1146.                                          chip);
  1147.             state->cursor0  = 0x00;
  1148.             state->cursor1  = 0x78;
  1149.             state->cursor2  = 0x00000000;
  1150.             state->pllsel   = 0x10010100;
  1151.             state->config   = ((width + 31)/32)
  1152.                             | (((pixelDepth > 2) ? 3 : pixelDepth) << 8)
  1153.                             | 0x1000;
  1154.             state->general  = 0x00100100;
  1155.             state->repaint1 = hDisplaySize < 1280 ? 0x06 : 0x02;
  1156.             break;
  1157.         case NV_ARCH_04:
  1158.             nv4UpdateArbitrationSettings(VClk, 
  1159.                                          pixelDepth * 8, 
  1160.                                         &(state->arbitration0),
  1161.                                         &(state->arbitration1),
  1162.                                          chip);
  1163.             state->cursor0  = 0x00;
  1164.             state->cursor1  = 0xFC;
  1165.             state->cursor2  = 0x00000000;
  1166.             state->pllsel   = 0x10000700;
  1167.             state->config   = 0x00001114;
  1168.             state->general  = bpp == 16 ? 0x00101100 : 0x00100100;
  1169.             state->repaint1 = hDisplaySize < 1280 ? 0x04 : 0x00;
  1170.             break;
  1171.         case NV_ARCH_10:
  1172. case NV_ARCH_20:
  1173.             nv10UpdateArbitrationSettings(VClk, 
  1174.                                           pixelDepth * 8, 
  1175.                                          &(state->arbitration0),
  1176.                                          &(state->arbitration1),
  1177.                                           chip);
  1178.             state->cursor0  = 0x00;
  1179.             state->cursor1  = 0xFC;
  1180.             state->cursor2  = 0x00000000;
  1181.             state->pllsel   = 0x10000700;
  1182.             state->config   = chip->PFB[0x00000200/4];
  1183.             state->general  = bpp == 16 ? 0x00101100 : 0x00100100;
  1184.             state->repaint1 = hDisplaySize < 1280 ? 0x04 : 0x00;
  1185.             break;
  1186.     }
  1187.     state->vpll     = (p << 16) | (n << 8) | m;
  1188.     state->screen   = ((hTotal   & 0x040) >> 2)
  1189.                     | ((vDisplay & 0x400) >> 7)
  1190.                     | ((vStart   & 0x400) >> 8)
  1191.                     | ((vDisplay & 0x400) >> 9)
  1192.                     | ((vTotal   & 0x400) >> 10);
  1193.     state->repaint0 = (((width/8)*pixelDepth) & 0x700) >> 3;
  1194.     state->horiz    = hTotal     < 260 ? 0x00 : 0x01;
  1195.     state->pixel    = pixelDepth > 2   ? 3    : pixelDepth;
  1196.     state->offset0  =
  1197.     state->offset1  =
  1198.     state->offset2  =
  1199.     state->offset3  = 0;
  1200.     state->pitch0   =
  1201.     state->pitch1   =
  1202.     state->pitch2   =
  1203.     state->pitch3   = pixelDepth * width;
  1204. }
  1205. /*
  1206.  * Load fixed function state and pre-calculated/stored state.
  1207.  */
  1208. #define LOAD_FIXED_STATE(tbl,dev)                                       
  1209.     for (i = 0; i < sizeof(tbl##Table##dev)/8; i++)                 
  1210.         chip->dev[tbl##Table##dev[i][0]] = tbl##Table##dev[i][1]
  1211. #define LOAD_FIXED_STATE_8BPP(tbl,dev)                                  
  1212.     for (i = 0; i < sizeof(tbl##Table##dev##_8BPP)/8; i++)            
  1213.         chip->dev[tbl##Table##dev##_8BPP[i][0]] = tbl##Table##dev##_8BPP[i][1]
  1214. #define LOAD_FIXED_STATE_15BPP(tbl,dev)                                 
  1215.     for (i = 0; i < sizeof(tbl##Table##dev##_15BPP)/8; i++)           
  1216.         chip->dev[tbl##Table##dev##_15BPP[i][0]] = tbl##Table##dev##_15BPP[i][1]
  1217. #define LOAD_FIXED_STATE_16BPP(tbl,dev)                                 
  1218.     for (i = 0; i < sizeof(tbl##Table##dev##_16BPP)/8; i++)           
  1219.         chip->dev[tbl##Table##dev##_16BPP[i][0]] = tbl##Table##dev##_16BPP[i][1]
  1220. #define LOAD_FIXED_STATE_32BPP(tbl,dev)                                 
  1221.     for (i = 0; i < sizeof(tbl##Table##dev##_32BPP)/8; i++)           
  1222.         chip->dev[tbl##Table##dev##_32BPP[i][0]] = tbl##Table##dev##_32BPP[i][1]
  1223. static void UpdateFifoState
  1224. (
  1225.     RIVA_HW_INST  *chip
  1226. )
  1227. {
  1228.     int i;
  1229.     switch (chip->Architecture)
  1230.     {
  1231.         case NV_ARCH_04:
  1232.             LOAD_FIXED_STATE(nv4,FIFO);
  1233.             chip->Tri03 = 0L;
  1234.             chip->Tri05 = (RivaTexturedTriangle05 *)&(chip->FIFO[0x0000E000/4]);
  1235.             break;
  1236.         case NV_ARCH_10:
  1237. case NV_ARCH_20:
  1238.             /*
  1239.              * Initialize state for the RivaTriangle3D05 routines.
  1240.              */
  1241.             LOAD_FIXED_STATE(nv10tri05,PGRAPH);
  1242.             LOAD_FIXED_STATE(nv10,FIFO);
  1243.             chip->Tri03 = 0L;
  1244.             chip->Tri05 = (RivaTexturedTriangle05 *)&(chip->FIFO[0x0000E000/4]);
  1245.             break;
  1246.     }
  1247. }
  1248. static void LoadStateExt
  1249. (
  1250.     RIVA_HW_INST  *chip,
  1251.     RIVA_HW_STATE *state
  1252. )
  1253. {
  1254.     int i;
  1255.     /*
  1256.      * Load HW fixed function state.
  1257.      */
  1258.     LOAD_FIXED_STATE(Riva,PMC);
  1259.     LOAD_FIXED_STATE(Riva,PTIMER);
  1260.     switch (chip->Architecture)
  1261.     {
  1262.         case NV_ARCH_03:
  1263.             /*
  1264.              * Make sure frame buffer config gets set before loading PRAMIN.
  1265.              */
  1266.             chip->PFB[0x00000200/4] = state->config;
  1267.             LOAD_FIXED_STATE(nv3,PFIFO);
  1268.             LOAD_FIXED_STATE(nv3,PRAMIN);
  1269.             LOAD_FIXED_STATE(nv3,PGRAPH);
  1270.             switch (state->bpp)
  1271.             {
  1272.                 case 15:
  1273.                 case 16:
  1274.                     LOAD_FIXED_STATE_15BPP(nv3,PRAMIN);
  1275.                     LOAD_FIXED_STATE_15BPP(nv3,PGRAPH);
  1276.                     chip->Tri03 = (RivaTexturedTriangle03  *)&(chip->FIFO[0x0000E000/4]);
  1277.                     break;
  1278.                 case 24:
  1279.                 case 32:
  1280.                     LOAD_FIXED_STATE_32BPP(nv3,PRAMIN);
  1281.                     LOAD_FIXED_STATE_32BPP(nv3,PGRAPH);
  1282.                     chip->Tri03 = 0L;
  1283.                     break;
  1284.                 case 8:
  1285.                 default:
  1286.                     LOAD_FIXED_STATE_8BPP(nv3,PRAMIN);
  1287.                     LOAD_FIXED_STATE_8BPP(nv3,PGRAPH);
  1288.                     chip->Tri03 = 0L;
  1289.                     break;
  1290.             }
  1291.             for (i = 0x00000; i < 0x00800; i++)
  1292.                 chip->PRAMIN[0x00000502 + i] = (i << 12) | 0x03;
  1293.             chip->PGRAPH[0x00000630/4] = state->offset0;
  1294.             chip->PGRAPH[0x00000634/4] = state->offset1;
  1295.             chip->PGRAPH[0x00000638/4] = state->offset2;
  1296.             chip->PGRAPH[0x0000063C/4] = state->offset3;
  1297.             chip->PGRAPH[0x00000650/4] = state->pitch0;
  1298.             chip->PGRAPH[0x00000654/4] = state->pitch1;
  1299.             chip->PGRAPH[0x00000658/4] = state->pitch2;
  1300.             chip->PGRAPH[0x0000065C/4] = state->pitch3;
  1301.             break;
  1302.         case NV_ARCH_04:
  1303.             /*
  1304.              * Make sure frame buffer config gets set before loading PRAMIN.
  1305.              */
  1306.             chip->PFB[0x00000200/4] = state->config;
  1307.             LOAD_FIXED_STATE(nv4,PFIFO);
  1308.             LOAD_FIXED_STATE(nv4,PRAMIN);
  1309.             LOAD_FIXED_STATE(nv4,PGRAPH);
  1310.             switch (state->bpp)
  1311.             {
  1312.                 case 15:
  1313.                     LOAD_FIXED_STATE_15BPP(nv4,PRAMIN);
  1314.                     LOAD_FIXED_STATE_15BPP(nv4,PGRAPH);
  1315.                     chip->Tri03 = (RivaTexturedTriangle03  *)&(chip->FIFO[0x0000E000/4]);
  1316.                     break;
  1317.                 case 16:
  1318.                     LOAD_FIXED_STATE_16BPP(nv4,PRAMIN);
  1319.                     LOAD_FIXED_STATE_16BPP(nv4,PGRAPH);
  1320.                     chip->Tri03 = (RivaTexturedTriangle03  *)&(chip->FIFO[0x0000E000/4]);
  1321.                     break;
  1322.                 case 24:
  1323.                 case 32:
  1324.                     LOAD_FIXED_STATE_32BPP(nv4,PRAMIN);
  1325.                     LOAD_FIXED_STATE_32BPP(nv4,PGRAPH);
  1326.                     chip->Tri03 = 0L;
  1327.                     break;
  1328.                 case 8:
  1329.                 default:
  1330.                     LOAD_FIXED_STATE_8BPP(nv4,PRAMIN);
  1331.                     LOAD_FIXED_STATE_8BPP(nv4,PGRAPH);
  1332.                     chip->Tri03 = 0L;
  1333.                     break;
  1334.             }
  1335.             chip->PGRAPH[0x00000640/4] = state->offset0;
  1336.             chip->PGRAPH[0x00000644/4] = state->offset1;
  1337.             chip->PGRAPH[0x00000648/4] = state->offset2;
  1338.             chip->PGRAPH[0x0000064C/4] = state->offset3;
  1339.             chip->PGRAPH[0x00000670/4] = state->pitch0;
  1340.             chip->PGRAPH[0x00000674/4] = state->pitch1;
  1341.             chip->PGRAPH[0x00000678/4] = state->pitch2;
  1342.             chip->PGRAPH[0x0000067C/4] = state->pitch3;
  1343.             break;
  1344.         case NV_ARCH_10:
  1345. case NV_ARCH_20:
  1346.             LOAD_FIXED_STATE(nv10,PFIFO);
  1347.             LOAD_FIXED_STATE(nv10,PRAMIN);
  1348.             LOAD_FIXED_STATE(nv10,PGRAPH);
  1349.             switch (state->bpp)
  1350.             {
  1351.                 case 15:
  1352.                     LOAD_FIXED_STATE_15BPP(nv10,PRAMIN);
  1353.                     LOAD_FIXED_STATE_15BPP(nv10,PGRAPH);
  1354.                     chip->Tri03 = (RivaTexturedTriangle03  *)&(chip->FIFO[0x0000E000/4]);
  1355.                     break;
  1356.                 case 16:
  1357.                     LOAD_FIXED_STATE_16BPP(nv10,PRAMIN);
  1358.                     LOAD_FIXED_STATE_16BPP(nv10,PGRAPH);
  1359.                     chip->Tri03 = (RivaTexturedTriangle03  *)&(chip->FIFO[0x0000E000/4]);
  1360.                     break;
  1361.                 case 24:
  1362.                 case 32:
  1363.                     LOAD_FIXED_STATE_32BPP(nv10,PRAMIN);
  1364.                     LOAD_FIXED_STATE_32BPP(nv10,PGRAPH);
  1365.                     chip->Tri03 = 0L;
  1366.                     break;
  1367.                 case 8:
  1368.                 default:
  1369.                     LOAD_FIXED_STATE_8BPP(nv10,PRAMIN);
  1370.                     LOAD_FIXED_STATE_8BPP(nv10,PGRAPH);
  1371.                     chip->Tri03 = 0L;
  1372.                     break;
  1373.             }
  1374.     if (chip->Architecture == NV_ARCH_10) {
  1375.              chip->PGRAPH[0x00000640/4] = state->offset0;
  1376.              chip->PGRAPH[0x00000644/4] = state->offset1;
  1377.              chip->PGRAPH[0x00000648/4] = state->offset2;
  1378.              chip->PGRAPH[0x0000064C/4] = state->offset3;
  1379.              chip->PGRAPH[0x00000670/4] = state->pitch0;
  1380.              chip->PGRAPH[0x00000674/4] = state->pitch1;
  1381.              chip->PGRAPH[0x00000678/4] = state->pitch2;
  1382.              chip->PGRAPH[0x0000067C/4] = state->pitch3;
  1383.              chip->PGRAPH[0x00000680/4] = state->pitch3;
  1384.     } else {
  1385. chip->PGRAPH[0x00000820/4] = state->offset0;
  1386. chip->PGRAPH[0x00000824/4] = state->offset1;
  1387. chip->PGRAPH[0x00000828/4] = state->offset2;
  1388. chip->PGRAPH[0x0000082C/4] = state->offset3;
  1389. chip->PGRAPH[0x00000850/4] = state->pitch0;
  1390. chip->PGRAPH[0x00000854/4] = state->pitch1;
  1391. chip->PGRAPH[0x00000858/4] = state->pitch2;
  1392. chip->PGRAPH[0x0000085C/4] = state->pitch3;
  1393. chip->PGRAPH[0x00000860/4] = state->pitch3;
  1394. chip->PGRAPH[0x00000864/4] = state->pitch3;
  1395. chip->PGRAPH[0x000009A4/4] = chip->PFB[0x00000200/4];
  1396. chip->PGRAPH[0x000009A8/4] = chip->PFB[0x00000204/4];
  1397.     }
  1398.             chip->PGRAPH[0x00000B00/4] = chip->PFB[0x00000240/4];
  1399.             chip->PGRAPH[0x00000B04/4] = chip->PFB[0x00000244/4];
  1400.             chip->PGRAPH[0x00000B08/4] = chip->PFB[0x00000248/4];
  1401.             chip->PGRAPH[0x00000B0C/4] = chip->PFB[0x0000024C/4];
  1402.             chip->PGRAPH[0x00000B10/4] = chip->PFB[0x00000250/4];
  1403.             chip->PGRAPH[0x00000B14/4] = chip->PFB[0x00000254/4];
  1404.             chip->PGRAPH[0x00000B18/4] = chip->PFB[0x00000258/4];
  1405.             chip->PGRAPH[0x00000B1C/4] = chip->PFB[0x0000025C/4];
  1406.             chip->PGRAPH[0x00000B20/4] = chip->PFB[0x00000260/4];
  1407.             chip->PGRAPH[0x00000B24/4] = chip->PFB[0x00000264/4];
  1408.             chip->PGRAPH[0x00000B28/4] = chip->PFB[0x00000268/4];
  1409.             chip->PGRAPH[0x00000B2C/4] = chip->PFB[0x0000026C/4];
  1410.             chip->PGRAPH[0x00000B30/4] = chip->PFB[0x00000270/4];
  1411.             chip->PGRAPH[0x00000B34/4] = chip->PFB[0x00000274/4];
  1412.             chip->PGRAPH[0x00000B38/4] = chip->PFB[0x00000278/4];
  1413.             chip->PGRAPH[0x00000B3C/4] = chip->PFB[0x0000027C/4];
  1414.             chip->PGRAPH[0x00000B40/4] = chip->PFB[0x00000280/4];
  1415.             chip->PGRAPH[0x00000B44/4] = chip->PFB[0x00000284/4];
  1416.             chip->PGRAPH[0x00000B48/4] = chip->PFB[0x00000288/4];
  1417.             chip->PGRAPH[0x00000B4C/4] = chip->PFB[0x0000028C/4];
  1418.             chip->PGRAPH[0x00000B50/4] = chip->PFB[0x00000290/4];
  1419.             chip->PGRAPH[0x00000B54/4] = chip->PFB[0x00000294/4];
  1420.             chip->PGRAPH[0x00000B58/4] = chip->PFB[0x00000298/4];
  1421.             chip->PGRAPH[0x00000B5C/4] = chip->PFB[0x0000029C/4];
  1422.             chip->PGRAPH[0x00000B60/4] = chip->PFB[0x000002A0/4];
  1423.             chip->PGRAPH[0x00000B64/4] = chip->PFB[0x000002A4/4];
  1424.             chip->PGRAPH[0x00000B68/4] = chip->PFB[0x000002A8/4];
  1425.             chip->PGRAPH[0x00000B6C/4] = chip->PFB[0x000002AC/4];
  1426.             chip->PGRAPH[0x00000B70/4] = chip->PFB[0x000002B0/4];
  1427.             chip->PGRAPH[0x00000B74/4] = chip->PFB[0x000002B4/4];
  1428.             chip->PGRAPH[0x00000B78/4] = chip->PFB[0x000002B8/4];
  1429.             chip->PGRAPH[0x00000B7C/4] = chip->PFB[0x000002BC/4];
  1430.             chip->PGRAPH[0x00000F40/4] = 0x10000000;
  1431.             chip->PGRAPH[0x00000F44/4] = 0x00000000;
  1432.             chip->PGRAPH[0x00000F50/4] = 0x00000040;
  1433.             chip->PGRAPH[0x00000F54/4] = 0x00000008;
  1434.             chip->PGRAPH[0x00000F50/4] = 0x00000200;
  1435.             for (i = 0; i < (3*16); i++)
  1436.                 chip->PGRAPH[0x00000F54/4] = 0x00000000;
  1437.             chip->PGRAPH[0x00000F50/4] = 0x00000040;
  1438.             chip->PGRAPH[0x00000F54/4] = 0x00000000;
  1439.             chip->PGRAPH[0x00000F50/4] = 0x00000800;
  1440.             for (i = 0; i < (16*16); i++)
  1441.                 chip->PGRAPH[0x00000F54/4] = 0x00000000;
  1442.             chip->PGRAPH[0x00000F40/4] = 0x30000000;
  1443.             chip->PGRAPH[0x00000F44/4] = 0x00000004;
  1444.             chip->PGRAPH[0x00000F50/4] = 0x00006400;
  1445.             for (i = 0; i < (59*4); i++)
  1446.                 chip->PGRAPH[0x00000F54/4] = 0x00000000;
  1447.             chip->PGRAPH[0x00000F50/4] = 0x00006800;
  1448.             for (i = 0; i < (47*4); i++)
  1449.                 chip->PGRAPH[0x00000F54/4] = 0x00000000;
  1450.             chip->PGRAPH[0x00000F50/4] = 0x00006C00;
  1451.             for (i = 0; i < (3*4); i++)
  1452.                 chip->PGRAPH[0x00000F54/4] = 0x00000000;
  1453.             chip->PGRAPH[0x00000F50/4] = 0x00007000;
  1454.             for (i = 0; i < (19*4); i++)
  1455.                 chip->PGRAPH[0x00000F54/4] = 0x00000000;
  1456.             chip->PGRAPH[0x00000F50/4] = 0x00007400;
  1457.             for (i = 0; i < (12*4); i++)
  1458.                 chip->PGRAPH[0x00000F54/4] = 0x00000000;
  1459.             chip->PGRAPH[0x00000F50/4] = 0x00007800;
  1460.             for (i = 0; i < (12*4); i++)
  1461.                 chip->PGRAPH[0x00000F54/4] = 0x00000000;
  1462.             chip->PGRAPH[0x00000F50/4] = 0x00004400;
  1463.             for (i = 0; i < (8*4); i++)
  1464.                 chip->PGRAPH[0x00000F54/4] = 0x00000000;
  1465.             chip->PGRAPH[0x00000F50/4] = 0x00000000;
  1466.             for (i = 0; i < 16; i++)
  1467.                 chip->PGRAPH[0x00000F54/4] = 0x00000000;
  1468.             chip->PGRAPH[0x00000F50/4] = 0x00000040;
  1469.             for (i = 0; i < 4; i++)
  1470.                 chip->PGRAPH[0x00000F54/4] = 0x00000000;
  1471.             break;
  1472.     }
  1473.     LOAD_FIXED_STATE(Riva,FIFO);
  1474.     UpdateFifoState(chip);
  1475.     /*
  1476.      * Load HW mode state.
  1477.      */
  1478.     VGA_WR08(chip->PCIO, 0x03D4, 0x19);
  1479.     VGA_WR08(chip->PCIO, 0x03D5, state->repaint0);
  1480.     VGA_WR08(chip->PCIO, 0x03D4, 0x1A);
  1481.     VGA_WR08(chip->PCIO, 0x03D5, state->repaint1);
  1482.     VGA_WR08(chip->PCIO, 0x03D4, 0x25);
  1483.     VGA_WR08(chip->PCIO, 0x03D5, state->screen);
  1484.     VGA_WR08(chip->PCIO, 0x03D4, 0x28);
  1485.     VGA_WR08(chip->PCIO, 0x03D5, state->pixel);
  1486.     VGA_WR08(chip->PCIO, 0x03D4, 0x2D);
  1487.     VGA_WR08(chip->PCIO, 0x03D5, state->horiz);
  1488.     VGA_WR08(chip->PCIO, 0x03D4, 0x1B);
  1489.     VGA_WR08(chip->PCIO, 0x03D5, state->arbitration0);
  1490.     VGA_WR08(chip->PCIO, 0x03D4, 0x20);
  1491.     VGA_WR08(chip->PCIO, 0x03D5, state->arbitration1);
  1492.     VGA_WR08(chip->PCIO, 0x03D4, 0x30);
  1493.     VGA_WR08(chip->PCIO, 0x03D5, state->cursor0);
  1494.     VGA_WR08(chip->PCIO, 0x03D4, 0x31);
  1495.     VGA_WR08(chip->PCIO, 0x03D5, state->cursor1);
  1496.     chip->PRAMDAC[0x00000300/4]  = state->cursor2;
  1497.     chip->PRAMDAC[0x00000508/4]  = state->vpll;
  1498.     chip->PRAMDAC[0x0000050C/4]  = state->pllsel;
  1499.     chip->PRAMDAC[0x00000600/4]  = state->general;
  1500.     /*
  1501.      * Turn off VBlank enable and reset.
  1502.      */
  1503.     *(chip->VBLANKENABLE) = 0;
  1504.     *(chip->VBLANK)       = chip->VBlankBit;
  1505.     /*
  1506.      * Set interrupt enable.
  1507.      */    
  1508.     chip->PMC[0x00000140/4]  = chip->EnableIRQ & 0x01;
  1509.     /*
  1510.      * Set current state pointer.
  1511.      */
  1512.     chip->CurrentState = state;
  1513.     /*
  1514.      * Reset FIFO free and empty counts.
  1515.      */
  1516.     chip->FifoFreeCount  = 0;
  1517.     /* Free count from first subchannel */
  1518.     chip->FifoEmptyCount = chip->Rop->FifoFree; 
  1519. }
  1520. static void UnloadStateExt
  1521. (
  1522.     RIVA_HW_INST  *chip,
  1523.     RIVA_HW_STATE *state
  1524. )
  1525. {
  1526.     /*
  1527.      * Save current HW state.
  1528.      */
  1529.     VGA_WR08(chip->PCIO, 0x03D4, 0x19);
  1530.     state->repaint0     = VGA_RD08(chip->PCIO, 0x03D5);
  1531.     VGA_WR08(chip->PCIO, 0x03D4, 0x1A);
  1532.     state->repaint1     = VGA_RD08(chip->PCIO, 0x03D5);
  1533.     VGA_WR08(chip->PCIO, 0x03D4, 0x25);
  1534.     state->screen       = VGA_RD08(chip->PCIO, 0x03D5);
  1535.     VGA_WR08(chip->PCIO, 0x03D4, 0x28);
  1536.     state->pixel        = VGA_RD08(chip->PCIO, 0x03D5);
  1537.     VGA_WR08(chip->PCIO, 0x03D4, 0x2D);
  1538.     state->horiz        = VGA_RD08(chip->PCIO, 0x03D5);
  1539.     VGA_WR08(chip->PCIO, 0x03D4, 0x1B);
  1540.     state->arbitration0 = VGA_RD08(chip->PCIO, 0x03D5);
  1541.     VGA_WR08(chip->PCIO, 0x03D4, 0x20);
  1542.     state->arbitration1 = VGA_RD08(chip->PCIO, 0x03D5);
  1543.     VGA_WR08(chip->PCIO, 0x03D4, 0x30);
  1544.     state->cursor0      = VGA_RD08(chip->PCIO, 0x03D5);
  1545.     VGA_WR08(chip->PCIO, 0x03D4, 0x31);
  1546.     state->cursor1      = VGA_RD08(chip->PCIO, 0x03D5);
  1547.     state->cursor2      = chip->PRAMDAC[0x00000300/4];
  1548.     state->vpll         = chip->PRAMDAC[0x00000508/4];
  1549.     state->pllsel       = chip->PRAMDAC[0x0000050C/4];
  1550.     state->general      = chip->PRAMDAC[0x00000600/4];
  1551.     state->config       = chip->PFB[0x00000200/4];
  1552.     switch (chip->Architecture)
  1553.     {
  1554.         case NV_ARCH_03:
  1555.             state->offset0  = chip->PGRAPH[0x00000630/4];
  1556.             state->offset1  = chip->PGRAPH[0x00000634/4];
  1557.             state->offset2  = chip->PGRAPH[0x00000638/4];
  1558.             state->offset3  = chip->PGRAPH[0x0000063C/4];
  1559.             state->pitch0   = chip->PGRAPH[0x00000650/4];
  1560.             state->pitch1   = chip->PGRAPH[0x00000654/4];
  1561.             state->pitch2   = chip->PGRAPH[0x00000658/4];
  1562.             state->pitch3   = chip->PGRAPH[0x0000065C/4];
  1563.             break;
  1564.         case NV_ARCH_04:
  1565.             state->offset0  = chip->PGRAPH[0x00000640/4];
  1566.             state->offset1  = chip->PGRAPH[0x00000644/4];
  1567.             state->offset2  = chip->PGRAPH[0x00000648/4];
  1568.             state->offset3  = chip->PGRAPH[0x0000064C/4];
  1569.             state->pitch0   = chip->PGRAPH[0x00000670/4];
  1570.             state->pitch1   = chip->PGRAPH[0x00000674/4];
  1571.             state->pitch2   = chip->PGRAPH[0x00000678/4];
  1572.             state->pitch3   = chip->PGRAPH[0x0000067C/4];
  1573.             break;
  1574.         case NV_ARCH_10:
  1575. case NV_ARCH_20:
  1576.             state->offset0  = chip->PGRAPH[0x00000640/4];
  1577.             state->offset1  = chip->PGRAPH[0x00000644/4];
  1578.             state->offset2  = chip->PGRAPH[0x00000648/4];
  1579.             state->offset3  = chip->PGRAPH[0x0000064C/4];
  1580.             state->pitch0   = chip->PGRAPH[0x00000670/4];
  1581.             state->pitch1   = chip->PGRAPH[0x00000674/4];
  1582.             state->pitch2   = chip->PGRAPH[0x00000678/4];
  1583.             state->pitch3   = chip->PGRAPH[0x0000067C/4];
  1584.             break;
  1585.     }
  1586. }
  1587. static void SetStartAddress
  1588. (
  1589.     RIVA_HW_INST *chip,
  1590.     unsigned      start
  1591. )
  1592. {
  1593.     int offset = start >> 2;
  1594.     int pan    = (start & 3) << 1;
  1595.     unsigned char tmp;
  1596.     /*
  1597.      * Unlock extended registers.
  1598.      */
  1599.     chip->LockUnlock(chip, 0);
  1600.     /*
  1601.      * Set start address.
  1602.      */
  1603.     VGA_WR08(chip->PCIO, 0x3D4, 0x0D); VGA_WR08(chip->PCIO, 0x3D5, offset);
  1604.     offset >>= 8;
  1605.     VGA_WR08(chip->PCIO, 0x3D4, 0x0C); VGA_WR08(chip->PCIO, 0x3D5, offset);
  1606.     offset >>= 8;
  1607.     VGA_WR08(chip->PCIO, 0x3D4, 0x19); tmp = VGA_RD08(chip->PCIO, 0x3D5);
  1608.     VGA_WR08(chip->PCIO, 0x3D5, (offset & 0x01F) | (tmp & ~0x1F));
  1609.     VGA_WR08(chip->PCIO, 0x3D4, 0x2D); tmp = VGA_RD08(chip->PCIO, 0x3D5);
  1610.     VGA_WR08(chip->PCIO, 0x3D5, (offset & 0x60) | (tmp & ~0x60));
  1611.     /*
  1612.      * 4 pixel pan register.
  1613.      */
  1614.     offset = VGA_RD08(chip->PCIO, chip->IO + 0x0A);
  1615.     VGA_WR08(chip->PCIO, 0x3C0, 0x13);
  1616.     VGA_WR08(chip->PCIO, 0x3C0, pan);
  1617. }
  1618. static void nv3SetSurfaces2D
  1619. (
  1620.     RIVA_HW_INST *chip,
  1621.     unsigned     surf0,
  1622.     unsigned     surf1
  1623. )
  1624. {
  1625.     RivaSurface *Surface = (RivaSurface *)&(chip->FIFO[0x0000E000/4]);
  1626.     RIVA_FIFO_FREE(*chip,Tri03,5);
  1627.     chip->FIFO[0x00003800] = 0x80000003;
  1628.     Surface->Offset        = surf0;
  1629.     chip->FIFO[0x00003800] = 0x80000004;
  1630.     Surface->Offset        = surf1;
  1631.     chip->FIFO[0x00003800] = 0x80000013;
  1632. }
  1633. static void nv4SetSurfaces2D
  1634. (
  1635.     RIVA_HW_INST *chip,
  1636.     unsigned     surf0,
  1637.     unsigned     surf1
  1638. )
  1639. {
  1640.     RivaSurface *Surface = (RivaSurface *)&(chip->FIFO[0x0000E000/4]);
  1641.     chip->FIFO[0x00003800] = 0x80000003;
  1642.     Surface->Offset        = surf0;
  1643.     chip->FIFO[0x00003800] = 0x80000004;
  1644.     Surface->Offset        = surf1;
  1645.     chip->FIFO[0x00003800] = 0x80000014;
  1646. }
  1647. static void nv10SetSurfaces2D
  1648. (
  1649.     RIVA_HW_INST *chip,
  1650.     unsigned     surf0,
  1651.     unsigned     surf1
  1652. )
  1653. {
  1654.     RivaSurface *Surface = (RivaSurface *)&(chip->FIFO[0x0000E000/4]);
  1655.     chip->FIFO[0x00003800] = 0x80000003;
  1656.     Surface->Offset        = surf0;
  1657.     chip->FIFO[0x00003800] = 0x80000004;
  1658.     Surface->Offset        = surf1;
  1659.     chip->FIFO[0x00003800] = 0x80000014;
  1660. }
  1661. static void nv3SetSurfaces3D
  1662. (
  1663.     RIVA_HW_INST *chip,
  1664.     unsigned     surf0,
  1665.     unsigned     surf1
  1666. )
  1667. {
  1668.     RivaSurface *Surface = (RivaSurface *)&(chip->FIFO[0x0000E000/4]);
  1669.     RIVA_FIFO_FREE(*chip,Tri03,5);
  1670.     chip->FIFO[0x00003800] = 0x80000005;
  1671.     Surface->Offset        = surf0;
  1672.     chip->FIFO[0x00003800] = 0x80000006;
  1673.     Surface->Offset        = surf1;
  1674.     chip->FIFO[0x00003800] = 0x80000013;
  1675. }
  1676. static void nv4SetSurfaces3D
  1677. (
  1678.     RIVA_HW_INST *chip,
  1679.     unsigned     surf0,
  1680.     unsigned     surf1
  1681. )
  1682. {
  1683.     RivaSurface *Surface = (RivaSurface *)&(chip->FIFO[0x0000E000/4]);
  1684.     chip->FIFO[0x00003800] = 0x80000005;
  1685.     Surface->Offset        = surf0;
  1686.     chip->FIFO[0x00003800] = 0x80000006;
  1687.     Surface->Offset        = surf1;
  1688.     chip->FIFO[0x00003800] = 0x80000014;
  1689. }
  1690. static void nv10SetSurfaces3D
  1691. (
  1692.     RIVA_HW_INST *chip,
  1693.     unsigned     surf0,
  1694.     unsigned     surf1
  1695. )
  1696. {
  1697.     RivaSurface3D *Surfaces3D = (RivaSurface3D *)&(chip->FIFO[0x0000E000/4]);
  1698.     RIVA_FIFO_FREE(*chip,Tri03,4);
  1699.     chip->FIFO[0x00003800]         = 0x80000007;
  1700.     Surfaces3D->RenderBufferOffset = surf0;
  1701.     Surfaces3D->ZBufferOffset      = surf1;
  1702.     chip->FIFO[0x00003800]         = 0x80000014;
  1703. }
  1704. /****************************************************************************
  1705. *                                                                            *
  1706. *                      Probe RIVA Chip Configuration                         *
  1707. *                                                                            *
  1708. ****************************************************************************/
  1709. static void nv3GetConfig
  1710. (
  1711.     RIVA_HW_INST *chip
  1712. )
  1713. {
  1714.     /*
  1715.      * Fill in chip configuration.
  1716.      */
  1717.     if (chip->PFB[0x00000000/4] & 0x00000020)
  1718.     {
  1719.         if (((chip->PMC[0x00000000/4] & 0xF0) == 0x20)
  1720.          && ((chip->PMC[0x00000000/4] & 0x0F) >= 0x02))
  1721.         {        
  1722.             /*
  1723.              * SDRAM 128 ZX.
  1724.              */
  1725.             chip->RamBandwidthKBytesPerSec = 800000;
  1726.             switch (chip->PFB[0x00000000/4] & 0x03)
  1727.             {
  1728.                 case 2:
  1729.                     chip->RamAmountKBytes = 1024 * 4;
  1730.                     break;
  1731.                 case 1:
  1732.                     chip->RamAmountKBytes = 1024 * 2;
  1733.                     break;
  1734.                 default:
  1735.                     chip->RamAmountKBytes = 1024 * 8;
  1736.                     break;
  1737.             }
  1738.         }            
  1739.         else            
  1740.         {
  1741.             chip->RamBandwidthKBytesPerSec = 1000000;
  1742.             chip->RamAmountKBytes          = 1024 * 8;
  1743.         }            
  1744.     }
  1745.     else
  1746.     {
  1747.         /*
  1748.          * SGRAM 128.
  1749.          */
  1750.         chip->RamBandwidthKBytesPerSec = 1000000;
  1751.         switch (chip->PFB[0x00000000/4] & 0x00000003)
  1752.         {
  1753.             case 0:
  1754.                 chip->RamAmountKBytes = 1024 * 8;
  1755.                 break;
  1756.             case 2:
  1757.                 chip->RamAmountKBytes = 1024 * 4;
  1758.                 break;
  1759.             default:
  1760.                 chip->RamAmountKBytes = 1024 * 2;
  1761.                 break;
  1762.         }
  1763.     }        
  1764.     chip->CrystalFreqKHz   = (chip->PEXTDEV[0x00000000/4] & 0x00000020) ? 14318 : 13500;
  1765.     chip->CURSOR           = &(chip->PRAMIN[0x00008000/4 - 0x0800/4]);
  1766.     chip->CURSORPOS        = &(chip->PRAMDAC[0x0300/4]);
  1767.     chip->VBLANKENABLE     = &(chip->PGRAPH[0x0140/4]);
  1768.     chip->VBLANK           = &(chip->PGRAPH[0x0100/4]);
  1769.     chip->VBlankBit        = 0x00000100;
  1770.     chip->MaxVClockFreqKHz = 256000;
  1771.     /*
  1772.      * Set chip functions.
  1773.      */
  1774.     chip->Busy            = nv3Busy;
  1775.     chip->ShowHideCursor  = ShowHideCursor;
  1776.     chip->CalcStateExt    = CalcStateExt;
  1777.     chip->LoadStateExt    = LoadStateExt;
  1778.     chip->UnloadStateExt  = UnloadStateExt;
  1779.     chip->SetStartAddress = SetStartAddress;
  1780.     chip->SetSurfaces2D   = nv3SetSurfaces2D;
  1781.     chip->SetSurfaces3D   = nv3SetSurfaces3D;
  1782.     chip->LockUnlock      = nv3LockUnlock;
  1783. }
  1784. static void nv4GetConfig
  1785. (
  1786.     RIVA_HW_INST *chip
  1787. )
  1788. {
  1789.     /*
  1790.      * Fill in chip configuration.
  1791.      */
  1792.     if (chip->PFB[0x00000000/4] & 0x00000100)
  1793.     {
  1794.         chip->RamAmountKBytes = ((chip->PFB[0x00000000/4] >> 12) & 0x0F) * 1024 * 2
  1795.                               + 1024 * 2;
  1796.     }
  1797.     else
  1798.     {
  1799.         switch (chip->PFB[0x00000000/4] & 0x00000003)
  1800.         {
  1801.             case 0:
  1802.                 chip->RamAmountKBytes = 1024 * 32;
  1803.                 break;
  1804.             case 1:
  1805.                 chip->RamAmountKBytes = 1024 * 4;
  1806.                 break;
  1807.             case 2:
  1808.                 chip->RamAmountKBytes = 1024 * 8;
  1809.                 break;
  1810.             case 3:
  1811.             default:
  1812.                 chip->RamAmountKBytes = 1024 * 16;
  1813.                 break;
  1814.         }
  1815.     }
  1816.     switch ((chip->PFB[0x00000000/4] >> 3) & 0x00000003)
  1817.     {
  1818.         case 3:
  1819.             chip->RamBandwidthKBytesPerSec = 800000;
  1820.             break;
  1821.         default:
  1822.             chip->RamBandwidthKBytesPerSec = 1000000;
  1823.             break;
  1824.     }
  1825.     chip->CrystalFreqKHz   = (chip->PEXTDEV[0x00000000/4] & 0x00000040) ? 14318 : 13500;
  1826.     chip->CURSOR           = &(chip->PRAMIN[0x00010000/4 - 0x0800/4]);
  1827.     chip->CURSORPOS        = &(chip->PRAMDAC[0x0300/4]);
  1828.     chip->VBLANKENABLE     = &(chip->PCRTC[0x0140/4]);
  1829.     chip->VBLANK           = &(chip->PCRTC[0x0100/4]);
  1830.     chip->VBlankBit        = 0x00000001;
  1831.     chip->MaxVClockFreqKHz = 350000;
  1832.     /*
  1833.      * Set chip functions.
  1834.      */
  1835.     chip->Busy            = nv4Busy;
  1836.     chip->ShowHideCursor  = ShowHideCursor;
  1837.     chip->CalcStateExt    = CalcStateExt;
  1838.     chip->LoadStateExt    = LoadStateExt;
  1839.     chip->UnloadStateExt  = UnloadStateExt;
  1840.     chip->SetStartAddress = SetStartAddress;
  1841.     chip->SetSurfaces2D   = nv4SetSurfaces2D;
  1842.     chip->SetSurfaces3D   = nv4SetSurfaces3D;
  1843.     chip->LockUnlock      = nv4LockUnlock;
  1844. }
  1845. static void nv10GetConfig
  1846. (
  1847.     RIVA_HW_INST *chip
  1848. )
  1849. {
  1850.     /*
  1851.      * Fill in chip configuration.
  1852.      */
  1853.     switch ((chip->PFB[0x0000020C/4] >> 20) & 0x000000FF)
  1854.     {
  1855.         case 0x02:
  1856.             chip->RamAmountKBytes = 1024 * 2;
  1857.             break;
  1858.         case 0x04:
  1859.             chip->RamAmountKBytes = 1024 * 4;
  1860.             break;
  1861.         case 0x08:
  1862.             chip->RamAmountKBytes = 1024 * 8;
  1863.             break;
  1864.         case 0x10:
  1865.             chip->RamAmountKBytes = 1024 * 16;
  1866.             break;
  1867.         case 0x20:
  1868.             chip->RamAmountKBytes = 1024 * 32;
  1869.             break;
  1870.         case 0x40:
  1871.             chip->RamAmountKBytes = 1024 * 64;
  1872.             break;
  1873.         case 0x80:
  1874.             chip->RamAmountKBytes = 1024 * 128;
  1875.             break;
  1876.         default:
  1877.             chip->RamAmountKBytes = 1024 * 16;
  1878.             break;
  1879.     }
  1880.     switch ((chip->PFB[0x00000000/4] >> 3) & 0x00000003)
  1881.     {
  1882.         case 3:
  1883.             chip->RamBandwidthKBytesPerSec = 800000;
  1884.             break;
  1885.         default:
  1886.             chip->RamBandwidthKBytesPerSec = 1000000;
  1887.             break;
  1888.     }
  1889.     chip->CrystalFreqKHz   = (chip->PEXTDEV[0x00000000/4] & 0x00000040) ? 14318 : 13500;
  1890.     chip->CURSOR           = &(chip->PRAMIN[0x00010000/4 - 0x0800/4]);
  1891.     chip->CURSORPOS        = &(chip->PRAMDAC[0x0300/4]);
  1892.     chip->VBLANKENABLE     = &(chip->PCRTC[0x0140/4]);
  1893.     chip->VBLANK           = &(chip->PCRTC[0x0100/4]);
  1894.     chip->VBlankBit        = 0x00000001;
  1895.     chip->MaxVClockFreqKHz = 350000;
  1896.     /*
  1897.      * Set chip functions.
  1898.      */
  1899.     chip->Busy            = nv10Busy;
  1900.     chip->ShowHideCursor  = ShowHideCursor;
  1901.     chip->CalcStateExt    = CalcStateExt;
  1902.     chip->LoadStateExt    = LoadStateExt;
  1903.     chip->UnloadStateExt  = UnloadStateExt;
  1904.     chip->SetStartAddress = SetStartAddress;
  1905.     chip->SetSurfaces2D   = nv10SetSurfaces2D;
  1906.     chip->SetSurfaces3D   = nv10SetSurfaces3D;
  1907.     chip->LockUnlock      = nv10LockUnlock;
  1908. }
  1909. int RivaGetConfig
  1910. (
  1911.     RIVA_HW_INST *chip
  1912. )
  1913. {
  1914.     /*
  1915.      * Save this so future SW know whats it's dealing with.
  1916.      */
  1917.     chip->Version = RIVA_SW_VERSION;
  1918.     /*
  1919.      * Chip specific configuration.
  1920.      */
  1921.     switch (chip->Architecture)
  1922.     {
  1923.         case NV_ARCH_03:
  1924.             nv3GetConfig(chip);
  1925.             break;
  1926.         case NV_ARCH_04:
  1927.             nv4GetConfig(chip);
  1928.             break;
  1929.         case NV_ARCH_10:
  1930. case NV_ARCH_20:
  1931.             nv10GetConfig(chip);
  1932.             break;
  1933.         default:
  1934.             return (-1);
  1935.     }
  1936.     /*
  1937.      * Fill in FIFO pointers.
  1938.      */
  1939.     chip->Rop    = (RivaRop                 *)&(chip->FIFO[0x00000000/4]);
  1940.     chip->Clip   = (RivaClip                *)&(chip->FIFO[0x00002000/4]);
  1941.     chip->Patt   = (RivaPattern             *)&(chip->FIFO[0x00004000/4]);
  1942.     chip->Pixmap = (RivaPixmap              *)&(chip->FIFO[0x00006000/4]);
  1943.     chip->Blt    = (RivaScreenBlt           *)&(chip->FIFO[0x00008000/4]);
  1944.     chip->Bitmap = (RivaBitmap              *)&(chip->FIFO[0x0000A000/4]);
  1945.     chip->Line   = (RivaLine                *)&(chip->FIFO[0x0000C000/4]);
  1946.     chip->Tri03  = (RivaTexturedTriangle03  *)&(chip->FIFO[0x0000E000/4]);
  1947.     return (0);
  1948. }