nvd0_display.c 44 KB

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