nvidia.c 32 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247
  1. /* Portions of this file derived from work with the following copyright */
  2. /***************************************************************************\
  3. |* *|
  4. |* Copyright 2003 NVIDIA, Corporation. All rights reserved. *|
  5. |* *|
  6. |* NOTICE TO USER: The source code is copyrighted under U.S. and *|
  7. |* international laws. Users and possessors of this source code are *|
  8. |* hereby granted a nonexclusive, royalty-free copyright license to *|
  9. |* use this code in individual and commercial software. *|
  10. |* *|
  11. |* Any use of this source code must include, in the user documenta- *|
  12. |* tion and internal comments to the code, notices to the end user *|
  13. |* as follows: *|
  14. |* *|
  15. |* Copyright 2003 NVIDIA, Corporation. All rights reserved. *|
  16. |* *|
  17. |* NVIDIA, CORPORATION MAKES NO REPRESENTATION ABOUT THE SUITABILITY *|
  18. |* OF THIS SOURCE CODE FOR ANY PURPOSE. IT IS PROVIDED "AS IS" *|
  19. |* WITHOUT EXPRESS OR IMPLIED WARRANTY OF ANY KIND. NVIDIA, CORPOR- *|
  20. |* ATION DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOURCE CODE, *|
  21. |* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGE- *|
  22. |* MENT, AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL *|
  23. |* NVIDIA, CORPORATION BE LIABLE FOR ANY SPECIAL, INDIRECT, INCI- *|
  24. |* DENTAL, OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RE- *|
  25. |* SULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION *|
  26. |* OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF *|
  27. |* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOURCE CODE. *|
  28. |* *|
  29. |* U.S. Government End Users. This source code is a "commercial *|
  30. |* item," as that term is defined at 48 C.F.R. 2.101 (OCT 1995), *|
  31. |* consisting of "commercial computer software" and "commercial *|
  32. |* computer software documentation," as such terms are used in *|
  33. |* 48 C.F.R. 12.212 (SEPT 1995) and is provided to the U.S. Govern- *|
  34. |* ment only as a commercial end item. Consistent with 48 C.F.R. *|
  35. |* 12.212 and 48 C.F.R. 227.7202-1 through 227.7202-4 (JUNE 1995), *|
  36. |* all U.S. Government End Users acquire the source code with only *|
  37. |* those rights set forth herein. *|
  38. |* *|
  39. \***************************************************************************/
  40. #include <u.h>
  41. #include <libc.h>
  42. #include <bio.h>
  43. #include "pci.h"
  44. #include "vga.h"
  45. typedef struct Nvidia Nvidia;
  46. struct Nvidia {
  47. Pcidev* pci;
  48. int did; /* not always == pci->did */
  49. int arch;
  50. int crystalfreq;
  51. ulong* mmio;
  52. ulong* pfb; /* mmio pointers */
  53. ulong* pramdac;
  54. ulong* pextdev;
  55. ulong* pmc;
  56. ulong* ptimer;
  57. ulong* pfifo;
  58. ulong* pramin;
  59. ulong* pgraph;
  60. ulong* fifo;
  61. ulong* pcrtc;
  62. ushort repaint0;
  63. ushort repaint1;
  64. ushort screen;
  65. ushort pixel;
  66. ushort horiz;
  67. ushort cursor0;
  68. ushort cursor1;
  69. ushort cursor2;
  70. ushort interlace;
  71. ushort extra;
  72. ushort crtcowner;
  73. ushort timingH;
  74. ushort timingV;
  75. ulong vpll;
  76. ulong vpllB;
  77. ulong vpll2;
  78. ulong vpll2B;
  79. ulong pllsel;
  80. ulong general;
  81. ulong scale;
  82. ulong config;
  83. ulong head;
  84. ulong head2;
  85. ulong cursorconfig;
  86. ulong dither;
  87. ulong crtcsync;
  88. ulong displayV;
  89. int islcd;
  90. int fpwidth;
  91. int fpheight;
  92. int twoheads;
  93. int twostagepll;
  94. int crtcnumber;
  95. };
  96. static void
  97. getpcixdid(Nvidia* nv)
  98. {
  99. ulong pcicmd, pciid;
  100. ushort vid, did;
  101. pcicmd = pcicfgr32(nv->pci, PciPCR);
  102. pcicfgw32(nv->pci, PciPCR, pcicmd | 0x02);
  103. pciid = nv->mmio[0x1800/4];
  104. pcicfgw32(nv->pci, PciPCR, pcicmd);
  105. vid = pciid >> 16;
  106. did = (pciid & 0xFFFF);
  107. if (did == 0x10DE)
  108. did = vid;
  109. else if (vid == 0xDE10)
  110. did = ((pciid << 8) & 0xFF00) | ((pciid >> 8) & 0x00FF);
  111. nv->did = did;
  112. }
  113. static void
  114. snarf(Vga* vga, Ctlr* ctlr)
  115. {
  116. Nvidia *nv;
  117. Pcidev *p;
  118. ulong *mmio, tmp;
  119. int implementation;
  120. if(vga->private == nil){
  121. vga->private = alloc(sizeof(Nvidia));
  122. nv = vga->private;
  123. p = nil;
  124. while((p = pcimatch(p, 0x10DE, 0)) != nil){
  125. if((p->ccru>>8) == 3)
  126. break;
  127. }
  128. if(p == nil)
  129. error("%s: not found\n", ctlr->name);
  130. vgactlw("type", ctlr->name);
  131. mmio = segattach(0, "nvidiammio", 0, p->mem[0].size);
  132. if(mmio == (void*)-1)
  133. error("%s: segattach nvidiammio, size %d: %r\n",
  134. ctlr->name, p->mem[0].size);
  135. nv->pci = p;
  136. nv->mmio = mmio;
  137. nv->pfb = mmio+0x00100000/4;
  138. nv->pramdac = mmio+0x00680000/4;
  139. nv->pextdev = mmio+0x00101000/4;
  140. nv->pmc = mmio+0x00000000/4;
  141. nv->ptimer = mmio+0x00009000/4;
  142. nv->pfifo = mmio+0x00002000/4;
  143. nv->pramin = mmio+0x00710000/4;
  144. nv->pgraph = mmio+0x00400000/4;
  145. nv->fifo = mmio+0x00800000/4;
  146. nv->pcrtc= mmio+0x00600000/4;
  147. nv->did = p->did;
  148. if ((nv->did & 0xfff0) == 0x00f0)
  149. getpcixdid(nv);
  150. switch (nv->did & 0x0ff0) {
  151. case 0x0020:
  152. case 0x00A0:
  153. nv->arch = 4;
  154. break;
  155. case 0x0100: /* GeForce 256 */
  156. case 0x0110: /* GeForce2 MX */
  157. case 0x0150: /* GeForce2 */
  158. case 0x0170: /* GeForce4 MX */
  159. case 0x0180: /* GeForce4 MX (8x AGP) */
  160. case 0x01A0: /* nForce */
  161. case 0x01F0: /* nForce2 */
  162. nv->arch = 10;
  163. break;
  164. case 0x0200: /* GeForce3 */
  165. case 0x0250: /* GeForce4 Ti */
  166. case 0x0280: /* GeForce4 Ti (8x AGP) */
  167. nv->arch = 20;
  168. break;
  169. case 0x0300: /* GeForceFX 5800 */
  170. case 0x0310: /* GeForceFX 5600 */
  171. case 0x0320: /* GeForceFX 5200 */
  172. case 0x0330: /* GeForceFX 5900 */
  173. case 0x0340: /* GeForceFX 5700 */
  174. nv->arch = 30;
  175. break;
  176. case 0x0040:
  177. case 0x00C0:
  178. case 0x0120:
  179. case 0x0130:
  180. case 0x0140: /* GeForce 6600 */
  181. case 0x0160:
  182. case 0x01D0:
  183. case 0x0090:
  184. case 0x0210:
  185. case 0x0290: /* nvidia 7950*/
  186. nv->arch = 40;
  187. break;
  188. default:
  189. error("%s: DID %#4.4ux - %#ux unsupported\n",
  190. ctlr->name, nv->did, (nv->did & 0x0ff0));
  191. break;
  192. }
  193. }
  194. nv = vga->private;
  195. implementation = nv->did & 0x0ff0;
  196. /*
  197. * Unlock
  198. */
  199. vgaxo(Crtx, 0x1F, 0x57);
  200. if (nv->pextdev[0x00000000] & 0x00000040)
  201. nv->crystalfreq = RefFreq;
  202. else
  203. nv->crystalfreq = 13500000;
  204. if ((implementation == 0x0170) ||
  205. (implementation == 0x0180) ||
  206. (implementation == 0x01F0) ||
  207. (implementation >= 0x0250))
  208. if(nv->pextdev[0x00000000] & (1 << 22))
  209. nv->crystalfreq = 27000000;
  210. nv->twoheads = (nv->arch >= 10) &&
  211. (implementation != 0x0100) &&
  212. (implementation != 0x0150) &&
  213. (implementation != 0x01A0) &&
  214. (implementation != 0x0200);
  215. nv->twostagepll = (implementation == 0x0310) ||
  216. (implementation == 0x0340) ||
  217. (nv->arch >= 40);
  218. if (nv->twoheads && (implementation != 0x0110))
  219. if(nv->pextdev[0x00000000] & (1 << 22))
  220. nv->crystalfreq = 27000000;
  221. /* laptop chips */
  222. switch (nv->did & 0xffff) {
  223. case 0x0112:
  224. case 0x0174:
  225. case 0x0175:
  226. case 0x0176:
  227. case 0x0177:
  228. case 0x0179:
  229. case 0x017C:
  230. case 0x017D:
  231. case 0x0186:
  232. case 0x0187:
  233. case 0x0189: /* 0x0189 not in nwaples's driver */
  234. case 0x018D:
  235. case 0x0286:
  236. case 0x028C:
  237. case 0x0316:
  238. case 0x0317:
  239. case 0x031A:
  240. case 0x031B:
  241. case 0x031C:
  242. case 0x031D:
  243. case 0x031E:
  244. case 0x031F:
  245. case 0x0324:
  246. case 0x0325:
  247. case 0x0328:
  248. case 0x0329:
  249. case 0x032C:
  250. case 0x032D:
  251. case 0x0347:
  252. case 0x0348:
  253. case 0x0349:
  254. case 0x034B:
  255. case 0x034C:
  256. case 0x0160:
  257. case 0x0166:
  258. case 0x00C8:
  259. case 0x00CC:
  260. case 0x0144:
  261. case 0x0146:
  262. case 0x0148:
  263. nv->islcd = 1;
  264. break;
  265. default:
  266. break;
  267. }
  268. if (nv->arch == 4) {
  269. tmp = nv->pfb[0x00000000];
  270. if (tmp & 0x0100) {
  271. vga->vmz = ((tmp >> 12) & 0x0F) * 1024 + 1024 * 2;
  272. } else {
  273. tmp &= 0x03;
  274. if (tmp)
  275. vga->vmz = (1024*1024*2) << tmp;
  276. else
  277. vga->vmz = 1024*1024*32;
  278. }
  279. } else if (implementation == 0x01a0) {
  280. p = nil;
  281. tmp = MKBUS(BusPCI, 0, 0, 1);
  282. while((p = pcimatch(p, 0x10DE, 0)) != nil){
  283. if(p->tbdf == tmp)
  284. break;
  285. }
  286. tmp = pcicfgr32(p, 0x7C);
  287. vga->vmz = (((tmp >> 6) & 31) + 1) * 1024 * 1024;
  288. } else if (implementation == 0x01f0) {
  289. p = nil;
  290. tmp = MKBUS(BusPCI, 0, 0, 1);
  291. while((p = pcimatch(p, 0x10DE, 0)) != nil){
  292. if(p->tbdf == tmp)
  293. break;
  294. }
  295. tmp = pcicfgr32(p, 0x84);
  296. vga->vmz = (((tmp >> 4) & 127) + 1) * 1024 * 1024;
  297. } else {
  298. tmp = (nv->pfb[0x0000020C/4] >> 20) & 0xFFF;
  299. if (tmp == 0)
  300. tmp = 16;
  301. vga->vmz = 1024*1024*tmp;
  302. }
  303. nv->repaint0 = vgaxi(Crtx, 0x19);
  304. nv->repaint1 = vgaxi(Crtx, 0x1A);
  305. nv->screen = vgaxi(Crtx, 0x25);
  306. nv->pixel = vgaxi(Crtx, 0x28);
  307. nv->horiz = vgaxi(Crtx, 0x2D);
  308. nv->cursor0 = vgaxi(Crtx, 0x30);
  309. nv->cursor1 = vgaxi(Crtx, 0x31);
  310. nv->cursor2 = vgaxi(Crtx, 0x2F);
  311. nv->interlace = vgaxi(Crtx, 0x39);
  312. nv->vpll = nv->pramdac[0x00000508/4];
  313. if (nv->twoheads)
  314. nv->vpll2 = nv->pramdac[0x00000520/4];
  315. if (nv->twostagepll) {
  316. nv->vpllB = nv->pramdac[0x00000578/4];
  317. nv->vpll2B = nv->pramdac[0x0000057C/4];
  318. }
  319. nv->pllsel = nv->pramdac[0x0000050C/4];
  320. nv->general = nv->pramdac[0x00000600/4];
  321. nv->scale = nv->pramdac[0x00000848/4];
  322. nv->config = nv->pfb[0x00000200/4];
  323. if (nv->pixel & 0x80){
  324. nv->islcd = 1;
  325. }
  326. if (nv->arch >= 10) {
  327. if (nv->twoheads) {
  328. nv->head = nv->pcrtc[0x0860/4];
  329. nv->head2 = nv->pcrtc[0x2860/4];
  330. nv->crtcowner = vgaxi(Crtx, 0x44);
  331. }
  332. nv->extra = vgaxi(Crtx, 0x41);
  333. nv->cursorconfig = nv->pcrtc[0x0810/4];
  334. if (implementation == 0x0110)
  335. nv->dither = nv->pramdac[0x0528/4];
  336. else if (nv->twoheads)
  337. nv->dither = nv->pramdac[0x083C/4];
  338. }
  339. /*
  340. * DFP.
  341. */
  342. if (nv->islcd) {
  343. nv->fpwidth = nv->pramdac[0x0820/4] + 1;
  344. nv->fpheight = nv->pramdac[0x0800/4] + 1;
  345. nv->crtcsync = nv->pramdac[0x0828/4];
  346. }
  347. nv->crtcnumber = 0;
  348. ctlr->flag |= Fsnarf;
  349. }
  350. static void
  351. options(Vga*, Ctlr* ctlr)
  352. {
  353. ctlr->flag |= Hlinear|Foptions;
  354. }
  355. static void
  356. clock(Vga* vga, Ctlr* ctlr)
  357. {
  358. int m, n, p, f, d;
  359. Nvidia *nv;
  360. double trouble;
  361. int fmin, mmin, nmin, crystalfreq;
  362. nv = vga->private;
  363. if(vga->f[0] == 0)
  364. vga->f[0] = vga->mode->frequency;
  365. vga->d[0] = vga->f[0]+1;
  366. vga->n[1] = 255;
  367. if (nv->twostagepll) {
  368. vga->p[1] = 6;
  369. vga->m[1] = 13;
  370. vga->f[1] = 400000000 << 2;
  371. crystalfreq = nv->crystalfreq << 2;
  372. fmin = 100000000 << 2;
  373. mmin = 1;
  374. nmin = 5;
  375. nv->vpllB = 0x80000401;
  376. } else {
  377. vga->p[1] = 4;
  378. if (nv->crystalfreq == 13500000)
  379. vga->m[1] = 13;
  380. else
  381. vga->m[1] = 14;
  382. vga->f[1] = 350000000;
  383. crystalfreq = nv->crystalfreq;
  384. fmin = 128000000;
  385. mmin = 7;
  386. nmin = 0;
  387. }
  388. for (p=0; p <= vga->p[1]; p++){
  389. f = vga->f[0] << p;
  390. if ((f >= fmin) && (f <= vga->f[1])) {
  391. for (m=mmin; m <= vga->m[1]; m++){
  392. trouble = (double) crystalfreq / (double) (m << p);
  393. n = (vga->f[0] / trouble)+0.5;
  394. f = n*trouble + 0.5;
  395. d = vga->f[0] - f;
  396. if (d < 0)
  397. d = -d;
  398. if ((n & ~0xFF) && (n >= nmin))
  399. d = vga->d[0] + 1;
  400. if (d <= vga->d[0]){
  401. vga->n[0] = n;
  402. vga->m[0] = m;
  403. vga->p[0] = p;
  404. vga->d[0] = d;
  405. }
  406. }
  407. }
  408. }
  409. if (vga->d[0] > vga->f[0])
  410. error("%s: vclk %lud out of range\n", ctlr->name, vga->f[0]);
  411. }
  412. static void
  413. init(Vga* vga, Ctlr* ctlr)
  414. {
  415. Mode *mode;
  416. Nvidia *nv;
  417. char *p, *val;
  418. int tmp, pixeldepth;
  419. ulong cursorstart;
  420. mode = vga->mode;
  421. if(mode->z == 24)
  422. error("%s: 24-bit colour not supported, use 32-bit\n", ctlr->name);
  423. nv = vga->private;
  424. if(vga->linear && (ctlr->flag & Hlinear))
  425. ctlr->flag |= Ulinear;
  426. clock(vga, ctlr);
  427. if(val = dbattr(vga->mode->attr, "lcd")){
  428. if((nv->islcd = strtol(val, &p, 0)) == 0 && p == val)
  429. error("%s: invalid 'lcd' attr\n", ctlr->name);
  430. }
  431. if(nv->arch == 4) {
  432. nv->cursor0 = 0x00;
  433. nv->cursor1 = 0xBC;
  434. nv->cursor2 = 0;
  435. nv->config = 0x00001114;
  436. } else if(nv->arch >= 10) {
  437. cursorstart = vga->vmz - 96 * 1024;
  438. nv->cursor0 = 0x80 | (cursorstart >> 17);
  439. nv->cursor1 = (cursorstart >> 11) << 2;
  440. nv->cursor2 = cursorstart >> 24;
  441. nv->config = nv->pfb[0x200/4];
  442. }
  443. nv->vpll = (vga->p[0] << 16) | (vga->n[0] << 8) | vga->m[0];
  444. nv->pllsel = 0x10000700;
  445. if (mode->z == 16)
  446. nv->general = 0x00001100;
  447. else
  448. nv->general = 0x00000100;
  449. //if (mode->z != 8)
  450. // nv->general |= 0x00000030;
  451. if (mode->x < 1280)
  452. nv->repaint1 = 0x04;
  453. else
  454. nv->repaint1 = 0;
  455. vga->attribute[0x10] &= ~0x40;
  456. vga->attribute[0x11] = Pblack;
  457. vga->crt[0x14] = 0x00;
  458. /* set vert blanking to cover full overscan */
  459. tmp = vga->crt[0x12];
  460. vga->crt[0x15] = tmp;
  461. if(tmp & 0x100)
  462. vga->crt[0x07] |= 0x08;
  463. else
  464. vga->crt[0x07] &= ~0x08;
  465. if(tmp & 0x200)
  466. vga->crt[0x09] |= 0x20;
  467. else
  468. vga->crt[0x09] &= ~0x20;
  469. vga->crt[0x16] = vga->crt[0x06] + 1;
  470. /* set horiz blanking to cover full overscan */
  471. vga->crt[0x02] = vga->crt[0x01];
  472. tmp = vga->crt[0x00] + 4;
  473. vga->crt[0x03] = 0x80 | (tmp & 0x1F);
  474. if (tmp & 0x20)
  475. vga->crt[0x05] |= 0x80;
  476. else
  477. vga->crt[0x05] &= ~0x80;
  478. if (tmp & 0x40)
  479. nv->screen = 0x10;
  480. else
  481. nv->screen = 0x00;
  482. /* overflow bits */
  483. if (nv->islcd){
  484. tmp = vga->crt[0x06] - 3;
  485. vga->crt[0x10] = tmp;
  486. if(tmp & 0x100)
  487. vga->crt[0x07] |= 0x04;
  488. else
  489. vga->crt[0x07] &= ~0x04;
  490. if(tmp & 0x200)
  491. vga->crt[0x07] |= 0x80;
  492. else
  493. vga->crt[0x07] &= ~0x80;
  494. vga->crt[0x11] = 0x20 | ((vga->crt[0x06] - 2) & 0x0F);
  495. tmp = vga->crt[0x10];
  496. vga->crt[0x15] = tmp;
  497. if(tmp & 0x100)
  498. vga->crt[0x07] |= 0x08;
  499. else
  500. vga->crt[0x07] &= ~0x08;
  501. if(tmp & 0x200)
  502. vga->crt[0x09] |= 0x20;
  503. else
  504. vga->crt[0x09] &= ~0x20;
  505. vga->crt[0x04] = vga->crt[0x00] - 5;
  506. vga->crt[0x05] &= ~0x1F;
  507. vga->crt[0x05] |= (0x1F & (vga->crt[0x00] - 2));
  508. }
  509. nv->repaint0 = (vga->crt[0x13] & 0x0700) >> 3;
  510. pixeldepth = (mode->z +1)/8;
  511. if (pixeldepth > 3)
  512. nv->pixel = 3;
  513. else
  514. nv->pixel = pixeldepth;
  515. nv->scale &= 0xFFF000FF;
  516. if(nv->islcd){
  517. nv->pixel |= 0x80;
  518. nv->scale |= 0x100;
  519. }
  520. if (vga->crt[0x06] & 0x400)
  521. nv->screen |= 0x01;
  522. if (vga->crt[0x12] & 0x400)
  523. nv->screen |= 0x02;
  524. if (vga->crt[0x10] & 0x400)
  525. nv->screen |= 0x04;
  526. if (vga->crt[0x15] & 0x400)
  527. nv->screen |= 0x08;
  528. if (vga->crt[0x13] & 0x800)
  529. nv->screen |= 0x20;
  530. nv->horiz = 0x00;
  531. if (vga->crt[0x00] & 0x100)
  532. nv->horiz = 0x01;
  533. if(vga->crt[0x01] & 0x100)
  534. nv->horiz |= 0x02;
  535. if(vga->crt[0x02] & 0x100)
  536. nv->horiz |= 0x04;
  537. if(vga->crt[0x04] & 0x100)
  538. nv->horiz |= 0x08;
  539. nv->extra = 0x00;
  540. if (vga->crt[0x06] & 0x800)
  541. nv->extra |= 0x01;
  542. if (vga->crt[0x12] & 0x800)
  543. nv->extra |= 0x04;
  544. if (vga->crt[0x10] & 0x800)
  545. nv->extra |= 0x10;
  546. if (vga->crt[0x15] & 0x800)
  547. nv->extra |= 0x40;
  548. nv->interlace = 0xFF;
  549. if (nv->twoheads) {
  550. nv->head |= 0x00001000;
  551. nv->head2 |= ~0x00001000;
  552. nv->crtcowner = 0;
  553. if((nv->did & 0x0ff0) == 0x0110)
  554. nv->dither &= ~0x00010000;
  555. else
  556. nv->dither &= ~1;
  557. }
  558. nv->cursorconfig = 0x00000100 | 0x02000000;
  559. nv->timingH = 0;
  560. nv->timingV = 0;
  561. nv->displayV = vga->crt[0x12] + 1;
  562. ctlr->flag |= Finit;
  563. }
  564. static void
  565. load(Vga* vga, Ctlr* ctlr)
  566. {
  567. Nvidia *nv;
  568. int i, regions;
  569. ulong tmp;
  570. nv = vga->private;
  571. /*
  572. * Unlock
  573. */
  574. vgaxo(Crtx, 0x1F, 0x57);
  575. nv->pmc[0x0140/4] = 0x00000000;
  576. nv->pmc[0x0200/4] = 0xFFFF00FF;
  577. nv->pmc[0x0200/4] = 0xFFFFFFFF;
  578. nv->ptimer[0x0200] = 0x00000008;
  579. nv->ptimer[0x0210] = 0x00000003;
  580. nv->ptimer[0x0140] = 0x00000000;
  581. nv->ptimer[0x0100] = 0xFFFFFFFF;
  582. if (nv->arch == 4)
  583. nv->pfb[0x00000200/4] = nv->config;
  584. else if((nv->arch < 40) || ((nv->did & 0xfff0) == 0x0040)){
  585. for(i = 0; i < 8; i++){
  586. nv->pfb[(0x0240 + (i * 0x10))/4] = 0;
  587. nv->pfb[(0x0244 + (i * 0x10))/4] = vga->vmz - 1;;
  588. }
  589. }
  590. else{
  591. if(((nv->did & 0xfff0) == 0x0090)
  592. || ((nv->did & 0xfff0) == 0x01D0)
  593. || ((nv->did & 0xfff0) == 0x0290)
  594. || ((nv->did & 0xfff0) == 0x0390))
  595. regions = 15;
  596. else
  597. regions = 12;
  598. for(i = 0; i < regions; i++){
  599. nv->pfb[(0x0600 + (i * 0x10))/4] = 0;
  600. nv->pfb[(0x0604 + (i * 0x10))/4] = vga->vmz - 1;
  601. }
  602. }
  603. if (nv->arch >= 40) {
  604. nv->pramin[0x0000] = 0x80000010;
  605. nv->pramin[0x0001] = 0x00101202;
  606. nv->pramin[0x0002] = 0x80000011;
  607. nv->pramin[0x0003] = 0x00101204;
  608. nv->pramin[0x0004] = 0x80000012;
  609. nv->pramin[0x0005] = 0x00101206;
  610. nv->pramin[0x0006] = 0x80000013;
  611. nv->pramin[0x0007] = 0x00101208;
  612. nv->pramin[0x0008] = 0x80000014;
  613. nv->pramin[0x0009] = 0x0010120A;
  614. nv->pramin[0x000A] = 0x80000015;
  615. nv->pramin[0x000B] = 0x0010120C;
  616. nv->pramin[0x000C] = 0x80000016;
  617. nv->pramin[0x000D] = 0x0010120E;
  618. nv->pramin[0x000E] = 0x80000017;
  619. nv->pramin[0x000F] = 0x00101210;
  620. nv->pramin[0x0800] = 0x00003000;
  621. nv->pramin[0x0801] = vga->vmz - 1;
  622. nv->pramin[0x0802] = 0x00000002;
  623. nv->pramin[0x0808] = 0x02080062;
  624. nv->pramin[0x0809] = 0x00000000;
  625. nv->pramin[0x080A] = 0x00001200;
  626. nv->pramin[0x080B] = 0x00001200;
  627. nv->pramin[0x080C] = 0x00000000;
  628. nv->pramin[0x080D] = 0x00000000;
  629. nv->pramin[0x0810] = 0x02080043;
  630. nv->pramin[0x0811] = 0x00000000;
  631. nv->pramin[0x0812] = 0x00000000;
  632. nv->pramin[0x0813] = 0x00000000;
  633. nv->pramin[0x0814] = 0x00000000;
  634. nv->pramin[0x0815] = 0x00000000;
  635. nv->pramin[0x0818] = 0x02080044;
  636. nv->pramin[0x0819] = 0x02000000;
  637. nv->pramin[0x081A] = 0x00000000;
  638. nv->pramin[0x081B] = 0x00000000;
  639. nv->pramin[0x081C] = 0x00000000;
  640. nv->pramin[0x081D] = 0x00000000;
  641. nv->pramin[0x0820] = 0x02080019;
  642. nv->pramin[0x0821] = 0x00000000;
  643. nv->pramin[0x0822] = 0x00000000;
  644. nv->pramin[0x0823] = 0x00000000;
  645. nv->pramin[0x0824] = 0x00000000;
  646. nv->pramin[0x0825] = 0x00000000;
  647. nv->pramin[0x0828] = 0x020A005C;
  648. nv->pramin[0x0829] = 0x00000000;
  649. nv->pramin[0x082A] = 0x00000000;
  650. nv->pramin[0x082B] = 0x00000000;
  651. nv->pramin[0x082C] = 0x00000000;
  652. nv->pramin[0x082D] = 0x00000000;
  653. nv->pramin[0x0830] = 0x0208009F;
  654. nv->pramin[0x0831] = 0x00000000;
  655. nv->pramin[0x0832] = 0x00001200;
  656. nv->pramin[0x0833] = 0x00001200;
  657. nv->pramin[0x0834] = 0x00000000;
  658. nv->pramin[0x0835] = 0x00000000;
  659. nv->pramin[0x0838] = 0x0208004A;
  660. nv->pramin[0x0839] = 0x02000000;
  661. nv->pramin[0x083A] = 0x00000000;
  662. nv->pramin[0x083B] = 0x00000000;
  663. nv->pramin[0x083C] = 0x00000000;
  664. nv->pramin[0x083D] = 0x00000000;
  665. nv->pramin[0x0840] = 0x02080077;
  666. nv->pramin[0x0841] = 0x00000000;
  667. nv->pramin[0x0842] = 0x00001200;
  668. nv->pramin[0x0843] = 0x00001200;
  669. nv->pramin[0x0844] = 0x00000000;
  670. nv->pramin[0x0845] = 0x00000000;
  671. nv->pramin[0x084C] = 0x00003002;
  672. nv->pramin[0x084D] = 0x00007FFF;
  673. nv->pramin[0x084E] = (vga->vmz - 128 * 1024) | 0x00000002;
  674. } else {
  675. nv->pramin[0x0000] = 0x80000010;
  676. nv->pramin[0x0001] = 0x80011201;
  677. nv->pramin[0x0002] = 0x80000011;
  678. nv->pramin[0x0003] = 0x80011202;
  679. nv->pramin[0x0004] = 0x80000012;
  680. nv->pramin[0x0005] = 0x80011203;
  681. nv->pramin[0x0006] = 0x80000013;
  682. nv->pramin[0x0007] = 0x80011204;
  683. nv->pramin[0x0008] = 0x80000014;
  684. nv->pramin[0x0009] = 0x80011205;
  685. nv->pramin[0x000A] = 0x80000015;
  686. nv->pramin[0x000B] = 0x80011206;
  687. nv->pramin[0x000C] = 0x80000016;
  688. nv->pramin[0x000D] = 0x80011207;
  689. nv->pramin[0x000E] = 0x80000017;
  690. nv->pramin[0x000F] = 0x80011208;
  691. nv->pramin[0x0800] = 0x00003000;
  692. nv->pramin[0x0801] = vga->vmz - 1;
  693. nv->pramin[0x0802] = 0x00000002;
  694. nv->pramin[0x0803] = 0x00000002;
  695. if (nv->arch >= 10)
  696. nv->pramin[0x0804] = 0x01008062;
  697. else
  698. nv->pramin[0x0804] = 0x01008042;
  699. nv->pramin[0x0805] = 0x00000000;
  700. nv->pramin[0x0806] = 0x12001200;
  701. nv->pramin[0x0807] = 0x00000000;
  702. nv->pramin[0x0808] = 0x01008043;
  703. nv->pramin[0x0809] = 0x00000000;
  704. nv->pramin[0x080A] = 0x00000000;
  705. nv->pramin[0x080B] = 0x00000000;
  706. nv->pramin[0x080C] = 0x01008044;
  707. nv->pramin[0x080D] = 0x00000002;
  708. nv->pramin[0x080E] = 0x00000000;
  709. nv->pramin[0x080F] = 0x00000000;
  710. nv->pramin[0x0810] = 0x01008019;
  711. nv->pramin[0x0811] = 0x00000000;
  712. nv->pramin[0x0812] = 0x00000000;
  713. nv->pramin[0x0813] = 0x00000000;
  714. nv->pramin[0x0814] = 0x0100A05C;
  715. nv->pramin[0x0815] = 0x00000000;
  716. nv->pramin[0x0816] = 0x00000000;
  717. nv->pramin[0x0817] = 0x00000000;
  718. nv->pramin[0x0818] = 0x0100805F;
  719. nv->pramin[0x0819] = 0x00000000;
  720. nv->pramin[0x081A] = 0x12001200;
  721. nv->pramin[0x081B] = 0x00000000;
  722. nv->pramin[0x081C] = 0x0100804A;
  723. nv->pramin[0x081D] = 0x00000002;
  724. nv->pramin[0x081E] = 0x00000000;
  725. nv->pramin[0x081F] = 0x00000000;
  726. nv->pramin[0x0820] = 0x01018077;
  727. nv->pramin[0x0821] = 0x00000000;
  728. nv->pramin[0x0822] = 0x01201200;
  729. nv->pramin[0x0823] = 0x00000000;
  730. nv->pramin[0x0824] = 0x00003002;
  731. nv->pramin[0x0825] = 0x00007FFF;
  732. nv->pramin[0x0826] = (vga->vmz - 128 * 1024) | 0x00000002;
  733. nv->pramin[0x0827] = 0x00000002;
  734. }
  735. if (nv->arch < 10) {
  736. if((nv->did & 0x0fff) == 0x0020) {
  737. nv->pramin[0x0824] |= 0x00020000;
  738. nv->pramin[0x0826] += nv->pci->mem[1].bar;
  739. }
  740. nv->pgraph[0x0080/4] = 0x000001FF;
  741. nv->pgraph[0x0080/4] = 0x1230C000;
  742. nv->pgraph[0x0084/4] = 0x72111101;
  743. nv->pgraph[0x0088/4] = 0x11D5F071;
  744. nv->pgraph[0x008C/4] = 0x0004FF31;
  745. nv->pgraph[0x008C/4] = 0x4004FF31;
  746. nv->pgraph[0x0140/4] = 0x00000000;
  747. nv->pgraph[0x0100/4] = 0xFFFFFFFF;
  748. nv->pgraph[0x0170/4] = 0x10010100;
  749. nv->pgraph[0x0710/4] = 0xFFFFFFFF;
  750. nv->pgraph[0x0720/4] = 0x00000001;
  751. nv->pgraph[0x0810/4] = 0x00000000;
  752. nv->pgraph[0x0608/4] = 0xFFFFFFFF;
  753. } else {
  754. nv->pgraph[0x0080/4] = 0xFFFFFFFF;
  755. nv->pgraph[0x0080/4] = 0x00000000;
  756. nv->pgraph[0x0140/4] = 0x00000000;
  757. nv->pgraph[0x0100/4] = 0xFFFFFFFF;
  758. nv->pgraph[0x0144/4] = 0x10010100;
  759. nv->pgraph[0x0714/4] = 0xFFFFFFFF;
  760. nv->pgraph[0x0720/4] = 0x00000001;
  761. nv->pgraph[0x0710/4] &= 0x0007ff00;
  762. nv->pgraph[0x0710/4] |= 0x00020100;
  763. if (nv->arch == 10) {
  764. nv->pgraph[0x0084/4] = 0x00118700;
  765. nv->pgraph[0x0088/4] = 0x24E00810;
  766. nv->pgraph[0x008C/4] = 0x55DE0030;
  767. for(i = 0; i < 32; i++)
  768. nv->pgraph[(0x0B00/4) + i] = nv->pfb[(0x0240/4) + i];
  769. nv->pgraph[0x640/4] = 0;
  770. nv->pgraph[0x644/4] = 0;
  771. nv->pgraph[0x684/4] = vga->vmz - 1;
  772. nv->pgraph[0x688/4] = vga->vmz - 1;
  773. nv->pgraph[0x0810/4] = 0x00000000;
  774. nv->pgraph[0x0608/4] = 0xFFFFFFFF;
  775. } else {
  776. if (nv->arch >= 40) {
  777. nv->pgraph[0x0084/4] = 0x401287c0;
  778. nv->pgraph[0x008C/4] = 0x60de8051;
  779. nv->pgraph[0x0090/4] = 0x00008000;
  780. nv->pgraph[0x0610/4] = 0x00be3c5f;
  781. tmp = nv->pgraph[0x1540] & 0xff;
  782. for(i = 0; tmp && !(tmp & 1); tmp >>= 1, i++)
  783. ;
  784. nv->pgraph[0x5000] = i;
  785. if ((nv->did & 0xfff0) == 0x0040) {
  786. nv->pgraph[0x09b0/4] = 0x83280fff;
  787. nv->pgraph[0x09b4/4] = 0x000000a0;
  788. } else {
  789. nv->pgraph[0x0820/4] = 0x83280eff;
  790. nv->pgraph[0x0824/4] = 0x000000a0;
  791. }
  792. switch(nv->did & 0xfff0) {
  793. case 0x0040:
  794. nv->pgraph[0x09b8/4] = 0x0078e366;
  795. nv->pgraph[0x09bc/4] = 0x0000014c;
  796. nv->pfb[0x033C/4] &= 0xffff7fff;
  797. break;
  798. case 0x00C0:
  799. case 0x0120:
  800. nv->pgraph[0x0828/4] = 0x007596ff;
  801. nv->pgraph[0x082C/4] = 0x00000108;
  802. break;
  803. case 0x0160:
  804. case 0x01D0:
  805. case 0x0240:
  806. nv->pmc[0x1700/4] = nv->pfb[0x020C/4];
  807. nv->pmc[0x1704/4] = 0;
  808. nv->pmc[0x1708/4] = 0;
  809. nv->pmc[0x170C/4] = nv->pfb[0x020C/4];
  810. nv->pgraph[0x0860/4] = 0;
  811. nv->pgraph[0x0864/4] = 0;
  812. nv->pramdac[0x0608/4] |= 0x00100000;
  813. break;
  814. case 0x0140:
  815. nv->pgraph[0x0828/4] = 0x0072cb77;
  816. nv->pgraph[0x082C/4] = 0x00000108;
  817. break;
  818. case 0x0220:
  819. nv->pgraph[0x0860/4] = 0;
  820. nv->pgraph[0x0864/4] = 0;
  821. nv->pramdac[0x0608/4] |= 0x00100000;
  822. break;
  823. case 0x0090:
  824. case 0x0290:
  825. case 0x0390:
  826. nv->pgraph[0x0608/4] |= 0x00100000;
  827. nv->pgraph[0x0828/4] = 0x07830610;
  828. nv->pgraph[0x082C/4] = 0x0000016A;
  829. break;
  830. default:
  831. break;
  832. }
  833. nv->pgraph[0x0b38/4] = 0x2ffff800;
  834. nv->pgraph[0x0b3c/4] = 0x00006000;
  835. nv->pgraph[0x032C/4] = 0x01000000;
  836. nv->pgraph[0x0220/4] = 0x00001200;
  837. } else if (nv->arch == 30) {
  838. nv->pgraph[0x0084/4] = 0x40108700;
  839. nv->pgraph[0x0890/4] = 0x00140000;
  840. nv->pgraph[0x008C/4] = 0xf00e0431;
  841. nv->pgraph[0x0090/4] = 0x00008000;
  842. nv->pgraph[0x0610/4] = 0xf04b1f36;
  843. nv->pgraph[0x0B80/4] = 0x1002d888;
  844. nv->pgraph[0x0B88/4] = 0x62ff007f;
  845. } else {
  846. nv->pgraph[0x0084/4] = 0x00118700;
  847. nv->pgraph[0x008C/4] = 0xF20E0431;
  848. nv->pgraph[0x0090/4] = 0x00000000;
  849. nv->pgraph[0x009C/4] = 0x00000040;
  850. if((nv->did & 0x0ff0) >= 0x0250) {
  851. nv->pgraph[0x0890/4] = 0x00080000;
  852. nv->pgraph[0x0610/4] = 0x304B1FB6;
  853. nv->pgraph[0x0B80/4] = 0x18B82880;
  854. nv->pgraph[0x0B84/4] = 0x44000000;
  855. nv->pgraph[0x0098/4] = 0x40000080;
  856. nv->pgraph[0x0B88/4] = 0x000000ff;
  857. } else {
  858. nv->pgraph[0x0880/4] = 0x00080000;
  859. nv->pgraph[0x0094/4] = 0x00000005;
  860. nv->pgraph[0x0B80/4] = 0x45CAA208;
  861. nv->pgraph[0x0B84/4] = 0x24000000;
  862. nv->pgraph[0x0098/4] = 0x00000040;
  863. nv->pgraph[0x0750/4] = 0x00E00038;
  864. nv->pgraph[0x0754/4] = 0x00000030;
  865. nv->pgraph[0x0750/4] = 0x00E10038;
  866. nv->pgraph[0x0754/4] = 0x00000030;
  867. }
  868. }
  869. if((nv->arch < 40) || ((nv->did & 0xfff0) == 0x0040)){
  870. for(i = 0; i < 32; i++) {
  871. nv->pgraph[(0x0900/4) + i] = nv->pfb[(0x0240/4) + i];
  872. nv->pgraph[(0x6900/4) + i] = nv->pfb[(0x0240/4) + i];
  873. }
  874. }
  875. else{
  876. if(((nv->did & 0xfff0) == 0x0090)
  877. || ((nv->did & 0xfff0) == 0x01D0)
  878. || ((nv->did & 0xfff0) == 0x0290)
  879. || ((nv->did & 0xfff0) == 0x0390)){
  880. for(i = 0; i < 60; i++) {
  881. nv->pgraph[(0x0D00/4) + i] = nv->pfb[(0x0600/4) + i];
  882. nv->pgraph[(0x6900/4) + i] = nv->pfb[(0x0600/4) + i];
  883. }
  884. }
  885. else{
  886. for(i = 0; i < 48; i++) {
  887. nv->pgraph[(0x0900/4) + i] = nv->pfb[(0x0600/4) + i];
  888. if(((nv->did & 0xfff0) != 0x0160)
  889. && ((nv->did & 0xfff0) != 0x0220)
  890. && ((nv->did & 0xfff0) != 0x0240))
  891. nv->pgraph[(0x6900/4) + i] = nv->pfb[(0x0600/4) + i];
  892. }
  893. }
  894. }
  895. if(nv->arch >= 40) {
  896. if((nv->did & 0xfff0) == 0x0040) {
  897. nv->pgraph[0x09A4/4] = nv->pfb[0x0200/4];
  898. nv->pgraph[0x09A8/4] = nv->pfb[0x0204/4];
  899. nv->pgraph[0x69A4/4] = nv->pfb[0x0200/4];
  900. nv->pgraph[0x69A8/4] = nv->pfb[0x0204/4];
  901. nv->pgraph[0x0820/4] = 0;
  902. nv->pgraph[0x0824/4] = 0;
  903. nv->pgraph[0x0864/4] = vga->vmz - 1;
  904. nv->pgraph[0x0868/4] = vga->vmz - 1;
  905. } else {
  906. nv->pgraph[0x09F0/4] = nv->pfb[0x0200/4];
  907. nv->pgraph[0x09F4/4] = nv->pfb[0x0204/4];
  908. nv->pgraph[0x69F0/4] = nv->pfb[0x0200/4];
  909. nv->pgraph[0x69F4/4] = nv->pfb[0x0204/4];
  910. nv->pgraph[0x0840/4] = 0;
  911. nv->pgraph[0x0844/4] = 0;
  912. nv->pgraph[0x08a0/4] = vga->vmz - 1;
  913. nv->pgraph[0x08a4/4] = vga->vmz - 1;
  914. }
  915. } else {
  916. nv->pgraph[0x09A4/4] = nv->pfb[0x0200/4];
  917. nv->pgraph[0x09A8/4] = nv->pfb[0x0204/4];
  918. nv->pgraph[0x0750/4] = 0x00EA0000;
  919. nv->pgraph[0x0754/4] = nv->pfb[0x0200/4];
  920. nv->pgraph[0x0750/4] = 0x00EA0004;
  921. nv->pgraph[0x0754/4] = nv->pfb[0x0204/4];
  922. nv->pgraph[0x0820/4] = 0;
  923. nv->pgraph[0x0824/4] = 0;
  924. nv->pgraph[0x0864/4] = vga->vmz - 1;
  925. nv->pgraph[0x0868/4] = vga->vmz - 1;
  926. }
  927. nv->pgraph[0x0B20/4] = 0x00000000;
  928. nv->pgraph[0x0B04/4] = 0xFFFFFFFF;
  929. }
  930. }
  931. nv->pgraph[0x053C/4] = 0;
  932. nv->pgraph[0x0540/4] = 0;
  933. nv->pgraph[0x0544/4] = 0x00007FFF;
  934. nv->pgraph[0x0548/4] = 0x00007FFF;
  935. nv->pfifo[0x0140] = 0x00000000;
  936. nv->pfifo[0x0141] = 0x00000001;
  937. nv->pfifo[0x0480] = 0x00000000;
  938. nv->pfifo[0x0494] = 0x00000000;
  939. if (nv->arch >= 40)
  940. nv->pfifo[0x0481] = 0x00010000;
  941. else
  942. nv->pfifo[0x0481] = 0x00000100;
  943. nv->pfifo[0x0490] = 0x00000000;
  944. nv->pfifo[0x0491] = 0x00000000;
  945. if (nv->arch >= 40)
  946. nv->pfifo[0x048B] = 0x00001213;
  947. else
  948. nv->pfifo[0x048B] = 0x00001209;
  949. nv->pfifo[0x0400] = 0x00000000;
  950. nv->pfifo[0x0414] = 0x00000000;
  951. nv->pfifo[0x0084] = 0x03000100;
  952. nv->pfifo[0x0085] = 0x00000110;
  953. nv->pfifo[0x0086] = 0x00000112;
  954. nv->pfifo[0x0143] = 0x0000FFFF;
  955. nv->pfifo[0x0496] = 0x0000FFFF;
  956. nv->pfifo[0x0050] = 0x00000000;
  957. nv->pfifo[0x0040] = 0xFFFFFFFF;
  958. nv->pfifo[0x0415] = 0x00000001;
  959. nv->pfifo[0x048C] = 0x00000000;
  960. nv->pfifo[0x04A0] = 0x00000000;
  961. nv->pfifo[0x0489] = 0x000F0078;
  962. nv->pfifo[0x0488] = 0x00000001;
  963. nv->pfifo[0x0480] = 0x00000001;
  964. nv->pfifo[0x0494] = 0x00000001;
  965. nv->pfifo[0x0495] = 0x00000001;
  966. nv->pfifo[0x0140] = 0x00000001;
  967. if (nv->arch >= 10) {
  968. if (nv->twoheads) {
  969. nv->pcrtc[0x0860/4] = nv->head;
  970. nv->pcrtc[0x2860/4] = nv->head2;
  971. }
  972. nv->pramdac[0x0404/4] |= (1 << 25);
  973. nv->pmc[0x8704/4] = 1;
  974. nv->pmc[0x8140/4] = 0;
  975. nv->pmc[0x8920/4] = 0;
  976. nv->pmc[0x8924/4] = 0;
  977. nv->pmc[0x8908/4] = vga->vmz - 1;
  978. nv->pmc[0x890C/4] = vga->vmz - 1;
  979. nv->pmc[0x1588/4] = 0;
  980. nv->pcrtc[0x0810/4] = nv->cursorconfig;
  981. nv->pcrtc[0x0830/4] = nv->displayV - 3;
  982. nv->pcrtc[0x0834/4] = nv->displayV - 1;
  983. if (nv->islcd) {
  984. if((nv->did & 0x0ff0) == 0x0110)
  985. nv->pramdac[0x0528/4] = nv->dither;
  986. else if (nv->twoheads)
  987. nv->pramdac[0x083C/4] = nv->dither;
  988. vgaxo(Crtx, 0x53, nv->timingH);
  989. vgaxo(Crtx, 0x54, nv->timingV);
  990. vgaxo(Crtx, 0x21, 0xFA);
  991. }
  992. vgaxo(Crtx, 0x41, nv->extra);
  993. }
  994. vgaxo(Crtx, 0x19, nv->repaint0);
  995. vgaxo(Crtx, 0x1A, nv->repaint1);
  996. vgaxo(Crtx, 0x25, nv->screen);
  997. vgaxo(Crtx, 0x28, nv->pixel);
  998. vgaxo(Crtx, 0x2D, nv->horiz);
  999. vgaxo(Crtx, 0x30, nv->cursor0);
  1000. vgaxo(Crtx, 0x31, nv->cursor1);
  1001. vgaxo(Crtx, 0x2F, nv->cursor2);
  1002. vgaxo(Crtx, 0x39, nv->interlace);
  1003. if (nv->islcd) {
  1004. nv->pramdac[0x00000848/4] = nv->scale;
  1005. nv->pramdac[0x00000828/4] = nv->crtcsync;
  1006. } else {
  1007. nv->pramdac[0x0000050C/4] = nv->pllsel;
  1008. nv->pramdac[0x00000508/4] = nv->vpll;
  1009. if (nv->twoheads)
  1010. nv->pramdac[0x00000520/4] = nv->vpll2;
  1011. if (nv->twostagepll) {
  1012. nv->pramdac[0x00000578/4] = nv->vpllB;
  1013. nv->pramdac[0x0000057C/4] = nv->vpll2B;
  1014. }
  1015. }
  1016. nv->pramdac[0x00000600/4] = nv->general;
  1017. nv->pcrtc[0x0140/4] = 0;
  1018. nv->pcrtc[0x0100/4] = 1;
  1019. ctlr->flag |= Fload;
  1020. }
  1021. static void
  1022. dump(Vga* vga, Ctlr* ctlr)
  1023. {
  1024. Nvidia *nv;
  1025. int m, n, p, f;
  1026. double trouble;
  1027. if((nv = vga->private) == 0)
  1028. return;
  1029. p = (nv->vpll >> 16);
  1030. n = (nv->vpll >> 8) & 0xFF;
  1031. m = nv->vpll & 0xFF;
  1032. trouble = nv->crystalfreq;
  1033. trouble = trouble * n / (m<<p);
  1034. f = trouble+0.5;
  1035. printitem(ctlr->name, "dclk m n p");
  1036. Bprint(&stdout, " %d %d - %d %d\n", f, m, n, p);
  1037. printitem(ctlr->name, "CrystalFreq");
  1038. Bprint(&stdout, " %d Hz\n", nv->crystalfreq);
  1039. printitem(ctlr->name, "arch");
  1040. Bprint(&stdout, " %d\n", nv->arch);
  1041. printitem(ctlr->name, "did");
  1042. Bprint(&stdout, " %.4ux\n", nv->did);
  1043. printitem(ctlr->name, "repaint0");
  1044. Bprint(&stdout, " %ux\n", nv->repaint0);
  1045. printitem(ctlr->name, "repaint1");
  1046. Bprint(&stdout, " %ux\n", nv->repaint1);
  1047. printitem(ctlr->name, "screen");
  1048. Bprint(&stdout, " %ux\n", nv->screen);
  1049. printitem(ctlr->name, "pixel");
  1050. Bprint(&stdout, " %ux\n", nv->pixel);
  1051. printitem(ctlr->name, "horiz");
  1052. Bprint(&stdout, " %ux\n", nv->horiz);
  1053. printitem(ctlr->name, "cursor0");
  1054. Bprint(&stdout, " %ux\n", nv->cursor0);
  1055. printitem(ctlr->name, "cursor1");
  1056. Bprint(&stdout, " %ux\n", nv->cursor1);
  1057. printitem(ctlr->name, "cursor2");
  1058. Bprint(&stdout, " %ux\n", nv->cursor2);
  1059. printitem(ctlr->name, "interlace");
  1060. Bprint(&stdout, " %ux\n", nv->interlace);
  1061. printitem(ctlr->name, "extra");
  1062. Bprint(&stdout, " %ux\n", nv->extra);
  1063. printitem(ctlr->name, "crtcowner");
  1064. Bprint(&stdout, " %ux\n", nv->crtcowner);
  1065. printitem(ctlr->name, "timingH");
  1066. Bprint(&stdout, " %ux\n", nv->timingH);
  1067. printitem(ctlr->name, "timingV");
  1068. Bprint(&stdout, " %ux\n", nv->timingV);
  1069. printitem(ctlr->name, "vpll");
  1070. Bprint(&stdout, " %lux\n", nv->vpll);
  1071. printitem(ctlr->name, "vpllB");
  1072. Bprint(&stdout, " %lux\n", nv->vpllB);
  1073. printitem(ctlr->name, "vpll2");
  1074. Bprint(&stdout, " %lux\n", nv->vpll2);
  1075. printitem(ctlr->name, "vpll2B");
  1076. Bprint(&stdout, " %lux\n", nv->vpll2B);
  1077. printitem(ctlr->name, "pllsel");
  1078. Bprint(&stdout, " %lux\n", nv->pllsel);
  1079. printitem(ctlr->name, "general");
  1080. Bprint(&stdout, " %lux\n", nv->general);
  1081. printitem(ctlr->name, "scale");
  1082. Bprint(&stdout, " %lux\n", nv->scale);
  1083. printitem(ctlr->name, "config");
  1084. Bprint(&stdout, " %lux\n", nv->config);
  1085. printitem(ctlr->name, "head");
  1086. Bprint(&stdout, " %lux\n", nv->head);
  1087. printitem(ctlr->name, "head2");
  1088. Bprint(&stdout, " %lux\n", nv->head2);
  1089. printitem(ctlr->name, "cursorconfig");
  1090. Bprint(&stdout, " %lux\n", nv->cursorconfig);
  1091. printitem(ctlr->name, "dither");
  1092. Bprint(&stdout, " %lux\n", nv->dither);
  1093. printitem(ctlr->name, "crtcsync");
  1094. Bprint(&stdout, " %lux\n", nv->crtcsync);
  1095. printitem(ctlr->name, "islcd");
  1096. Bprint(&stdout, " %d\n", nv->islcd);
  1097. printitem(ctlr->name, "twoheads");
  1098. Bprint(&stdout, " %d\n", nv->twoheads);
  1099. printitem(ctlr->name, "twostagepll");
  1100. Bprint(&stdout, " %d\n", nv->twostagepll);
  1101. printitem(ctlr->name, "crtcnumber");
  1102. Bprint(&stdout, " %d\n", nv->crtcnumber);
  1103. printitem(ctlr->name, "fpwidth");
  1104. Bprint(&stdout, " %d\n", nv->fpwidth);
  1105. printitem(ctlr->name, "fpheight");
  1106. Bprint(&stdout, " %d\n", nv->fpheight);
  1107. }
  1108. Ctlr nvidia = {
  1109. "nvidia", /* name */
  1110. snarf, /* snarf */
  1111. options, /* options */
  1112. init, /* init */
  1113. load, /* load */
  1114. dump, /* dump */
  1115. };
  1116. Ctlr nvidiahwgc = {
  1117. "nvidiahwgc", /* name */
  1118. 0, /* snarf */
  1119. 0, /* options */
  1120. 0, /* init */
  1121. 0, /* load */
  1122. 0, /* dump */
  1123. };