riva_hw.c 78 KB

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