nvd0_display.c 45 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703
  1. /*
  2. * Copyright 2011 Red Hat Inc.
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a
  5. * copy of this software and associated documentation files (the "Software"),
  6. * to deal in the Software without restriction, including without limitation
  7. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  8. * and/or sell copies of the Software, and to permit persons to whom the
  9. * Software is furnished to do so, subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice shall be included in
  12. * all copies or substantial portions of the Software.
  13. *
  14. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  17. * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
  18. * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  19. * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  20. * OTHER DEALINGS IN THE SOFTWARE.
  21. *
  22. * Authors: Ben Skeggs
  23. */
  24. #include <linux/dma-mapping.h>
  25. #include "drmP.h"
  26. #include "drm_crtc_helper.h"
  27. #include "nouveau_drv.h"
  28. #include "nouveau_connector.h"
  29. #include "nouveau_encoder.h"
  30. #include "nouveau_crtc.h"
  31. #include "nouveau_dma.h"
  32. #include "nouveau_fb.h"
  33. #include "nv50_display.h"
  34. #define EVO_MASTER (0x00)
  35. #define EVO_SYNC(c) (0x01 + (c))
  36. #define EVO_CURS(c) (0x0d + (c))
  37. struct nvd0_display {
  38. struct nouveau_gpuobj *mem;
  39. struct {
  40. dma_addr_t handle;
  41. u32 *ptr;
  42. } evo[3];
  43. struct tasklet_struct tasklet;
  44. u32 modeset;
  45. };
  46. static struct nvd0_display *
  47. nvd0_display(struct drm_device *dev)
  48. {
  49. struct drm_nouveau_private *dev_priv = dev->dev_private;
  50. return dev_priv->engine.display.priv;
  51. }
  52. static struct drm_crtc *
  53. nvd0_display_crtc_get(struct drm_encoder *encoder)
  54. {
  55. return nouveau_encoder(encoder)->crtc;
  56. }
  57. /******************************************************************************
  58. * EVO channel helpers
  59. *****************************************************************************/
  60. static inline int
  61. evo_icmd(struct drm_device *dev, int id, u32 mthd, u32 data)
  62. {
  63. int ret = 0;
  64. nv_mask(dev, 0x610700 + (id * 0x10), 0x00000001, 0x00000001);
  65. nv_wr32(dev, 0x610704 + (id * 0x10), data);
  66. nv_mask(dev, 0x610704 + (id * 0x10), 0x80000ffc, 0x80000000 | mthd);
  67. if (!nv_wait(dev, 0x610704 + (id * 0x10), 0x80000000, 0x00000000))
  68. ret = -EBUSY;
  69. nv_mask(dev, 0x610700 + (id * 0x10), 0x00000001, 0x00000000);
  70. return ret;
  71. }
  72. static u32 *
  73. evo_wait(struct drm_device *dev, int id, int nr)
  74. {
  75. struct nvd0_display *disp = nvd0_display(dev);
  76. u32 put = nv_rd32(dev, 0x640000 + (id * 0x1000)) / 4;
  77. if (put + nr >= (PAGE_SIZE / 4)) {
  78. disp->evo[id].ptr[put] = 0x20000000;
  79. nv_wr32(dev, 0x640000 + (id * 0x1000), 0x00000000);
  80. if (!nv_wait(dev, 0x640004 + (id * 0x1000), ~0, 0x00000000)) {
  81. NV_ERROR(dev, "evo %d dma stalled\n", id);
  82. return NULL;
  83. }
  84. put = 0;
  85. }
  86. if (nouveau_reg_debug & NOUVEAU_REG_DEBUG_EVO)
  87. NV_INFO(dev, "Evo%d: %p START\n", id, disp->evo[id].ptr + put);
  88. return disp->evo[id].ptr + put;
  89. }
  90. static void
  91. evo_kick(u32 *push, struct drm_device *dev, int id)
  92. {
  93. struct nvd0_display *disp = nvd0_display(dev);
  94. if (nouveau_reg_debug & NOUVEAU_REG_DEBUG_EVO) {
  95. u32 curp = nv_rd32(dev, 0x640000 + (id * 0x1000)) >> 2;
  96. u32 *cur = disp->evo[id].ptr + curp;
  97. while (cur < push)
  98. NV_INFO(dev, "Evo%d: 0x%08x\n", id, *cur++);
  99. NV_INFO(dev, "Evo%d: %p KICK!\n", id, push);
  100. }
  101. nv_wr32(dev, 0x640000 + (id * 0x1000), (push - disp->evo[id].ptr) << 2);
  102. }
  103. #define evo_mthd(p,m,s) *((p)++) = (((s) << 18) | (m))
  104. #define evo_data(p,d) *((p)++) = (d)
  105. static int
  106. evo_init_dma(struct drm_device *dev, int ch)
  107. {
  108. struct nvd0_display *disp = nvd0_display(dev);
  109. u32 flags;
  110. flags = 0x00000000;
  111. if (ch == EVO_MASTER)
  112. flags |= 0x01000000;
  113. nv_wr32(dev, 0x610494 + (ch * 0x0010), (disp->evo[ch].handle >> 8) | 3);
  114. nv_wr32(dev, 0x610498 + (ch * 0x0010), 0x00010000);
  115. nv_wr32(dev, 0x61049c + (ch * 0x0010), 0x00000001);
  116. nv_mask(dev, 0x610490 + (ch * 0x0010), 0x00000010, 0x00000010);
  117. nv_wr32(dev, 0x640000 + (ch * 0x1000), 0x00000000);
  118. nv_wr32(dev, 0x610490 + (ch * 0x0010), 0x00000013 | flags);
  119. if (!nv_wait(dev, 0x610490 + (ch * 0x0010), 0x80000000, 0x00000000)) {
  120. NV_ERROR(dev, "PDISP: ch%d 0x%08x\n", ch,
  121. nv_rd32(dev, 0x610490 + (ch * 0x0010)));
  122. return -EBUSY;
  123. }
  124. nv_mask(dev, 0x610090, (1 << ch), (1 << ch));
  125. nv_mask(dev, 0x6100a0, (1 << ch), (1 << ch));
  126. return 0;
  127. }
  128. static void
  129. evo_fini_dma(struct drm_device *dev, int ch)
  130. {
  131. if (!(nv_rd32(dev, 0x610490 + (ch * 0x0010)) & 0x00000010))
  132. return;
  133. nv_mask(dev, 0x610490 + (ch * 0x0010), 0x00000010, 0x00000000);
  134. nv_mask(dev, 0x610490 + (ch * 0x0010), 0x00000003, 0x00000000);
  135. nv_wait(dev, 0x610490 + (ch * 0x0010), 0x80000000, 0x00000000);
  136. nv_mask(dev, 0x610090, (1 << ch), 0x00000000);
  137. nv_mask(dev, 0x6100a0, (1 << ch), 0x00000000);
  138. }
  139. static int
  140. evo_init_pio(struct drm_device *dev, int ch)
  141. {
  142. nv_wr32(dev, 0x610490 + (ch * 0x0010), 0x00000001);
  143. if (!nv_wait(dev, 0x610490 + (ch * 0x0010), 0x00010000, 0x00010000)) {
  144. NV_ERROR(dev, "PDISP: ch%d 0x%08x\n", ch,
  145. nv_rd32(dev, 0x610490 + (ch * 0x0010)));
  146. return -EBUSY;
  147. }
  148. nv_mask(dev, 0x610090, (1 << ch), (1 << ch));
  149. nv_mask(dev, 0x6100a0, (1 << ch), (1 << ch));
  150. return 0;
  151. }
  152. static void
  153. evo_fini_pio(struct drm_device *dev, int ch)
  154. {
  155. if (!(nv_rd32(dev, 0x610490 + (ch * 0x0010)) & 0x00000001))
  156. return;
  157. nv_mask(dev, 0x610490 + (ch * 0x0010), 0x00000010, 0x00000010);
  158. nv_mask(dev, 0x610490 + (ch * 0x0010), 0x00000001, 0x00000000);
  159. nv_wait(dev, 0x610490 + (ch * 0x0010), 0x00010000, 0x00000000);
  160. nv_mask(dev, 0x610090, (1 << ch), 0x00000000);
  161. nv_mask(dev, 0x6100a0, (1 << ch), 0x00000000);
  162. }
  163. /******************************************************************************
  164. * CRTC
  165. *****************************************************************************/
  166. static int
  167. nvd0_crtc_set_dither(struct nouveau_crtc *nv_crtc, bool update)
  168. {
  169. struct drm_device *dev = nv_crtc->base.dev;
  170. struct nouveau_connector *nv_connector;
  171. struct drm_connector *connector;
  172. u32 *push, mode = 0x00;
  173. nv_connector = nouveau_crtc_connector_get(nv_crtc);
  174. connector = &nv_connector->base;
  175. if (nv_connector->dithering_mode == DITHERING_MODE_AUTO) {
  176. if (nv_crtc->base.fb->depth > connector->display_info.bpc * 3)
  177. mode = DITHERING_MODE_DYNAMIC2X2;
  178. } else {
  179. mode = nv_connector->dithering_mode;
  180. }
  181. if (nv_connector->dithering_depth == DITHERING_DEPTH_AUTO) {
  182. if (connector->display_info.bpc >= 8)
  183. mode |= DITHERING_DEPTH_8BPC;
  184. } else {
  185. mode |= nv_connector->dithering_depth;
  186. }
  187. push = evo_wait(dev, 0, 4);
  188. if (push) {
  189. evo_mthd(push, 0x0490 + (nv_crtc->index * 0x300), 1);
  190. evo_data(push, mode);
  191. if (update) {
  192. evo_mthd(push, 0x0080, 1);
  193. evo_data(push, 0x00000000);
  194. }
  195. evo_kick(push, dev, 0);
  196. }
  197. return 0;
  198. }
  199. static int
  200. nvd0_crtc_set_scale(struct nouveau_crtc *nv_crtc, bool update)
  201. {
  202. struct drm_display_mode *omode, *umode = &nv_crtc->base.mode;
  203. struct drm_device *dev = nv_crtc->base.dev;
  204. struct nouveau_connector *nv_connector;
  205. int mode = DRM_MODE_SCALE_NONE;
  206. u32 oX, oY, *push;
  207. /* start off at the resolution we programmed the crtc for, this
  208. * effectively handles NONE/FULL scaling
  209. */
  210. nv_connector = nouveau_crtc_connector_get(nv_crtc);
  211. if (nv_connector && nv_connector->native_mode)
  212. mode = nv_connector->scaling_mode;
  213. if (mode != DRM_MODE_SCALE_NONE)
  214. omode = nv_connector->native_mode;
  215. else
  216. omode = umode;
  217. oX = omode->hdisplay;
  218. oY = omode->vdisplay;
  219. if (omode->flags & DRM_MODE_FLAG_DBLSCAN)
  220. oY *= 2;
  221. /* add overscan compensation if necessary, will keep the aspect
  222. * ratio the same as the backend mode unless overridden by the
  223. * user setting both hborder and vborder properties.
  224. */
  225. if (nv_connector && ( nv_connector->underscan == UNDERSCAN_ON ||
  226. (nv_connector->underscan == UNDERSCAN_AUTO &&
  227. nv_connector->edid &&
  228. drm_detect_hdmi_monitor(nv_connector->edid)))) {
  229. u32 bX = nv_connector->underscan_hborder;
  230. u32 bY = nv_connector->underscan_vborder;
  231. u32 aspect = (oY << 19) / oX;
  232. if (bX) {
  233. oX -= (bX * 2);
  234. if (bY) oY -= (bY * 2);
  235. else oY = ((oX * aspect) + (aspect / 2)) >> 19;
  236. } else {
  237. oX -= (oX >> 4) + 32;
  238. if (bY) oY -= (bY * 2);
  239. else oY = ((oX * aspect) + (aspect / 2)) >> 19;
  240. }
  241. }
  242. /* handle CENTER/ASPECT scaling, taking into account the areas
  243. * removed already for overscan compensation
  244. */
  245. switch (mode) {
  246. case DRM_MODE_SCALE_CENTER:
  247. oX = min((u32)umode->hdisplay, oX);
  248. oY = min((u32)umode->vdisplay, oY);
  249. /* fall-through */
  250. case DRM_MODE_SCALE_ASPECT:
  251. if (oY < oX) {
  252. u32 aspect = (umode->hdisplay << 19) / umode->vdisplay;
  253. oX = ((oY * aspect) + (aspect / 2)) >> 19;
  254. } else {
  255. u32 aspect = (umode->vdisplay << 19) / umode->hdisplay;
  256. oY = ((oX * aspect) + (aspect / 2)) >> 19;
  257. }
  258. break;
  259. default:
  260. break;
  261. }
  262. push = evo_wait(dev, 0, 16);
  263. if (push) {
  264. evo_mthd(push, 0x04c0 + (nv_crtc->index * 0x300), 3);
  265. evo_data(push, (oY << 16) | oX);
  266. evo_data(push, (oY << 16) | oX);
  267. evo_data(push, (oY << 16) | oX);
  268. evo_mthd(push, 0x0494 + (nv_crtc->index * 0x300), 1);
  269. evo_data(push, 0x00000000);
  270. evo_mthd(push, 0x04b8 + (nv_crtc->index * 0x300), 1);
  271. evo_data(push, (umode->vdisplay << 16) | umode->hdisplay);
  272. if (update) {
  273. evo_mthd(push, 0x0080, 1);
  274. evo_data(push, 0x00000000);
  275. }
  276. evo_kick(push, dev, 0);
  277. }
  278. return 0;
  279. }
  280. static int
  281. nvd0_crtc_set_image(struct nouveau_crtc *nv_crtc, struct drm_framebuffer *fb,
  282. int x, int y, bool update)
  283. {
  284. struct nouveau_framebuffer *nvfb = nouveau_framebuffer(fb);
  285. u32 *push;
  286. push = evo_wait(fb->dev, 0, 16);
  287. if (push) {
  288. evo_mthd(push, 0x0460 + (nv_crtc->index * 0x300), 1);
  289. evo_data(push, nvfb->nvbo->bo.offset >> 8);
  290. evo_mthd(push, 0x0468 + (nv_crtc->index * 0x300), 4);
  291. evo_data(push, (fb->height << 16) | fb->width);
  292. evo_data(push, nvfb->r_pitch);
  293. evo_data(push, nvfb->r_format);
  294. evo_data(push, nvfb->r_dma);
  295. evo_mthd(push, 0x04b0 + (nv_crtc->index * 0x300), 1);
  296. evo_data(push, (y << 16) | x);
  297. if (update) {
  298. evo_mthd(push, 0x0080, 1);
  299. evo_data(push, 0x00000000);
  300. }
  301. evo_kick(push, fb->dev, 0);
  302. }
  303. nv_crtc->fb.tile_flags = nvfb->r_dma;
  304. return 0;
  305. }
  306. static void
  307. nvd0_crtc_cursor_show(struct nouveau_crtc *nv_crtc, bool show, bool update)
  308. {
  309. struct drm_device *dev = nv_crtc->base.dev;
  310. u32 *push = evo_wait(dev, 0, 16);
  311. if (push) {
  312. if (show) {
  313. evo_mthd(push, 0x0480 + (nv_crtc->index * 0x300), 2);
  314. evo_data(push, 0x85000000);
  315. evo_data(push, nv_crtc->cursor.nvbo->bo.offset >> 8);
  316. evo_mthd(push, 0x048c + (nv_crtc->index * 0x300), 1);
  317. evo_data(push, NvEvoVRAM);
  318. } else {
  319. evo_mthd(push, 0x0480 + (nv_crtc->index * 0x300), 1);
  320. evo_data(push, 0x05000000);
  321. evo_mthd(push, 0x048c + (nv_crtc->index * 0x300), 1);
  322. evo_data(push, 0x00000000);
  323. }
  324. if (update) {
  325. evo_mthd(push, 0x0080, 1);
  326. evo_data(push, 0x00000000);
  327. }
  328. evo_kick(push, dev, 0);
  329. }
  330. }
  331. static void
  332. nvd0_crtc_dpms(struct drm_crtc *crtc, int mode)
  333. {
  334. }
  335. static void
  336. nvd0_crtc_prepare(struct drm_crtc *crtc)
  337. {
  338. struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc);
  339. u32 *push;
  340. push = evo_wait(crtc->dev, 0, 2);
  341. if (push) {
  342. evo_mthd(push, 0x0474 + (nv_crtc->index * 0x300), 1);
  343. evo_data(push, 0x00000000);
  344. evo_mthd(push, 0x0440 + (nv_crtc->index * 0x300), 1);
  345. evo_data(push, 0x03000000);
  346. evo_mthd(push, 0x045c + (nv_crtc->index * 0x300), 1);
  347. evo_data(push, 0x00000000);
  348. evo_kick(push, crtc->dev, 0);
  349. }
  350. nvd0_crtc_cursor_show(nv_crtc, false, false);
  351. }
  352. static void
  353. nvd0_crtc_commit(struct drm_crtc *crtc)
  354. {
  355. struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc);
  356. u32 *push;
  357. push = evo_wait(crtc->dev, 0, 32);
  358. if (push) {
  359. evo_mthd(push, 0x0474 + (nv_crtc->index * 0x300), 1);
  360. evo_data(push, nv_crtc->fb.tile_flags);
  361. evo_mthd(push, 0x0440 + (nv_crtc->index * 0x300), 4);
  362. evo_data(push, 0x83000000);
  363. evo_data(push, nv_crtc->lut.nvbo->bo.offset >> 8);
  364. evo_data(push, 0x00000000);
  365. evo_data(push, 0x00000000);
  366. evo_mthd(push, 0x045c + (nv_crtc->index * 0x300), 1);
  367. evo_data(push, NvEvoVRAM);
  368. evo_mthd(push, 0x0430 + (nv_crtc->index * 0x300), 1);
  369. evo_data(push, 0xffffff00);
  370. evo_kick(push, crtc->dev, 0);
  371. }
  372. nvd0_crtc_cursor_show(nv_crtc, nv_crtc->cursor.visible, true);
  373. }
  374. static bool
  375. nvd0_crtc_mode_fixup(struct drm_crtc *crtc, struct drm_display_mode *mode,
  376. struct drm_display_mode *adjusted_mode)
  377. {
  378. return true;
  379. }
  380. static int
  381. nvd0_crtc_swap_fbs(struct drm_crtc *crtc, struct drm_framebuffer *old_fb)
  382. {
  383. struct nouveau_framebuffer *nvfb = nouveau_framebuffer(crtc->fb);
  384. int ret;
  385. ret = nouveau_bo_pin(nvfb->nvbo, TTM_PL_FLAG_VRAM);
  386. if (ret)
  387. return ret;
  388. if (old_fb) {
  389. nvfb = nouveau_framebuffer(old_fb);
  390. nouveau_bo_unpin(nvfb->nvbo);
  391. }
  392. return 0;
  393. }
  394. static int
  395. nvd0_crtc_mode_set(struct drm_crtc *crtc, struct drm_display_mode *umode,
  396. struct drm_display_mode *mode, int x, int y,
  397. struct drm_framebuffer *old_fb)
  398. {
  399. struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc);
  400. struct nouveau_connector *nv_connector;
  401. u32 ilace = (mode->flags & DRM_MODE_FLAG_INTERLACE) ? 2 : 1;
  402. u32 vscan = (mode->flags & DRM_MODE_FLAG_DBLSCAN) ? 2 : 1;
  403. u32 hactive, hsynce, hbackp, hfrontp, hblanke, hblanks;
  404. u32 vactive, vsynce, vbackp, vfrontp, vblanke, vblanks;
  405. u32 vblan2e = 0, vblan2s = 1;
  406. u32 magic = 0x31ec6000;
  407. u32 syncs, *push;
  408. int ret;
  409. hactive = mode->htotal;
  410. hsynce = mode->hsync_end - mode->hsync_start - 1;
  411. hbackp = mode->htotal - mode->hsync_end;
  412. hblanke = hsynce + hbackp;
  413. hfrontp = mode->hsync_start - mode->hdisplay;
  414. hblanks = mode->htotal - hfrontp - 1;
  415. vactive = mode->vtotal * vscan / ilace;
  416. vsynce = ((mode->vsync_end - mode->vsync_start) * vscan / ilace) - 1;
  417. vbackp = (mode->vtotal - mode->vsync_end) * vscan / ilace;
  418. vblanke = vsynce + vbackp;
  419. vfrontp = (mode->vsync_start - mode->vdisplay) * vscan / ilace;
  420. vblanks = vactive - vfrontp - 1;
  421. if (mode->flags & DRM_MODE_FLAG_INTERLACE) {
  422. vblan2e = vactive + vsynce + vbackp;
  423. vblan2s = vblan2e + (mode->vdisplay * vscan / ilace);
  424. vactive = (vactive * 2) + 1;
  425. magic |= 0x00000001;
  426. }
  427. syncs = 0x00000001;
  428. if (mode->flags & DRM_MODE_FLAG_NHSYNC)
  429. syncs |= 0x00000008;
  430. if (mode->flags & DRM_MODE_FLAG_NVSYNC)
  431. syncs |= 0x00000010;
  432. ret = nvd0_crtc_swap_fbs(crtc, old_fb);
  433. if (ret)
  434. return ret;
  435. push = evo_wait(crtc->dev, 0, 64);
  436. if (push) {
  437. evo_mthd(push, 0x0410 + (nv_crtc->index * 0x300), 6);
  438. evo_data(push, 0x00000000);
  439. evo_data(push, (vactive << 16) | hactive);
  440. evo_data(push, ( vsynce << 16) | hsynce);
  441. evo_data(push, (vblanke << 16) | hblanke);
  442. evo_data(push, (vblanks << 16) | hblanks);
  443. evo_data(push, (vblan2e << 16) | vblan2s);
  444. evo_mthd(push, 0x042c + (nv_crtc->index * 0x300), 1);
  445. evo_data(push, 0x00000000); /* ??? */
  446. evo_mthd(push, 0x0450 + (nv_crtc->index * 0x300), 3);
  447. evo_data(push, mode->clock * 1000);
  448. evo_data(push, 0x00200000); /* ??? */
  449. evo_data(push, mode->clock * 1000);
  450. evo_mthd(push, 0x0404 + (nv_crtc->index * 0x300), 2);
  451. evo_data(push, syncs);
  452. evo_data(push, magic);
  453. evo_kick(push, crtc->dev, 0);
  454. }
  455. nv_connector = nouveau_crtc_connector_get(nv_crtc);
  456. nvd0_crtc_set_dither(nv_crtc, false);
  457. nvd0_crtc_set_scale(nv_crtc, false);
  458. nvd0_crtc_set_image(nv_crtc, crtc->fb, x, y, false);
  459. return 0;
  460. }
  461. static int
  462. nvd0_crtc_mode_set_base(struct drm_crtc *crtc, int x, int y,
  463. struct drm_framebuffer *old_fb)
  464. {
  465. struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc);
  466. int ret;
  467. if (!crtc->fb) {
  468. NV_DEBUG_KMS(crtc->dev, "No FB bound\n");
  469. return 0;
  470. }
  471. ret = nvd0_crtc_swap_fbs(crtc, old_fb);
  472. if (ret)
  473. return ret;
  474. nvd0_crtc_set_image(nv_crtc, crtc->fb, x, y, true);
  475. return 0;
  476. }
  477. static int
  478. nvd0_crtc_mode_set_base_atomic(struct drm_crtc *crtc,
  479. struct drm_framebuffer *fb, int x, int y,
  480. enum mode_set_atomic state)
  481. {
  482. struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc);
  483. nvd0_crtc_set_image(nv_crtc, fb, x, y, true);
  484. return 0;
  485. }
  486. static void
  487. nvd0_crtc_lut_load(struct drm_crtc *crtc)
  488. {
  489. struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc);
  490. void __iomem *lut = nvbo_kmap_obj_iovirtual(nv_crtc->lut.nvbo);
  491. int i;
  492. for (i = 0; i < 256; i++) {
  493. writew(0x6000 + (nv_crtc->lut.r[i] >> 2), lut + (i * 0x20) + 0);
  494. writew(0x6000 + (nv_crtc->lut.g[i] >> 2), lut + (i * 0x20) + 2);
  495. writew(0x6000 + (nv_crtc->lut.b[i] >> 2), lut + (i * 0x20) + 4);
  496. }
  497. }
  498. static int
  499. nvd0_crtc_cursor_set(struct drm_crtc *crtc, struct drm_file *file_priv,
  500. uint32_t handle, uint32_t width, uint32_t height)
  501. {
  502. struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc);
  503. struct drm_device *dev = crtc->dev;
  504. struct drm_gem_object *gem;
  505. struct nouveau_bo *nvbo;
  506. bool visible = (handle != 0);
  507. int i, ret = 0;
  508. if (visible) {
  509. if (width != 64 || height != 64)
  510. return -EINVAL;
  511. gem = drm_gem_object_lookup(dev, file_priv, handle);
  512. if (unlikely(!gem))
  513. return -ENOENT;
  514. nvbo = nouveau_gem_object(gem);
  515. ret = nouveau_bo_map(nvbo);
  516. if (ret == 0) {
  517. for (i = 0; i < 64 * 64; i++) {
  518. u32 v = nouveau_bo_rd32(nvbo, i);
  519. nouveau_bo_wr32(nv_crtc->cursor.nvbo, i, v);
  520. }
  521. nouveau_bo_unmap(nvbo);
  522. }
  523. drm_gem_object_unreference_unlocked(gem);
  524. }
  525. if (visible != nv_crtc->cursor.visible) {
  526. nvd0_crtc_cursor_show(nv_crtc, visible, true);
  527. nv_crtc->cursor.visible = visible;
  528. }
  529. return ret;
  530. }
  531. static int
  532. nvd0_crtc_cursor_move(struct drm_crtc *crtc, int x, int y)
  533. {
  534. struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc);
  535. const u32 data = (y << 16) | x;
  536. nv_wr32(crtc->dev, 0x64d084 + (nv_crtc->index * 0x1000), data);
  537. nv_wr32(crtc->dev, 0x64d080 + (nv_crtc->index * 0x1000), 0x00000000);
  538. return 0;
  539. }
  540. static void
  541. nvd0_crtc_gamma_set(struct drm_crtc *crtc, u16 *r, u16 *g, u16 *b,
  542. uint32_t start, uint32_t size)
  543. {
  544. struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc);
  545. u32 end = max(start + size, (u32)256);
  546. u32 i;
  547. for (i = start; i < end; i++) {
  548. nv_crtc->lut.r[i] = r[i];
  549. nv_crtc->lut.g[i] = g[i];
  550. nv_crtc->lut.b[i] = b[i];
  551. }
  552. nvd0_crtc_lut_load(crtc);
  553. }
  554. static void
  555. nvd0_crtc_destroy(struct drm_crtc *crtc)
  556. {
  557. struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc);
  558. nouveau_bo_unmap(nv_crtc->cursor.nvbo);
  559. nouveau_bo_ref(NULL, &nv_crtc->cursor.nvbo);
  560. nouveau_bo_unmap(nv_crtc->lut.nvbo);
  561. nouveau_bo_ref(NULL, &nv_crtc->lut.nvbo);
  562. drm_crtc_cleanup(crtc);
  563. kfree(crtc);
  564. }
  565. static const struct drm_crtc_helper_funcs nvd0_crtc_hfunc = {
  566. .dpms = nvd0_crtc_dpms,
  567. .prepare = nvd0_crtc_prepare,
  568. .commit = nvd0_crtc_commit,
  569. .mode_fixup = nvd0_crtc_mode_fixup,
  570. .mode_set = nvd0_crtc_mode_set,
  571. .mode_set_base = nvd0_crtc_mode_set_base,
  572. .mode_set_base_atomic = nvd0_crtc_mode_set_base_atomic,
  573. .load_lut = nvd0_crtc_lut_load,
  574. };
  575. static const struct drm_crtc_funcs nvd0_crtc_func = {
  576. .cursor_set = nvd0_crtc_cursor_set,
  577. .cursor_move = nvd0_crtc_cursor_move,
  578. .gamma_set = nvd0_crtc_gamma_set,
  579. .set_config = drm_crtc_helper_set_config,
  580. .destroy = nvd0_crtc_destroy,
  581. };
  582. static void
  583. nvd0_cursor_set_pos(struct nouveau_crtc *nv_crtc, int x, int y)
  584. {
  585. }
  586. static void
  587. nvd0_cursor_set_offset(struct nouveau_crtc *nv_crtc, uint32_t offset)
  588. {
  589. }
  590. static int
  591. nvd0_crtc_create(struct drm_device *dev, int index)
  592. {
  593. struct nouveau_crtc *nv_crtc;
  594. struct drm_crtc *crtc;
  595. int ret, i;
  596. nv_crtc = kzalloc(sizeof(*nv_crtc), GFP_KERNEL);
  597. if (!nv_crtc)
  598. return -ENOMEM;
  599. nv_crtc->index = index;
  600. nv_crtc->set_dither = nvd0_crtc_set_dither;
  601. nv_crtc->set_scale = nvd0_crtc_set_scale;
  602. nv_crtc->cursor.set_offset = nvd0_cursor_set_offset;
  603. nv_crtc->cursor.set_pos = nvd0_cursor_set_pos;
  604. for (i = 0; i < 256; i++) {
  605. nv_crtc->lut.r[i] = i << 8;
  606. nv_crtc->lut.g[i] = i << 8;
  607. nv_crtc->lut.b[i] = i << 8;
  608. }
  609. crtc = &nv_crtc->base;
  610. drm_crtc_init(dev, crtc, &nvd0_crtc_func);
  611. drm_crtc_helper_add(crtc, &nvd0_crtc_hfunc);
  612. drm_mode_crtc_set_gamma_size(crtc, 256);
  613. ret = nouveau_bo_new(dev, 64 * 64 * 4, 0x100, TTM_PL_FLAG_VRAM,
  614. 0, 0x0000, &nv_crtc->cursor.nvbo);
  615. if (!ret) {
  616. ret = nouveau_bo_pin(nv_crtc->cursor.nvbo, TTM_PL_FLAG_VRAM);
  617. if (!ret)
  618. ret = nouveau_bo_map(nv_crtc->cursor.nvbo);
  619. if (ret)
  620. nouveau_bo_ref(NULL, &nv_crtc->cursor.nvbo);
  621. }
  622. if (ret)
  623. goto out;
  624. ret = nouveau_bo_new(dev, 8192, 0x100, TTM_PL_FLAG_VRAM,
  625. 0, 0x0000, &nv_crtc->lut.nvbo);
  626. if (!ret) {
  627. ret = nouveau_bo_pin(nv_crtc->lut.nvbo, TTM_PL_FLAG_VRAM);
  628. if (!ret)
  629. ret = nouveau_bo_map(nv_crtc->lut.nvbo);
  630. if (ret)
  631. nouveau_bo_ref(NULL, &nv_crtc->lut.nvbo);
  632. }
  633. if (ret)
  634. goto out;
  635. nvd0_crtc_lut_load(crtc);
  636. out:
  637. if (ret)
  638. nvd0_crtc_destroy(crtc);
  639. return ret;
  640. }
  641. /******************************************************************************
  642. * DAC
  643. *****************************************************************************/
  644. static void
  645. nvd0_dac_dpms(struct drm_encoder *encoder, int mode)
  646. {
  647. struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
  648. struct drm_device *dev = encoder->dev;
  649. int or = nv_encoder->or;
  650. u32 dpms_ctrl;
  651. dpms_ctrl = 0x80000000;
  652. if (mode == DRM_MODE_DPMS_STANDBY || mode == DRM_MODE_DPMS_OFF)
  653. dpms_ctrl |= 0x00000001;
  654. if (mode == DRM_MODE_DPMS_SUSPEND || mode == DRM_MODE_DPMS_OFF)
  655. dpms_ctrl |= 0x00000004;
  656. nv_wait(dev, 0x61a004 + (or * 0x0800), 0x80000000, 0x00000000);
  657. nv_mask(dev, 0x61a004 + (or * 0x0800), 0xc000007f, dpms_ctrl);
  658. nv_wait(dev, 0x61a004 + (or * 0x0800), 0x80000000, 0x00000000);
  659. }
  660. static bool
  661. nvd0_dac_mode_fixup(struct drm_encoder *encoder, struct drm_display_mode *mode,
  662. struct drm_display_mode *adjusted_mode)
  663. {
  664. struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
  665. struct nouveau_connector *nv_connector;
  666. nv_connector = nouveau_encoder_connector_get(nv_encoder);
  667. if (nv_connector && nv_connector->native_mode) {
  668. if (nv_connector->scaling_mode != DRM_MODE_SCALE_NONE) {
  669. int id = adjusted_mode->base.id;
  670. *adjusted_mode = *nv_connector->native_mode;
  671. adjusted_mode->base.id = id;
  672. }
  673. }
  674. return true;
  675. }
  676. static void
  677. nvd0_dac_prepare(struct drm_encoder *encoder)
  678. {
  679. }
  680. static void
  681. nvd0_dac_commit(struct drm_encoder *encoder)
  682. {
  683. }
  684. static void
  685. nvd0_dac_mode_set(struct drm_encoder *encoder, struct drm_display_mode *mode,
  686. struct drm_display_mode *adjusted_mode)
  687. {
  688. struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
  689. struct nouveau_crtc *nv_crtc = nouveau_crtc(encoder->crtc);
  690. u32 *push;
  691. nvd0_dac_dpms(encoder, DRM_MODE_DPMS_ON);
  692. push = evo_wait(encoder->dev, 0, 4);
  693. if (push) {
  694. evo_mthd(push, 0x0180 + (nv_encoder->or * 0x20), 2);
  695. evo_data(push, 1 << nv_crtc->index);
  696. evo_data(push, 0x00ff);
  697. evo_kick(push, encoder->dev, 0);
  698. }
  699. nv_encoder->crtc = encoder->crtc;
  700. }
  701. static void
  702. nvd0_dac_disconnect(struct drm_encoder *encoder)
  703. {
  704. struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
  705. struct drm_device *dev = encoder->dev;
  706. u32 *push;
  707. if (nv_encoder->crtc) {
  708. nvd0_crtc_prepare(nv_encoder->crtc);
  709. push = evo_wait(dev, 0, 4);
  710. if (push) {
  711. evo_mthd(push, 0x0180 + (nv_encoder->or * 0x20), 1);
  712. evo_data(push, 0x00000000);
  713. evo_mthd(push, 0x0080, 1);
  714. evo_data(push, 0x00000000);
  715. evo_kick(push, dev, 0);
  716. }
  717. nv_encoder->crtc = NULL;
  718. }
  719. }
  720. static enum drm_connector_status
  721. nvd0_dac_detect(struct drm_encoder *encoder, struct drm_connector *connector)
  722. {
  723. enum drm_connector_status status = connector_status_disconnected;
  724. struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
  725. struct drm_device *dev = encoder->dev;
  726. int or = nv_encoder->or;
  727. u32 load;
  728. nv_wr32(dev, 0x61a00c + (or * 0x800), 0x00100000);
  729. udelay(9500);
  730. nv_wr32(dev, 0x61a00c + (or * 0x800), 0x80000000);
  731. load = nv_rd32(dev, 0x61a00c + (or * 0x800));
  732. if ((load & 0x38000000) == 0x38000000)
  733. status = connector_status_connected;
  734. nv_wr32(dev, 0x61a00c + (or * 0x800), 0x00000000);
  735. return status;
  736. }
  737. static void
  738. nvd0_dac_destroy(struct drm_encoder *encoder)
  739. {
  740. drm_encoder_cleanup(encoder);
  741. kfree(encoder);
  742. }
  743. static const struct drm_encoder_helper_funcs nvd0_dac_hfunc = {
  744. .dpms = nvd0_dac_dpms,
  745. .mode_fixup = nvd0_dac_mode_fixup,
  746. .prepare = nvd0_dac_prepare,
  747. .commit = nvd0_dac_commit,
  748. .mode_set = nvd0_dac_mode_set,
  749. .disable = nvd0_dac_disconnect,
  750. .get_crtc = nvd0_display_crtc_get,
  751. .detect = nvd0_dac_detect
  752. };
  753. static const struct drm_encoder_funcs nvd0_dac_func = {
  754. .destroy = nvd0_dac_destroy,
  755. };
  756. static int
  757. nvd0_dac_create(struct drm_connector *connector, struct dcb_entry *dcbe)
  758. {
  759. struct drm_device *dev = connector->dev;
  760. struct nouveau_encoder *nv_encoder;
  761. struct drm_encoder *encoder;
  762. nv_encoder = kzalloc(sizeof(*nv_encoder), GFP_KERNEL);
  763. if (!nv_encoder)
  764. return -ENOMEM;
  765. nv_encoder->dcb = dcbe;
  766. nv_encoder->or = ffs(dcbe->or) - 1;
  767. encoder = to_drm_encoder(nv_encoder);
  768. encoder->possible_crtcs = dcbe->heads;
  769. encoder->possible_clones = 0;
  770. drm_encoder_init(dev, encoder, &nvd0_dac_func, DRM_MODE_ENCODER_DAC);
  771. drm_encoder_helper_add(encoder, &nvd0_dac_hfunc);
  772. drm_mode_connector_attach_encoder(connector, encoder);
  773. return 0;
  774. }
  775. /******************************************************************************
  776. * Audio
  777. *****************************************************************************/
  778. static void
  779. nvd0_audio_mode_set(struct drm_encoder *encoder, struct drm_display_mode *mode)
  780. {
  781. struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
  782. struct nouveau_connector *nv_connector;
  783. struct drm_device *dev = encoder->dev;
  784. int i, or = nv_encoder->or * 0x30;
  785. nv_connector = nouveau_encoder_connector_get(nv_encoder);
  786. if (!drm_detect_monitor_audio(nv_connector->edid))
  787. return;
  788. nv_mask(dev, 0x10ec10 + or, 0x80000003, 0x80000001);
  789. drm_edid_to_eld(&nv_connector->base, nv_connector->edid);
  790. if (nv_connector->base.eld[0]) {
  791. u8 *eld = nv_connector->base.eld;
  792. for (i = 0; i < eld[2] * 4; i++)
  793. nv_wr32(dev, 0x10ec00 + or, (i << 8) | eld[i]);
  794. for (i = eld[2] * 4; i < 0x60; i++)
  795. nv_wr32(dev, 0x10ec00 + or, (i << 8) | 0x00);
  796. nv_mask(dev, 0x10ec10 + or, 0x80000002, 0x80000002);
  797. }
  798. }
  799. static void
  800. nvd0_audio_disconnect(struct drm_encoder *encoder)
  801. {
  802. struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
  803. struct drm_device *dev = encoder->dev;
  804. int or = nv_encoder->or * 0x30;
  805. nv_mask(dev, 0x10ec10 + or, 0x80000003, 0x80000000);
  806. }
  807. /******************************************************************************
  808. * HDMI
  809. *****************************************************************************/
  810. static void
  811. nvd0_hdmi_mode_set(struct drm_encoder *encoder, struct drm_display_mode *mode)
  812. {
  813. struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
  814. struct nouveau_crtc *nv_crtc = nouveau_crtc(encoder->crtc);
  815. struct nouveau_connector *nv_connector;
  816. struct drm_device *dev = encoder->dev;
  817. int head = nv_crtc->index * 0x800;
  818. u32 rekey = 56; /* binary driver, and tegra constant */
  819. u32 max_ac_packet;
  820. nv_connector = nouveau_encoder_connector_get(nv_encoder);
  821. if (!drm_detect_hdmi_monitor(nv_connector->edid))
  822. return;
  823. max_ac_packet = mode->htotal - mode->hdisplay;
  824. max_ac_packet -= rekey;
  825. max_ac_packet -= 18; /* constant from tegra */
  826. max_ac_packet /= 32;
  827. /* AVI InfoFrame */
  828. nv_mask(dev, 0x616714 + head, 0x00000001, 0x00000000);
  829. nv_wr32(dev, 0x61671c + head, 0x000d0282);
  830. nv_wr32(dev, 0x616720 + head, 0x0000006f);
  831. nv_wr32(dev, 0x616724 + head, 0x00000000);
  832. nv_wr32(dev, 0x616728 + head, 0x00000000);
  833. nv_wr32(dev, 0x61672c + head, 0x00000000);
  834. nv_mask(dev, 0x616714 + head, 0x00000001, 0x00000001);
  835. /* ??? InfoFrame? */
  836. nv_mask(dev, 0x6167a4 + head, 0x00000001, 0x00000000);
  837. nv_wr32(dev, 0x6167ac + head, 0x00000010);
  838. nv_mask(dev, 0x6167a4 + head, 0x00000001, 0x00000001);
  839. /* HDMI_CTRL */
  840. nv_mask(dev, 0x616798 + head, 0x401f007f, 0x40000000 | rekey |
  841. max_ac_packet << 16);
  842. /* NFI, audio doesn't work without it though.. */
  843. nv_mask(dev, 0x616548 + head, 0x00000070, 0x00000000);
  844. nvd0_audio_mode_set(encoder, mode);
  845. }
  846. static void
  847. nvd0_hdmi_disconnect(struct drm_encoder *encoder)
  848. {
  849. struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
  850. struct nouveau_crtc *nv_crtc = nouveau_crtc(nv_encoder->crtc);
  851. struct drm_device *dev = encoder->dev;
  852. int head = nv_crtc->index * 0x800;
  853. nvd0_audio_disconnect(encoder);
  854. nv_mask(dev, 0x616798 + head, 0x40000000, 0x00000000);
  855. nv_mask(dev, 0x6167a4 + head, 0x00000001, 0x00000000);
  856. nv_mask(dev, 0x616714 + head, 0x00000001, 0x00000000);
  857. }
  858. /******************************************************************************
  859. * SOR
  860. *****************************************************************************/
  861. static void
  862. nvd0_sor_dpms(struct drm_encoder *encoder, int mode)
  863. {
  864. struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
  865. struct drm_device *dev = encoder->dev;
  866. struct drm_encoder *partner;
  867. int or = nv_encoder->or;
  868. u32 dpms_ctrl;
  869. nv_encoder->last_dpms = mode;
  870. list_for_each_entry(partner, &dev->mode_config.encoder_list, head) {
  871. struct nouveau_encoder *nv_partner = nouveau_encoder(partner);
  872. if (partner->encoder_type != DRM_MODE_ENCODER_TMDS)
  873. continue;
  874. if (nv_partner != nv_encoder &&
  875. nv_partner->dcb->or == nv_encoder->dcb->or) {
  876. if (nv_partner->last_dpms == DRM_MODE_DPMS_ON)
  877. return;
  878. break;
  879. }
  880. }
  881. dpms_ctrl = (mode == DRM_MODE_DPMS_ON);
  882. dpms_ctrl |= 0x80000000;
  883. nv_wait(dev, 0x61c004 + (or * 0x0800), 0x80000000, 0x00000000);
  884. nv_mask(dev, 0x61c004 + (or * 0x0800), 0x80000001, dpms_ctrl);
  885. nv_wait(dev, 0x61c004 + (or * 0x0800), 0x80000000, 0x00000000);
  886. nv_wait(dev, 0x61c030 + (or * 0x0800), 0x10000000, 0x00000000);
  887. }
  888. static bool
  889. nvd0_sor_mode_fixup(struct drm_encoder *encoder, struct drm_display_mode *mode,
  890. struct drm_display_mode *adjusted_mode)
  891. {
  892. struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
  893. struct nouveau_connector *nv_connector;
  894. nv_connector = nouveau_encoder_connector_get(nv_encoder);
  895. if (nv_connector && nv_connector->native_mode) {
  896. if (nv_connector->scaling_mode != DRM_MODE_SCALE_NONE) {
  897. int id = adjusted_mode->base.id;
  898. *adjusted_mode = *nv_connector->native_mode;
  899. adjusted_mode->base.id = id;
  900. }
  901. }
  902. return true;
  903. }
  904. static void
  905. nvd0_sor_prepare(struct drm_encoder *encoder)
  906. {
  907. }
  908. static void
  909. nvd0_sor_commit(struct drm_encoder *encoder)
  910. {
  911. }
  912. static void
  913. nvd0_sor_mode_set(struct drm_encoder *encoder, struct drm_display_mode *umode,
  914. struct drm_display_mode *mode)
  915. {
  916. struct drm_device *dev = encoder->dev;
  917. struct drm_nouveau_private *dev_priv = dev->dev_private;
  918. struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
  919. struct nouveau_crtc *nv_crtc = nouveau_crtc(encoder->crtc);
  920. struct nouveau_connector *nv_connector;
  921. struct nvbios *bios = &dev_priv->vbios;
  922. u32 mode_ctrl = (1 << nv_crtc->index);
  923. u32 *push, or_config;
  924. nv_connector = nouveau_encoder_connector_get(nv_encoder);
  925. switch (nv_encoder->dcb->type) {
  926. case OUTPUT_TMDS:
  927. if (nv_encoder->dcb->sorconf.link & 1) {
  928. if (mode->clock < 165000)
  929. mode_ctrl |= 0x00000100;
  930. else
  931. mode_ctrl |= 0x00000500;
  932. } else {
  933. mode_ctrl |= 0x00000200;
  934. }
  935. or_config = (mode_ctrl & 0x00000f00) >> 8;
  936. if (mode->clock >= 165000)
  937. or_config |= 0x0100;
  938. nvd0_hdmi_mode_set(encoder, mode);
  939. break;
  940. case OUTPUT_LVDS:
  941. or_config = (mode_ctrl & 0x00000f00) >> 8;
  942. if (bios->fp_no_ddc) {
  943. if (bios->fp.dual_link)
  944. or_config |= 0x0100;
  945. if (bios->fp.if_is_24bit)
  946. or_config |= 0x0200;
  947. } else {
  948. if (nv_connector->dcb->type == DCB_CONNECTOR_LVDS_SPWG) {
  949. if (((u8 *)nv_connector->edid)[121] == 2)
  950. or_config |= 0x0100;
  951. } else
  952. if (mode->clock >= bios->fp.duallink_transition_clk) {
  953. or_config |= 0x0100;
  954. }
  955. if (or_config & 0x0100) {
  956. if (bios->fp.strapless_is_24bit & 2)
  957. or_config |= 0x0200;
  958. } else {
  959. if (bios->fp.strapless_is_24bit & 1)
  960. or_config |= 0x0200;
  961. }
  962. if (nv_connector->base.display_info.bpc == 8)
  963. or_config |= 0x0200;
  964. }
  965. break;
  966. default:
  967. BUG_ON(1);
  968. break;
  969. }
  970. nvd0_sor_dpms(encoder, DRM_MODE_DPMS_ON);
  971. push = evo_wait(dev, 0, 4);
  972. if (push) {
  973. evo_mthd(push, 0x0200 + (nv_encoder->or * 0x20), 2);
  974. evo_data(push, mode_ctrl);
  975. evo_data(push, or_config);
  976. evo_kick(push, dev, 0);
  977. }
  978. nv_encoder->crtc = encoder->crtc;
  979. }
  980. static void
  981. nvd0_sor_disconnect(struct drm_encoder *encoder)
  982. {
  983. struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
  984. struct drm_device *dev = encoder->dev;
  985. u32 *push;
  986. if (nv_encoder->crtc) {
  987. nvd0_crtc_prepare(nv_encoder->crtc);
  988. push = evo_wait(dev, 0, 4);
  989. if (push) {
  990. evo_mthd(push, 0x0200 + (nv_encoder->or * 0x20), 1);
  991. evo_data(push, 0x00000000);
  992. evo_mthd(push, 0x0080, 1);
  993. evo_data(push, 0x00000000);
  994. evo_kick(push, dev, 0);
  995. }
  996. nvd0_hdmi_disconnect(encoder);
  997. nv_encoder->crtc = NULL;
  998. nv_encoder->last_dpms = DRM_MODE_DPMS_OFF;
  999. }
  1000. }
  1001. static void
  1002. nvd0_sor_destroy(struct drm_encoder *encoder)
  1003. {
  1004. drm_encoder_cleanup(encoder);
  1005. kfree(encoder);
  1006. }
  1007. static const struct drm_encoder_helper_funcs nvd0_sor_hfunc = {
  1008. .dpms = nvd0_sor_dpms,
  1009. .mode_fixup = nvd0_sor_mode_fixup,
  1010. .prepare = nvd0_sor_prepare,
  1011. .commit = nvd0_sor_commit,
  1012. .mode_set = nvd0_sor_mode_set,
  1013. .disable = nvd0_sor_disconnect,
  1014. .get_crtc = nvd0_display_crtc_get,
  1015. };
  1016. static const struct drm_encoder_funcs nvd0_sor_func = {
  1017. .destroy = nvd0_sor_destroy,
  1018. };
  1019. static int
  1020. nvd0_sor_create(struct drm_connector *connector, struct dcb_entry *dcbe)
  1021. {
  1022. struct drm_device *dev = connector->dev;
  1023. struct nouveau_encoder *nv_encoder;
  1024. struct drm_encoder *encoder;
  1025. nv_encoder = kzalloc(sizeof(*nv_encoder), GFP_KERNEL);
  1026. if (!nv_encoder)
  1027. return -ENOMEM;
  1028. nv_encoder->dcb = dcbe;
  1029. nv_encoder->or = ffs(dcbe->or) - 1;
  1030. nv_encoder->last_dpms = DRM_MODE_DPMS_OFF;
  1031. encoder = to_drm_encoder(nv_encoder);
  1032. encoder->possible_crtcs = dcbe->heads;
  1033. encoder->possible_clones = 0;
  1034. drm_encoder_init(dev, encoder, &nvd0_sor_func, DRM_MODE_ENCODER_TMDS);
  1035. drm_encoder_helper_add(encoder, &nvd0_sor_hfunc);
  1036. drm_mode_connector_attach_encoder(connector, encoder);
  1037. return 0;
  1038. }
  1039. /******************************************************************************
  1040. * IRQ
  1041. *****************************************************************************/
  1042. static struct dcb_entry *
  1043. lookup_dcb(struct drm_device *dev, int id, u32 mc)
  1044. {
  1045. struct drm_nouveau_private *dev_priv = dev->dev_private;
  1046. int type, or, i;
  1047. if (id < 4) {
  1048. type = OUTPUT_ANALOG;
  1049. or = id;
  1050. } else {
  1051. switch (mc & 0x00000f00) {
  1052. case 0x00000000: type = OUTPUT_LVDS; break;
  1053. case 0x00000100: type = OUTPUT_TMDS; break;
  1054. case 0x00000200: type = OUTPUT_TMDS; break;
  1055. case 0x00000500: type = OUTPUT_TMDS; break;
  1056. default:
  1057. NV_ERROR(dev, "PDISP: unknown SOR mc 0x%08x\n", mc);
  1058. return NULL;
  1059. }
  1060. or = id - 4;
  1061. }
  1062. for (i = 0; i < dev_priv->vbios.dcb.entries; i++) {
  1063. struct dcb_entry *dcb = &dev_priv->vbios.dcb.entry[i];
  1064. if (dcb->type == type && (dcb->or & (1 << or)))
  1065. return dcb;
  1066. }
  1067. NV_ERROR(dev, "PDISP: DCB for %d/0x%08x not found\n", id, mc);
  1068. return NULL;
  1069. }
  1070. static void
  1071. nvd0_display_unk1_handler(struct drm_device *dev, u32 crtc, u32 mask)
  1072. {
  1073. struct dcb_entry *dcb;
  1074. int i;
  1075. for (i = 0; mask && i < 8; i++) {
  1076. u32 mcc = nv_rd32(dev, 0x640180 + (i * 0x20));
  1077. if (!(mcc & (1 << crtc)))
  1078. continue;
  1079. dcb = lookup_dcb(dev, i, mcc);
  1080. if (!dcb)
  1081. continue;
  1082. nouveau_bios_run_display_table(dev, 0x0000, -1, dcb, crtc);
  1083. }
  1084. nv_wr32(dev, 0x6101d4, 0x00000000);
  1085. nv_wr32(dev, 0x6109d4, 0x00000000);
  1086. nv_wr32(dev, 0x6101d0, 0x80000000);
  1087. }
  1088. static void
  1089. nvd0_display_unk2_handler(struct drm_device *dev, u32 crtc, u32 mask)
  1090. {
  1091. struct dcb_entry *dcb;
  1092. u32 or, tmp, pclk;
  1093. int i;
  1094. for (i = 0; mask && i < 8; i++) {
  1095. u32 mcc = nv_rd32(dev, 0x640180 + (i * 0x20));
  1096. if (!(mcc & (1 << crtc)))
  1097. continue;
  1098. dcb = lookup_dcb(dev, i, mcc);
  1099. if (!dcb)
  1100. continue;
  1101. nouveau_bios_run_display_table(dev, 0x0000, -2, dcb, crtc);
  1102. }
  1103. pclk = nv_rd32(dev, 0x660450 + (crtc * 0x300)) / 1000;
  1104. if (mask & 0x00010000) {
  1105. nv50_crtc_set_clock(dev, crtc, pclk);
  1106. }
  1107. for (i = 0; mask && i < 8; i++) {
  1108. u32 mcp = nv_rd32(dev, 0x660180 + (i * 0x20));
  1109. u32 cfg = nv_rd32(dev, 0x660184 + (i * 0x20));
  1110. if (!(mcp & (1 << crtc)))
  1111. continue;
  1112. dcb = lookup_dcb(dev, i, mcp);
  1113. if (!dcb)
  1114. continue;
  1115. or = ffs(dcb->or) - 1;
  1116. nouveau_bios_run_display_table(dev, cfg, pclk, dcb, crtc);
  1117. nv_wr32(dev, 0x612200 + (crtc * 0x800), 0x00000000);
  1118. switch (dcb->type) {
  1119. case OUTPUT_ANALOG:
  1120. nv_wr32(dev, 0x612280 + (or * 0x800), 0x00000000);
  1121. break;
  1122. case OUTPUT_TMDS:
  1123. case OUTPUT_LVDS:
  1124. if (cfg & 0x00000100)
  1125. tmp = 0x00000101;
  1126. else
  1127. tmp = 0x00000000;
  1128. nv_mask(dev, 0x612300 + (or * 0x800), 0x00000707, tmp);
  1129. break;
  1130. default:
  1131. break;
  1132. }
  1133. break;
  1134. }
  1135. nv_wr32(dev, 0x6101d4, 0x00000000);
  1136. nv_wr32(dev, 0x6109d4, 0x00000000);
  1137. nv_wr32(dev, 0x6101d0, 0x80000000);
  1138. }
  1139. static void
  1140. nvd0_display_unk4_handler(struct drm_device *dev, u32 crtc, u32 mask)
  1141. {
  1142. struct dcb_entry *dcb;
  1143. int pclk, i;
  1144. pclk = nv_rd32(dev, 0x660450 + (crtc * 0x300)) / 1000;
  1145. for (i = 0; mask && i < 8; i++) {
  1146. u32 mcp = nv_rd32(dev, 0x660180 + (i * 0x20));
  1147. u32 cfg = nv_rd32(dev, 0x660184 + (i * 0x20));
  1148. if (!(mcp & (1 << crtc)))
  1149. continue;
  1150. dcb = lookup_dcb(dev, i, mcp);
  1151. if (!dcb)
  1152. continue;
  1153. nouveau_bios_run_display_table(dev, cfg, -pclk, dcb, crtc);
  1154. }
  1155. nv_wr32(dev, 0x6101d4, 0x00000000);
  1156. nv_wr32(dev, 0x6109d4, 0x00000000);
  1157. nv_wr32(dev, 0x6101d0, 0x80000000);
  1158. }
  1159. static void
  1160. nvd0_display_bh(unsigned long data)
  1161. {
  1162. struct drm_device *dev = (struct drm_device *)data;
  1163. struct nvd0_display *disp = nvd0_display(dev);
  1164. u32 mask, crtc;
  1165. int i;
  1166. if (drm_debug & (DRM_UT_DRIVER | DRM_UT_KMS)) {
  1167. NV_INFO(dev, "PDISP: modeset req %d\n", disp->modeset);
  1168. NV_INFO(dev, " STAT: 0x%08x 0x%08x 0x%08x\n",
  1169. nv_rd32(dev, 0x6101d0),
  1170. nv_rd32(dev, 0x6101d4), nv_rd32(dev, 0x6109d4));
  1171. for (i = 0; i < 8; i++) {
  1172. NV_INFO(dev, " %s%d: 0x%08x 0x%08x\n",
  1173. i < 4 ? "DAC" : "SOR", i,
  1174. nv_rd32(dev, 0x640180 + (i * 0x20)),
  1175. nv_rd32(dev, 0x660180 + (i * 0x20)));
  1176. }
  1177. }
  1178. mask = nv_rd32(dev, 0x6101d4);
  1179. crtc = 0;
  1180. if (!mask) {
  1181. mask = nv_rd32(dev, 0x6109d4);
  1182. crtc = 1;
  1183. }
  1184. if (disp->modeset & 0x00000001)
  1185. nvd0_display_unk1_handler(dev, crtc, mask);
  1186. if (disp->modeset & 0x00000002)
  1187. nvd0_display_unk2_handler(dev, crtc, mask);
  1188. if (disp->modeset & 0x00000004)
  1189. nvd0_display_unk4_handler(dev, crtc, mask);
  1190. }
  1191. static void
  1192. nvd0_display_intr(struct drm_device *dev)
  1193. {
  1194. struct nvd0_display *disp = nvd0_display(dev);
  1195. u32 intr = nv_rd32(dev, 0x610088);
  1196. if (intr & 0x00000002) {
  1197. u32 stat = nv_rd32(dev, 0x61009c);
  1198. int chid = ffs(stat) - 1;
  1199. if (chid >= 0) {
  1200. u32 mthd = nv_rd32(dev, 0x6101f0 + (chid * 12));
  1201. u32 data = nv_rd32(dev, 0x6101f4 + (chid * 12));
  1202. u32 unkn = nv_rd32(dev, 0x6101f8 + (chid * 12));
  1203. NV_INFO(dev, "EvoCh: chid %d mthd 0x%04x data 0x%08x "
  1204. "0x%08x 0x%08x\n",
  1205. chid, (mthd & 0x0000ffc), data, mthd, unkn);
  1206. nv_wr32(dev, 0x61009c, (1 << chid));
  1207. nv_wr32(dev, 0x6101f0 + (chid * 12), 0x90000000);
  1208. }
  1209. intr &= ~0x00000002;
  1210. }
  1211. if (intr & 0x00100000) {
  1212. u32 stat = nv_rd32(dev, 0x6100ac);
  1213. if (stat & 0x00000007) {
  1214. disp->modeset = stat;
  1215. tasklet_schedule(&disp->tasklet);
  1216. nv_wr32(dev, 0x6100ac, (stat & 0x00000007));
  1217. stat &= ~0x00000007;
  1218. }
  1219. if (stat) {
  1220. NV_INFO(dev, "PDISP: unknown intr24 0x%08x\n", stat);
  1221. nv_wr32(dev, 0x6100ac, stat);
  1222. }
  1223. intr &= ~0x00100000;
  1224. }
  1225. if (intr & 0x01000000) {
  1226. u32 stat = nv_rd32(dev, 0x6100bc);
  1227. nv_wr32(dev, 0x6100bc, stat);
  1228. intr &= ~0x01000000;
  1229. }
  1230. if (intr & 0x02000000) {
  1231. u32 stat = nv_rd32(dev, 0x6108bc);
  1232. nv_wr32(dev, 0x6108bc, stat);
  1233. intr &= ~0x02000000;
  1234. }
  1235. if (intr)
  1236. NV_INFO(dev, "PDISP: unknown intr 0x%08x\n", intr);
  1237. }
  1238. /******************************************************************************
  1239. * Init
  1240. *****************************************************************************/
  1241. void
  1242. nvd0_display_fini(struct drm_device *dev)
  1243. {
  1244. int i;
  1245. /* fini cursors + syncs */
  1246. for (i = 1; i >= 0; i--) {
  1247. evo_fini_pio(dev, EVO_CURS(i));
  1248. evo_fini_dma(dev, EVO_SYNC(i));
  1249. }
  1250. /* fini master */
  1251. evo_fini_dma(dev, EVO_MASTER);
  1252. }
  1253. int
  1254. nvd0_display_init(struct drm_device *dev)
  1255. {
  1256. struct nvd0_display *disp = nvd0_display(dev);
  1257. int ret, i;
  1258. u32 *push;
  1259. if (nv_rd32(dev, 0x6100ac) & 0x00000100) {
  1260. nv_wr32(dev, 0x6100ac, 0x00000100);
  1261. nv_mask(dev, 0x6194e8, 0x00000001, 0x00000000);
  1262. if (!nv_wait(dev, 0x6194e8, 0x00000002, 0x00000000)) {
  1263. NV_ERROR(dev, "PDISP: 0x6194e8 0x%08x\n",
  1264. nv_rd32(dev, 0x6194e8));
  1265. return -EBUSY;
  1266. }
  1267. }
  1268. /* nfi what these are exactly, i do know that SOR_MODE_CTRL won't
  1269. * work at all unless you do the SOR part below.
  1270. */
  1271. for (i = 0; i < 3; i++) {
  1272. u32 dac = nv_rd32(dev, 0x61a000 + (i * 0x800));
  1273. nv_wr32(dev, 0x6101c0 + (i * 0x800), dac);
  1274. }
  1275. for (i = 0; i < 4; i++) {
  1276. u32 sor = nv_rd32(dev, 0x61c000 + (i * 0x800));
  1277. nv_wr32(dev, 0x6301c4 + (i * 0x800), sor);
  1278. }
  1279. for (i = 0; i < dev->mode_config.num_crtc; i++) {
  1280. u32 crtc0 = nv_rd32(dev, 0x616104 + (i * 0x800));
  1281. u32 crtc1 = nv_rd32(dev, 0x616108 + (i * 0x800));
  1282. u32 crtc2 = nv_rd32(dev, 0x61610c + (i * 0x800));
  1283. nv_wr32(dev, 0x6101b4 + (i * 0x800), crtc0);
  1284. nv_wr32(dev, 0x6101b8 + (i * 0x800), crtc1);
  1285. nv_wr32(dev, 0x6101bc + (i * 0x800), crtc2);
  1286. }
  1287. /* point at our hash table / objects, enable interrupts */
  1288. nv_wr32(dev, 0x610010, (disp->mem->vinst >> 8) | 9);
  1289. nv_mask(dev, 0x6100b0, 0x00000307, 0x00000307);
  1290. /* init master */
  1291. ret = evo_init_dma(dev, EVO_MASTER);
  1292. if (ret)
  1293. goto error;
  1294. /* init syncs + cursors */
  1295. for (i = 0; i < dev->mode_config.num_crtc; i++) {
  1296. if ((ret = evo_init_dma(dev, EVO_SYNC(i))) ||
  1297. (ret = evo_init_pio(dev, EVO_CURS(i))))
  1298. goto error;
  1299. }
  1300. push = evo_wait(dev, 0, 32);
  1301. if (!push) {
  1302. ret = -EBUSY;
  1303. goto error;
  1304. }
  1305. evo_mthd(push, 0x0088, 1);
  1306. evo_data(push, NvEvoSync);
  1307. evo_mthd(push, 0x0084, 1);
  1308. evo_data(push, 0x00000000);
  1309. evo_mthd(push, 0x0084, 1);
  1310. evo_data(push, 0x80000000);
  1311. evo_mthd(push, 0x008c, 1);
  1312. evo_data(push, 0x00000000);
  1313. evo_kick(push, dev, 0);
  1314. error:
  1315. if (ret)
  1316. nvd0_display_fini(dev);
  1317. return ret;
  1318. }
  1319. void
  1320. nvd0_display_destroy(struct drm_device *dev)
  1321. {
  1322. struct drm_nouveau_private *dev_priv = dev->dev_private;
  1323. struct nvd0_display *disp = nvd0_display(dev);
  1324. struct pci_dev *pdev = dev->pdev;
  1325. int i;
  1326. for (i = 0; i < 3; i++) {
  1327. pci_free_consistent(pdev, PAGE_SIZE, disp->evo[i].ptr,
  1328. disp->evo[i].handle);
  1329. }
  1330. nouveau_gpuobj_ref(NULL, &disp->mem);
  1331. nouveau_irq_unregister(dev, 26);
  1332. dev_priv->engine.display.priv = NULL;
  1333. kfree(disp);
  1334. }
  1335. int
  1336. nvd0_display_create(struct drm_device *dev)
  1337. {
  1338. struct drm_nouveau_private *dev_priv = dev->dev_private;
  1339. struct nouveau_instmem_engine *pinstmem = &dev_priv->engine.instmem;
  1340. struct dcb_table *dcb = &dev_priv->vbios.dcb;
  1341. struct drm_connector *connector, *tmp;
  1342. struct pci_dev *pdev = dev->pdev;
  1343. struct nvd0_display *disp;
  1344. struct dcb_entry *dcbe;
  1345. int ret, i;
  1346. disp = kzalloc(sizeof(*disp), GFP_KERNEL);
  1347. if (!disp)
  1348. return -ENOMEM;
  1349. dev_priv->engine.display.priv = disp;
  1350. /* create crtc objects to represent the hw heads */
  1351. for (i = 0; i < 2; i++) {
  1352. ret = nvd0_crtc_create(dev, i);
  1353. if (ret)
  1354. goto out;
  1355. }
  1356. /* create encoder/connector objects based on VBIOS DCB table */
  1357. for (i = 0, dcbe = &dcb->entry[0]; i < dcb->entries; i++, dcbe++) {
  1358. connector = nouveau_connector_create(dev, dcbe->connector);
  1359. if (IS_ERR(connector))
  1360. continue;
  1361. if (dcbe->location != DCB_LOC_ON_CHIP) {
  1362. NV_WARN(dev, "skipping off-chip encoder %d/%d\n",
  1363. dcbe->type, ffs(dcbe->or) - 1);
  1364. continue;
  1365. }
  1366. switch (dcbe->type) {
  1367. case OUTPUT_TMDS:
  1368. case OUTPUT_LVDS:
  1369. nvd0_sor_create(connector, dcbe);
  1370. break;
  1371. case OUTPUT_ANALOG:
  1372. nvd0_dac_create(connector, dcbe);
  1373. break;
  1374. default:
  1375. NV_WARN(dev, "skipping unsupported encoder %d/%d\n",
  1376. dcbe->type, ffs(dcbe->or) - 1);
  1377. continue;
  1378. }
  1379. }
  1380. /* cull any connectors we created that don't have an encoder */
  1381. list_for_each_entry_safe(connector, tmp, &dev->mode_config.connector_list, head) {
  1382. if (connector->encoder_ids[0])
  1383. continue;
  1384. NV_WARN(dev, "%s has no encoders, removing\n",
  1385. drm_get_connector_name(connector));
  1386. connector->funcs->destroy(connector);
  1387. }
  1388. /* setup interrupt handling */
  1389. tasklet_init(&disp->tasklet, nvd0_display_bh, (unsigned long)dev);
  1390. nouveau_irq_register(dev, 26, nvd0_display_intr);
  1391. /* hash table and dma objects for the memory areas we care about */
  1392. ret = nouveau_gpuobj_new(dev, NULL, 0x4000, 0x10000,
  1393. NVOBJ_FLAG_ZERO_ALLOC, &disp->mem);
  1394. if (ret)
  1395. goto out;
  1396. nv_wo32(disp->mem, 0x1000, 0x00000049);
  1397. nv_wo32(disp->mem, 0x1004, (disp->mem->vinst + 0x2000) >> 8);
  1398. nv_wo32(disp->mem, 0x1008, (disp->mem->vinst + 0x2fff) >> 8);
  1399. nv_wo32(disp->mem, 0x100c, 0x00000000);
  1400. nv_wo32(disp->mem, 0x1010, 0x00000000);
  1401. nv_wo32(disp->mem, 0x1014, 0x00000000);
  1402. nv_wo32(disp->mem, 0x0000, NvEvoSync);
  1403. nv_wo32(disp->mem, 0x0004, (0x1000 << 9) | 0x00000001);
  1404. nv_wo32(disp->mem, 0x1020, 0x00000049);
  1405. nv_wo32(disp->mem, 0x1024, 0x00000000);
  1406. nv_wo32(disp->mem, 0x1028, (dev_priv->vram_size - 1) >> 8);
  1407. nv_wo32(disp->mem, 0x102c, 0x00000000);
  1408. nv_wo32(disp->mem, 0x1030, 0x00000000);
  1409. nv_wo32(disp->mem, 0x1034, 0x00000000);
  1410. nv_wo32(disp->mem, 0x0008, NvEvoVRAM);
  1411. nv_wo32(disp->mem, 0x000c, (0x1020 << 9) | 0x00000001);
  1412. nv_wo32(disp->mem, 0x1040, 0x00000009);
  1413. nv_wo32(disp->mem, 0x1044, 0x00000000);
  1414. nv_wo32(disp->mem, 0x1048, (dev_priv->vram_size - 1) >> 8);
  1415. nv_wo32(disp->mem, 0x104c, 0x00000000);
  1416. nv_wo32(disp->mem, 0x1050, 0x00000000);
  1417. nv_wo32(disp->mem, 0x1054, 0x00000000);
  1418. nv_wo32(disp->mem, 0x0010, NvEvoVRAM_LP);
  1419. nv_wo32(disp->mem, 0x0014, (0x1040 << 9) | 0x00000001);
  1420. nv_wo32(disp->mem, 0x1060, 0x0fe00009);
  1421. nv_wo32(disp->mem, 0x1064, 0x00000000);
  1422. nv_wo32(disp->mem, 0x1068, (dev_priv->vram_size - 1) >> 8);
  1423. nv_wo32(disp->mem, 0x106c, 0x00000000);
  1424. nv_wo32(disp->mem, 0x1070, 0x00000000);
  1425. nv_wo32(disp->mem, 0x1074, 0x00000000);
  1426. nv_wo32(disp->mem, 0x0018, NvEvoFB32);
  1427. nv_wo32(disp->mem, 0x001c, (0x1060 << 9) | 0x00000001);
  1428. pinstmem->flush(dev);
  1429. /* push buffers for evo channels */
  1430. for (i = 0; i < 3; i++) {
  1431. disp->evo[i].ptr = pci_alloc_consistent(pdev, PAGE_SIZE,
  1432. &disp->evo[i].handle);
  1433. if (!disp->evo[i].ptr) {
  1434. ret = -ENOMEM;
  1435. goto out;
  1436. }
  1437. }
  1438. out:
  1439. if (ret)
  1440. nvd0_display_destroy(dev);
  1441. return ret;
  1442. }