riva_hw.c 78 KB

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