nvidia.c 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897
  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. ulong mmio;
  48. Pcidev* pci;
  49. int arch;
  50. int crystalfreq;
  51. ulong* pfb; /* mmio pointers */
  52. ulong* pramdac;
  53. ulong* pextdev;
  54. ulong* pmc;
  55. ulong* ptimer;
  56. ulong* pfifo;
  57. ulong* pramin;
  58. ulong* pgraph;
  59. ulong* fifo;
  60. ulong* pcrtc;
  61. ushort repaint0;
  62. ushort repaint1;
  63. ushort screen;
  64. ushort pixel;
  65. ushort horiz;
  66. ushort cursor0;
  67. ushort cursor1;
  68. ushort cursor2;
  69. ushort interlace;
  70. ushort extra;
  71. ushort crtcowner;
  72. ulong vpll;
  73. ulong vpllB;
  74. ulong vpll2;
  75. ulong vpll2B;
  76. ulong pllsel;
  77. ulong general;
  78. ulong scale;
  79. ulong config;
  80. ulong head;
  81. ulong head2;
  82. ulong cursorconfig;
  83. ulong dither;
  84. int islcd;
  85. int twoheads;
  86. int twostagepll;
  87. int crtcnumber;
  88. };
  89. static void
  90. snarf(Vga* vga, Ctlr* ctlr)
  91. {
  92. Nvidia *nv;
  93. Pcidev *p;
  94. ulong m, *mmio, tmp;
  95. int implementation;
  96. if(vga->private == nil){
  97. vga->private = alloc(sizeof(Nvidia));
  98. nv = vga->private;
  99. p = nil;
  100. while((p = pcimatch(p, 0x10DE, 0)) != nil){
  101. if((p->ccru>>8) == 3)
  102. break;
  103. }
  104. if(p == nil)
  105. error("%s: not found\n", ctlr->name);
  106. nv->arch = ((p->did&0x0F00) >> 8) * 10;
  107. if(nv->arch == 0)
  108. nv->arch = 4;
  109. if((p->did < 0x20) || (nv->arch > 30))
  110. error("%s: DID %4.4uX unsupported\n", ctlr->name, p->did);
  111. vgactlw("type", ctlr->name);
  112. if((m = segattach(0, "nvidiammio", 0, p->mem[0].size)) == -1)
  113. error("%s: segattach nvidiammio, size %d: %r\n",
  114. ctlr->name, p->mem[0].size);
  115. nv->pci = p;
  116. nv->mmio = m;
  117. mmio = (ulong*)m;
  118. nv->pfb = mmio+0x00100000/4;
  119. nv->pramdac = mmio+0x00680000/4;
  120. nv->pextdev = mmio+0x00101000/4;
  121. nv->pmc = mmio+0x00000000/4;
  122. nv->ptimer = mmio+0x00009000/4;
  123. nv->pfifo = mmio+0x00002000/4;
  124. nv->pramin = mmio+0x00710000/4;
  125. nv->pgraph = mmio+0x00400000/4;
  126. nv->fifo = mmio+0x00800000/4;
  127. nv->pcrtc= mmio+0x00600000/4;
  128. }
  129. nv = vga->private;
  130. implementation = nv->pci->did & 0x0ff0;
  131. /*
  132. * Unlock
  133. */
  134. vgaxo(Crtx, 0x1F, 0x57);
  135. if (nv->pextdev[0x00000000] & 0x00000040)
  136. nv->crystalfreq = RefFreq;
  137. else
  138. nv->crystalfreq = 13500000;
  139. if ((implementation == 0x0170) ||
  140. (implementation == 0x0180) ||
  141. (implementation == 0x01F0) ||
  142. (implementation >= 0x0250))
  143. if(nv->pextdev[0x00000000] & (1 << 22))
  144. nv->crystalfreq = 27000000;
  145. nv->twoheads = (implementation >= 0x0110) &&
  146. (implementation != 0x0150) &&
  147. (implementation != 0x01A0) &&
  148. (implementation != 0x0200);
  149. nv->twostagepll = (implementation == 0x0310) ||
  150. (implementation == 0x0340);
  151. /* laptop chips */
  152. switch (nv->pci->did & 0xffff) {
  153. case 0x0112:
  154. case 0x0174:
  155. case 0x0175:
  156. case 0x0176:
  157. case 0x0177:
  158. case 0x0179:
  159. case 0x017C:
  160. case 0x017D:
  161. case 0x0186:
  162. case 0x0187:
  163. case 0x0189:
  164. case 0x0286:
  165. case 0x028C:
  166. case 0x0316:
  167. case 0x0317:
  168. case 0x031A:
  169. case 0x031B:
  170. case 0x031C:
  171. case 0x031D:
  172. case 0x031E:
  173. case 0x031F:
  174. case 0x0324:
  175. case 0x0325:
  176. case 0x0328:
  177. case 0x0329:
  178. case 0x032C:
  179. case 0x032D:
  180. case 0x0347:
  181. case 0x0348:
  182. case 0x0349:
  183. case 0x034B:
  184. case 0x034C:
  185. nv->islcd = 1;
  186. break;
  187. default:
  188. break;
  189. }
  190. if (nv->arch == 4) {
  191. tmp = nv->pfb[0x00000000];
  192. if (tmp & 0x0100) {
  193. vga->vmz = ((tmp >> 12) & 0x0F) * 1024 + 1024 * 2;
  194. } else {
  195. tmp &= 0x03;
  196. if (tmp)
  197. vga->vmz = (1024*1024*2) << tmp;
  198. else
  199. vga->vmz = 1024*1024*32;
  200. }
  201. } else {
  202. tmp = (nv->pfb[0x0000020C/4] >> 20) & 0xFF;
  203. if (tmp == 0)
  204. tmp = 16;
  205. vga->vmz = 1024*1024*tmp;
  206. }
  207. nv->repaint0 = vgaxi(Crtx, 0x19);
  208. nv->repaint1 = vgaxi(Crtx, 0x1A);
  209. nv->screen = vgaxi(Crtx, 0x25);
  210. nv->pixel = vgaxi(Crtx, 0x28);
  211. nv->horiz = vgaxi(Crtx, 0x2D);
  212. nv->cursor0 = vgaxi(Crtx, 0x30);
  213. nv->cursor1 = vgaxi(Crtx, 0x31);
  214. nv->cursor2 = vgaxi(Crtx, 0x2F);
  215. nv->interlace = vgaxi(Crtx, 0x39);
  216. nv->vpll = nv->pramdac[0x00000508/4];
  217. if (nv->twoheads)
  218. nv->vpll2 = nv->pramdac[0x00000520/4];
  219. if (nv->twostagepll) {
  220. nv->vpllB = nv->pramdac[0x00000578/4];
  221. nv->vpll2B = nv->pramdac[0x0000057C/4];
  222. }
  223. nv->pllsel = nv->pramdac[0x0000050C/4];
  224. nv->general = nv->pramdac[0x00000600/4];
  225. nv->scale = nv->pramdac[0x00000848/4];
  226. nv->config = nv->pfb[0x00000200/4];
  227. if (nv->arch >= 10) {
  228. if (nv->twoheads) {
  229. nv->head = nv->pcrtc[0x0860/4];
  230. nv->head2 = nv->pcrtc[0x2860/4];
  231. nv->crtcowner = vgaxi(Crtx, 0x44);
  232. }
  233. nv->extra = vgaxi(Crtx, 0x41);
  234. nv->cursorconfig = nv->pcrtc[0x0810/4];
  235. if (implementation == 0x0110)
  236. nv->dither = nv->pramdac[0x0528/4];
  237. else if (implementation >= 0x0170)
  238. nv->dither = nv->pramdac[0x083C/4];
  239. }
  240. if (nv->pixel & 0x80)
  241. nv->islcd = 1;
  242. nv->crtcnumber = 0;
  243. ctlr->flag |= Fsnarf;
  244. }
  245. static void
  246. options(Vga*, Ctlr* ctlr)
  247. {
  248. ctlr->flag |= Hlinear|Foptions;
  249. }
  250. static void
  251. clock(Vga* vga, Ctlr* ctlr)
  252. {
  253. int m, n, p, f, d;
  254. Nvidia *nv;
  255. double trouble;
  256. int fmin, mmin, nmin, crystalfreq;
  257. nv = vga->private;
  258. if(vga->f[0] == 0)
  259. vga->f[0] = vga->mode->frequency;
  260. vga->d[0] = vga->f[0]+1;
  261. vga->n[1] = 255;
  262. if (nv->twostagepll) {
  263. vga->p[1] = 6;
  264. vga->m[1] = 13;
  265. vga->f[1] = 400000000 << 2;
  266. crystalfreq = nv->crystalfreq << 2;
  267. fmin = 100000000 << 2;
  268. mmin = 1;
  269. nmin = 5;
  270. nv->vpllB = 0x80000401;
  271. } else {
  272. vga->p[1] = 4;
  273. if (nv->crystalfreq == 13500000)
  274. vga->m[1] = 13;
  275. else
  276. vga->m[1] = 14;
  277. vga->f[1] = 350000000;
  278. crystalfreq = nv->crystalfreq;
  279. fmin = 128000000;
  280. mmin = 7;
  281. nmin = 0;
  282. }
  283. for (p=0; p <= vga->p[1]; p++){
  284. f = vga->f[0] << p;
  285. if ((f >= fmin) && (f <= vga->f[1])) {
  286. for (m=mmin; m <= vga->m[1]; m++){
  287. trouble = (double) crystalfreq / (double) (m << p);
  288. n = (vga->f[0] / trouble)+0.5;
  289. f = n*trouble + 0.5;
  290. d = vga->f[0] - f;
  291. if (d < 0)
  292. d = -d;
  293. if ((n & ~0xFF) && (n >= nmin))
  294. d = vga->d[0] + 1;
  295. if (d <= vga->d[0]){
  296. vga->n[0] = n;
  297. vga->m[0] = m;
  298. vga->p[0] = p;
  299. vga->d[0] = d;
  300. }
  301. }
  302. }
  303. }
  304. if (vga->d[0] > vga->f[0])
  305. error("%s: vclk %lud out of range\n", ctlr->name, vga->f[0]);
  306. }
  307. static void
  308. init(Vga* vga, Ctlr* ctlr)
  309. {
  310. Mode *mode;
  311. Nvidia *nv;
  312. char *p, *val;
  313. int tmp, pixeldepth;
  314. ulong cursorstart;
  315. mode = vga->mode;
  316. if(mode->z == 24)
  317. error("%s: 24-bit colour not supported, use 32-bit\n", ctlr->name);
  318. nv = vga->private;
  319. if(vga->linear && (ctlr->flag & Hlinear))
  320. ctlr->flag |= Ulinear;
  321. clock(vga, ctlr);
  322. if(val = dbattr(vga->mode->attr, "lcd")){
  323. if((nv->islcd = strtol(val, &p, 0)) == 0 && p == val)
  324. error("%s: invalid 'lcd' attr\n", ctlr->name);
  325. }
  326. if(nv->arch == 4) {
  327. nv->cursor0 = 0x00;
  328. nv->cursor1 = 0xBC;
  329. nv->cursor2 = 0;
  330. nv->config = 0x00001114;
  331. } else if(nv->arch >= 10) {
  332. cursorstart = vga->vmz - 96 * 1024;
  333. nv->cursor0 = 0x80 | (cursorstart >> 17);
  334. nv->cursor1 = (cursorstart >> 11) << 2;
  335. nv->cursor2 = cursorstart >> 24;
  336. nv->config = nv->pfb[0x200/4];
  337. }
  338. nv->vpll = (vga->p[0] << 16) | (vga->n[0] << 8) | vga->m[0];
  339. nv->pllsel = 0x10000700;
  340. if (mode->z == 16)
  341. nv->general = 0x00001100;
  342. else
  343. nv->general = 0x00000100;
  344. //if (mode->z != 8)
  345. // nv->general |= 0x00000030;
  346. if (mode->x < 1280)
  347. nv->repaint1 = 0x04;
  348. else
  349. nv->repaint1 = 0;
  350. vga->attribute[0x10] &= ~0x40;
  351. vga->attribute[0x11] = Pblack;
  352. vga->crt[0x14] = 0x00;
  353. /* set vert blanking to cover full overscan */
  354. tmp = vga->crt[0x12];
  355. vga->crt[0x15] = tmp;
  356. if(tmp & 0x100)
  357. vga->crt[0x07] |= 0x08;
  358. else
  359. vga->crt[0x07] &= ~0x08;
  360. if(tmp & 0x200)
  361. vga->crt[0x09] |= 0x20;
  362. else
  363. vga->crt[0x09] &= ~0x20;
  364. vga->crt[0x16] = vga->crt[0x06] + 1;
  365. /* set horiz blanking to cover full overscan */
  366. vga->crt[0x02] = vga->crt[0x01];
  367. tmp = vga->crt[0x00] + 4;
  368. vga->crt[0x03] = 0x80 | (tmp & 0x1F);
  369. if (tmp & 0x20)
  370. vga->crt[0x05] |= 0x80;
  371. else
  372. vga->crt[0x05] &= ~0x80;
  373. if (tmp & 0x40)
  374. nv->screen = 0x10;
  375. else
  376. nv->screen = 0x00;
  377. /* overflow bits */
  378. if (nv->islcd){
  379. tmp = vga->crt[0x06] - 3;
  380. vga->crt[0x10] = tmp;
  381. if(tmp & 0x100)
  382. vga->crt[0x07] |= 0x04;
  383. else
  384. vga->crt[0x07] &= ~0x04;
  385. if(tmp & 0x200)
  386. vga->crt[0x07] |= 0x80;
  387. else
  388. vga->crt[0x07] &= ~0x80;
  389. vga->crt[0x11] = 0x20 | ((vga->crt[0x06] - 2) & 0x0F);
  390. tmp = vga->crt[0x10];
  391. vga->crt[0x15] = tmp;
  392. if(tmp & 0x100)
  393. vga->crt[0x07] |= 0x08;
  394. else
  395. vga->crt[0x07] &= ~0x08;
  396. if(tmp & 0x200)
  397. vga->crt[0x09] |= 0x20;
  398. else
  399. vga->crt[0x09] &= ~0x20;
  400. vga->crt[0x04] = vga->crt[0x00] - 5;
  401. vga->crt[0x05] &= ~0x1F;
  402. vga->crt[0x05] |= (0x1F & (vga->crt[0x00] - 2));
  403. }
  404. nv->repaint0 = (vga->crt[0x13] & 0x0700) >> 3;
  405. pixeldepth = (mode->z +1)/8;
  406. if (pixeldepth > 3)
  407. nv->pixel = 3;
  408. else
  409. nv->pixel = pixeldepth;
  410. nv->scale &= 0xFFF000FF;
  411. if(nv->islcd){
  412. nv->pixel |= 0x80;
  413. nv->scale |= 0x100;
  414. }
  415. if (vga->crt[0x06] & 0x400)
  416. nv->screen |= 0x01;
  417. if (vga->crt[0x12] & 0x400)
  418. nv->screen |= 0x02;
  419. if (vga->crt[0x10] & 0x400)
  420. nv->screen |= 0x04;
  421. if (vga->crt[0x15] & 0x400)
  422. nv->screen |= 0x08;
  423. if (vga->crt[0x13] & 0x800)
  424. nv->screen |= 0x20;
  425. nv->horiz = 0x00;
  426. if (vga->crt[0x00] & 0x100)
  427. nv->horiz = 0x01;
  428. if(vga->crt[0x01] & 0x100)
  429. nv->horiz |= 0x02;
  430. if(vga->crt[0x02] & 0x100)
  431. nv->horiz |= 0x04;
  432. if(vga->crt[0x04] & 0x100)
  433. nv->horiz |= 0x08;
  434. nv->extra = 0x00;
  435. if (vga->crt[0x06] & 0x800)
  436. nv->extra |= 0x01;
  437. if (vga->crt[0x12] & 0x800)
  438. nv->extra |= 0x04;
  439. if (vga->crt[0x10] & 0x800)
  440. nv->extra |= 0x10;
  441. if (vga->crt[0x15] & 0x800)
  442. nv->extra |= 0x40;
  443. nv->interlace = 0xFF;
  444. if (nv->twoheads) {
  445. nv->head |= 0x00001000;
  446. nv->head2 |= ~0x00001000;
  447. nv->crtcowner = 0;
  448. }
  449. nv->cursorconfig = 0x00000100 | 0x02000000;
  450. ctlr->flag |= Finit;
  451. }
  452. static void
  453. load(Vga* vga, Ctlr* ctlr)
  454. {
  455. Nvidia *nv;
  456. int i;
  457. nv = vga->private;
  458. /*
  459. * Unlock
  460. */
  461. vgaxo(Crtx, 0x1F, 0x57);
  462. nv->pmc[0x0140/4] = 0x00000000;
  463. nv->pmc[0x0200/4] = 0xFFFF00FF;
  464. nv->pmc[0x0200/4] = 0xFFFFFFFF;
  465. nv->ptimer[0x0200] = 0x00000008;
  466. nv->ptimer[0x0210] = 0x00000003;
  467. nv->ptimer[0x0140] = 0x00000000;
  468. nv->ptimer[0x0100] = 0xFFFFFFFF;
  469. if (nv->arch == 4)
  470. nv->pfb[0x00000200/4] = nv->config;
  471. else {
  472. for(i=0; i<8; i++) {
  473. nv->pfb[0x240/4+(i * 4)] = 0;
  474. nv->pfb[0x244/4+(i * 4)] = vga->vmz - 1;
  475. }
  476. }
  477. nv->pramin[0x0000] = 0x80000010;
  478. nv->pramin[0x0001] = 0x80011201;
  479. nv->pramin[0x0002] = 0x80000011;
  480. nv->pramin[0x0003] = 0x80011202;
  481. nv->pramin[0x0004] = 0x80000012;
  482. nv->pramin[0x0005] = 0x80011203;
  483. nv->pramin[0x0006] = 0x80000013;
  484. nv->pramin[0x0007] = 0x80011204;
  485. nv->pramin[0x0008] = 0x80000014;
  486. nv->pramin[0x0009] = 0x80011205;
  487. nv->pramin[0x000A] = 0x80000015;
  488. nv->pramin[0x000B] = 0x80011206;
  489. nv->pramin[0x000C] = 0x80000016;
  490. nv->pramin[0x000D] = 0x80011207;
  491. nv->pramin[0x000E] = 0x80000017;
  492. nv->pramin[0x000F] = 0x80011208;
  493. nv->pramin[0x0800] = 0x00003000;
  494. nv->pramin[0x0801] = vga->vmz - 1;
  495. nv->pramin[0x0802] = 0x00000002;
  496. nv->pramin[0x0803] = 0x00000002;
  497. if (nv->arch >= 10)
  498. nv->pramin[0x0804] = 0x01008062;
  499. else
  500. nv->pramin[0x0804] = 0x01008042;
  501. nv->pramin[0x0805] = 0x00000000;
  502. nv->pramin[0x0806] = 0x12001200;
  503. nv->pramin[0x0807] = 0x00000000;
  504. nv->pramin[0x0808] = 0x01008043;
  505. nv->pramin[0x0809] = 0x00000000;
  506. nv->pramin[0x080A] = 0x00000000;
  507. nv->pramin[0x080B] = 0x00000000;
  508. nv->pramin[0x080C] = 0x01008044;
  509. nv->pramin[0x080D] = 0x00000002;
  510. nv->pramin[0x080E] = 0x00000000;
  511. nv->pramin[0x080F] = 0x00000000;
  512. nv->pramin[0x0810] = 0x01008019;
  513. nv->pramin[0x0811] = 0x00000000;
  514. nv->pramin[0x0812] = 0x00000000;
  515. nv->pramin[0x0813] = 0x00000000;
  516. nv->pramin[0x0814] = 0x0100A05C;
  517. nv->pramin[0x0815] = 0x00000000;
  518. nv->pramin[0x0816] = 0x00000000;
  519. nv->pramin[0x0817] = 0x00000000;
  520. nv->pramin[0x0818] = 0x0100805F;
  521. nv->pramin[0x0819] = 0x00000000;
  522. nv->pramin[0x081A] = 0x12001200;
  523. nv->pramin[0x081B] = 0x00000000;
  524. nv->pramin[0x081C] = 0x0100804A;
  525. nv->pramin[0x081D] = 0x00000002;
  526. nv->pramin[0x081E] = 0x00000000;
  527. nv->pramin[0x081F] = 0x00000000;
  528. nv->pramin[0x0820] = 0x01018077;
  529. nv->pramin[0x0821] = 0x00000000;
  530. nv->pramin[0x0822] = 0x01201200;
  531. nv->pramin[0x0823] = 0x00000000;
  532. nv->pramin[0x0824] = 0x00003002;
  533. nv->pramin[0x0825] = 0x00007FFF;
  534. nv->pramin[0x0826] = (vga->vmz - 128 * 1024) | 0x00000002;
  535. nv->pramin[0x0827] = 0x00000002;
  536. if (nv->arch < 10) {
  537. if((nv->pci->did & 0x0fff) == 0x0020) {
  538. nv->pramin[0x0824] |= 0x00020000;
  539. nv->pramin[0x0826] += nv->pci->mem[1].bar;
  540. }
  541. nv->pgraph[0x0080/4] = 0x000001FF;
  542. nv->pgraph[0x0080/4] = 0x1230C000;
  543. nv->pgraph[0x0084/4] = 0x72111101;
  544. nv->pgraph[0x0088/4] = 0x11D5F071;
  545. nv->pgraph[0x008C/4] = 0x0004FF31;
  546. nv->pgraph[0x0140/4] = 0x00000000;
  547. nv->pgraph[0x0100/4] = 0xFFFFFFFF;
  548. nv->pgraph[0x0170/4] = 0x10010100;
  549. nv->pgraph[0x0710/4] = 0xFFFFFFFF;
  550. nv->pgraph[0x0720/4] = 0x00000001;
  551. nv->pgraph[0x0810/4] = 0x00000000;
  552. } else {
  553. nv->pgraph[0x0080/4] = 0xFFFFFFFF;
  554. nv->pgraph[0x0080/4] = 0x00000000;
  555. nv->pgraph[0x0140/4] = 0x00000000;
  556. nv->pgraph[0x0100/4] = 0xFFFFFFFF;
  557. nv->pgraph[0x0144/4] = 0x10010100;
  558. nv->pgraph[0x0714/4] = 0xFFFFFFFF;
  559. nv->pgraph[0x0720/4] = 0x00000001;
  560. if (nv->arch == 10) {
  561. nv->pgraph[0x0084/4] = 0x00118700;
  562. nv->pgraph[0x0088/4] = 0x24E00810;
  563. nv->pgraph[0x008C/4] = 0x55DE0030;
  564. for(i = 0; i < 32; i++)
  565. nv->pgraph[(0x0B00/4) + i] = nv->pfb[(0x0240/4) + i];
  566. nv->pgraph[0x640/4] = 0;
  567. nv->pgraph[0x644/4] = 0;
  568. nv->pgraph[0x684/4] = vga->vmz - 1;
  569. nv->pgraph[0x688/4] = vga->vmz - 1;
  570. nv->pgraph[0x0810/4] = 0x00000000;
  571. } else {
  572. if(nv->arch >= 30) {
  573. nv->pgraph[0x0084/4] = 0x40108700;
  574. nv->pgraph[0x0890/4] = 0x00140000;
  575. nv->pgraph[0x008C/4] = 0xf00e0431;
  576. nv->pgraph[0x0090/4] = 0x00008000;
  577. nv->pgraph[0x0610/4] = 0xf04b1f36;
  578. nv->pgraph[0x0B80/4] = 0x1002d888;
  579. nv->pgraph[0x0B88/4] = 0x62ff007f;
  580. } else {
  581. nv->pgraph[0x0084/4] = 0x00118700;
  582. nv->pgraph[0x008C/4] = 0xF20E0431;
  583. nv->pgraph[0x0090/4] = 0x00000000;
  584. nv->pgraph[0x009C/4] = 0x00000040;
  585. if((nv->pci->did & 0x0ff0) >= 0x0250) {
  586. nv->pgraph[0x0890/4] = 0x00080000;
  587. nv->pgraph[0x0610/4] = 0x304B1FB6;
  588. nv->pgraph[0x0B80/4] = 0x18B82880;
  589. nv->pgraph[0x0B84/4] = 0x44000000;
  590. nv->pgraph[0x0098/4] = 0x40000080;
  591. nv->pgraph[0x0B88/4] = 0x000000ff;
  592. } else {
  593. nv->pgraph[0x0880/4] = 0x00080000;
  594. nv->pgraph[0x0094/4] = 0x00000005;
  595. nv->pgraph[0x0B80/4] = 0x45CAA208;
  596. nv->pgraph[0x0B84/4] = 0x24000000;
  597. nv->pgraph[0x0098/4] = 0x00000040;
  598. nv->pgraph[0x0750/4] = 0x00E00038;
  599. nv->pgraph[0x0754/4] = 0x00000030;
  600. nv->pgraph[0x0750/4] = 0x00E10038;
  601. nv->pgraph[0x0754/4] = 0x00000030;
  602. }
  603. }
  604. for(i = 0; i < 32; i++)
  605. nv->pgraph[(0x0900/4) + i] = nv->pfb[(0x0240/4) + i];
  606. nv->pgraph[0x09A4/4] = nv->pfb[0x0200/4];
  607. nv->pgraph[0x09A8/4] = nv->pfb[0x0204/4];
  608. nv->pgraph[0x0750/4] = 0x00EA0000;
  609. nv->pgraph[0x0754/4] = nv->pfb[0x0200/4];
  610. nv->pgraph[0x0750/4] = 0x00EA0004;
  611. nv->pgraph[0x0754/4] = nv->pfb[0x0204/4];
  612. nv->pgraph[0x0820/4] = 0;
  613. nv->pgraph[0x0824/4] = 0;
  614. nv->pgraph[0x0864/4] = vga->vmz - 1;
  615. nv->pgraph[0x0868/4] = vga->vmz - 1;
  616. nv->pgraph[0x0B20/4] = 0x00000000;
  617. }
  618. }
  619. nv->pgraph[0x053C/4] = 0;
  620. nv->pgraph[0x0540/4] = 0;
  621. nv->pgraph[0x0544/4] = 0x00007FFF;
  622. nv->pgraph[0x0548/4] = 0x00007FFF;
  623. nv->pfifo[0x0140] = 0x00000000;
  624. nv->pfifo[0x0141] = 0x00000001;
  625. nv->pfifo[0x0480] = 0x00000000;
  626. nv->pfifo[0x0494] = 0x00000000;
  627. nv->pfifo[0x0481] = 0x00000100;
  628. nv->pfifo[0x0490] = 0x00000000;
  629. nv->pfifo[0x0491] = 0x00000000;
  630. nv->pfifo[0x048B] = 0x00001209;
  631. nv->pfifo[0x0400] = 0x00000000;
  632. nv->pfifo[0x0414] = 0x00000000;
  633. nv->pfifo[0x0084] = 0x03000100;
  634. nv->pfifo[0x0085] = 0x00000110;
  635. nv->pfifo[0x0086] = 0x00000112;
  636. nv->pfifo[0x0143] = 0x0000FFFF;
  637. nv->pfifo[0x0496] = 0x0000FFFF;
  638. nv->pfifo[0x0050] = 0x00000000;
  639. nv->pfifo[0x0040] = 0xFFFFFFFF;
  640. nv->pfifo[0x0415] = 0x00000001;
  641. nv->pfifo[0x048C] = 0x00000000;
  642. nv->pfifo[0x04A0] = 0x00000000;
  643. nv->pfifo[0x0489] = 0x000F0078;
  644. nv->pfifo[0x0488] = 0x00000001;
  645. nv->pfifo[0x0480] = 0x00000001;
  646. nv->pfifo[0x0494] = 0x00000001;
  647. nv->pfifo[0x0495] = 0x00000001;
  648. nv->pfifo[0x0140] = 0x00000001;
  649. if (nv->arch >= 10) {
  650. if (nv->twoheads) {
  651. nv->pcrtc[0x0860/4] = nv->head;
  652. nv->pcrtc[0x2860/4] = nv->head2;
  653. }
  654. nv->pramdac[0x0404/4] |= (1 << 25);
  655. nv->pmc[0x8704/4] = 1;
  656. nv->pmc[0x8140/4] = 0;
  657. nv->pmc[0x8920/4] = 0;
  658. nv->pmc[0x8924/4] = 0;
  659. nv->pmc[0x8908/4] = vga->vmz - 1;
  660. nv->pmc[0x890C/4] = vga->vmz - 1;
  661. nv->pmc[0x1588/4] = 0;
  662. nv->pcrtc[0x0810/4] = nv->cursorconfig;
  663. if (nv->islcd) {
  664. if((nv->pci->did & 0x0ff0) == 0x0110)
  665. nv->pramdac[0x0528/4] = nv->dither;
  666. else if((nv->pci->did & 0x0ff0) >= 0x0170)
  667. nv->pramdac[0x083C/4] = nv->dither;
  668. vgaxo(Crtx, 0x53, 0);
  669. vgaxo(Crtx, 0x54, 0);
  670. vgaxo(Crtx, 0x21, 0xFA);
  671. }
  672. vgaxo(Crtx, 0x41, nv->extra);
  673. }
  674. vgaxo(Crtx, 0x19, nv->repaint0);
  675. vgaxo(Crtx, 0x1A, nv->repaint1);
  676. vgaxo(Crtx, 0x25, nv->screen);
  677. vgaxo(Crtx, 0x28, nv->pixel);
  678. vgaxo(Crtx, 0x2D, nv->horiz);
  679. vgaxo(Crtx, 0x30, nv->cursor0);
  680. vgaxo(Crtx, 0x31, nv->cursor1);
  681. vgaxo(Crtx, 0x2F, nv->cursor2);
  682. vgaxo(Crtx, 0x39, nv->interlace);
  683. if (nv->islcd)
  684. nv->pramdac[0x00000848/4] = nv->scale;
  685. else {
  686. nv->pramdac[0x0000050C/4] = nv->pllsel;
  687. nv->pramdac[0x00000508/4] = nv->vpll;
  688. if (nv->twoheads)
  689. nv->pramdac[0x00000520/4] = nv->vpll2;
  690. if (nv->twostagepll) {
  691. nv->pramdac[0x00000578/4] = nv->vpllB;
  692. nv->pramdac[0x0000057C/4] = nv->vpll2B;
  693. }
  694. }
  695. nv->pramdac[0x00000600/4] = nv->general;
  696. nv->pcrtc[0x0140/4] = 0;
  697. nv->pcrtc[0x0100/4] = 1;
  698. ctlr->flag |= Fload;
  699. }
  700. static void
  701. dump(Vga* vga, Ctlr* ctlr)
  702. {
  703. Nvidia *nv;
  704. int m, n, p, f;
  705. double trouble;
  706. if((nv = vga->private) == 0)
  707. return;
  708. p = (nv->vpll >> 16);
  709. n = (nv->vpll >> 8) & 0xFF;
  710. m = nv->vpll & 0xFF;
  711. trouble = nv->crystalfreq;
  712. trouble = trouble * n / (m<<p);
  713. f = trouble+0.5;
  714. printitem(ctlr->name, "dclk m n p");
  715. Bprint(&stdout, " %d %d - %d %d\n", f, m, n, p);
  716. printitem(ctlr->name, "CrystalFreq");
  717. Bprint(&stdout, " %d Hz\n", nv->crystalfreq);
  718. printitem(ctlr->name, "arch");
  719. Bprint(&stdout, " %d\n", nv->arch);
  720. printitem(ctlr->name, "repaint0");
  721. Bprint(&stdout, " %ux\n", nv->repaint0);
  722. printitem(ctlr->name, "repaint1");
  723. Bprint(&stdout, " %ux\n", nv->repaint1);
  724. printitem(ctlr->name, "screen");
  725. Bprint(&stdout, " %ux\n", nv->screen);
  726. printitem(ctlr->name, "pixel");
  727. Bprint(&stdout, " %ux\n", nv->pixel);
  728. printitem(ctlr->name, "horiz");
  729. Bprint(&stdout, " %ux\n", nv->horiz);
  730. printitem(ctlr->name, "cursor0");
  731. Bprint(&stdout, " %ux\n", nv->cursor0);
  732. printitem(ctlr->name, "cursor1");
  733. Bprint(&stdout, " %ux\n", nv->cursor1);
  734. printitem(ctlr->name, "cursor2");
  735. Bprint(&stdout, " %ux\n", nv->cursor2);
  736. printitem(ctlr->name, "interlace");
  737. Bprint(&stdout, " %ux\n", nv->interlace);
  738. printitem(ctlr->name, "extra");
  739. Bprint(&stdout, " %ux\n", nv->extra);
  740. printitem(ctlr->name, "crtcowner");
  741. Bprint(&stdout, " %ux\n", nv->crtcowner);
  742. printitem(ctlr->name, "vpll");
  743. Bprint(&stdout, " %lux\n", nv->vpll);
  744. printitem(ctlr->name, "vpllB");
  745. Bprint(&stdout, " %lux\n", nv->vpllB);
  746. printitem(ctlr->name, "vpll2");
  747. Bprint(&stdout, " %lux\n", nv->vpll2);
  748. printitem(ctlr->name, "vpll2B");
  749. Bprint(&stdout, " %lux\n", nv->vpll2B);
  750. printitem(ctlr->name, "pllsel");
  751. Bprint(&stdout, " %lux\n", nv->pllsel);
  752. printitem(ctlr->name, "general");
  753. Bprint(&stdout, " %lux\n", nv->general);
  754. printitem(ctlr->name, "scale");
  755. Bprint(&stdout, " %lux\n", nv->scale);
  756. printitem(ctlr->name, "config");
  757. Bprint(&stdout, " %lux\n", nv->config);
  758. printitem(ctlr->name, "head");
  759. Bprint(&stdout, " %lux\n", nv->head);
  760. printitem(ctlr->name, "head2");
  761. Bprint(&stdout, " %lux\n", nv->head2);
  762. printitem(ctlr->name, "cursorconfig");
  763. Bprint(&stdout, " %lux\n", nv->cursorconfig);
  764. printitem(ctlr->name, "dither");
  765. Bprint(&stdout, " %lux\n", nv->dither);
  766. printitem(ctlr->name, "islcd");
  767. Bprint(&stdout, " %d\n", nv->islcd);
  768. printitem(ctlr->name, "twoheads");
  769. Bprint(&stdout, " %d\n", nv->twoheads);
  770. printitem(ctlr->name, "twostagepll");
  771. Bprint(&stdout, " %d\n", nv->twostagepll);
  772. printitem(ctlr->name, "crtcnumber");
  773. Bprint(&stdout, " %d\n", nv->crtcnumber);
  774. }
  775. Ctlr nvidia = {
  776. "nvidia", /* name */
  777. snarf, /* snarf */
  778. options, /* options */
  779. init, /* init */
  780. load, /* load */
  781. dump, /* dump */
  782. };
  783. Ctlr nvidiahwgc = {
  784. "nvidiahwgc", /* name */
  785. 0, /* snarf */
  786. 0, /* options */
  787. 0, /* init */
  788. 0, /* load */
  789. 0, /* dump */
  790. };