nvidia.c 32 KB

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