nvidia.c 32 KB

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