nvd0_display.c 58 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141
  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 <drm/drmP.h>
  26. #include <drm/drm_crtc_helper.h>
  27. #include "nouveau_drm.h"
  28. #include "nouveau_dma.h"
  29. #include "nouveau_gem.h"
  30. #include "nouveau_connector.h"
  31. #include "nouveau_encoder.h"
  32. #include "nouveau_crtc.h"
  33. #include "nouveau_fence.h"
  34. #include "nv50_display.h"
  35. #include <core/gpuobj.h>
  36. #include <subdev/timer.h>
  37. #include <subdev/bar.h>
  38. #include <subdev/fb.h>
  39. #define EVO_DMA_NR 9
  40. #define EVO_MASTER (0x00)
  41. #define EVO_FLIP(c) (0x01 + (c))
  42. #define EVO_OVLY(c) (0x05 + (c))
  43. #define EVO_OIMM(c) (0x09 + (c))
  44. #define EVO_CURS(c) (0x0d + (c))
  45. /* offsets in shared sync bo of various structures */
  46. #define EVO_SYNC(c, o) ((c) * 0x0100 + (o))
  47. #define EVO_MAST_NTFY EVO_SYNC( 0, 0x00)
  48. #define EVO_FLIP_SEM0(c) EVO_SYNC((c), 0x00)
  49. #define EVO_FLIP_SEM1(c) EVO_SYNC((c), 0x10)
  50. struct evo {
  51. int idx;
  52. dma_addr_t handle;
  53. u32 *ptr;
  54. struct {
  55. u32 offset;
  56. u16 value;
  57. } sem;
  58. };
  59. struct nvd0_display {
  60. struct nouveau_gpuobj *mem;
  61. struct nouveau_bo *sync;
  62. struct evo evo[9];
  63. struct tasklet_struct tasklet;
  64. u32 modeset;
  65. };
  66. static struct nvd0_display *
  67. nvd0_display(struct drm_device *dev)
  68. {
  69. return nouveau_display(dev)->priv;
  70. }
  71. static struct drm_crtc *
  72. nvd0_display_crtc_get(struct drm_encoder *encoder)
  73. {
  74. return nouveau_encoder(encoder)->crtc;
  75. }
  76. /******************************************************************************
  77. * EVO channel helpers
  78. *****************************************************************************/
  79. static inline int
  80. evo_icmd(struct drm_device *dev, int id, u32 mthd, u32 data)
  81. {
  82. struct nouveau_device *device = nouveau_dev(dev);
  83. int ret = 0;
  84. nv_mask(device, 0x610700 + (id * 0x10), 0x00000001, 0x00000001);
  85. nv_wr32(device, 0x610704 + (id * 0x10), data);
  86. nv_mask(device, 0x610704 + (id * 0x10), 0x80000ffc, 0x80000000 | mthd);
  87. if (!nv_wait(device, 0x610704 + (id * 0x10), 0x80000000, 0x00000000))
  88. ret = -EBUSY;
  89. nv_mask(device, 0x610700 + (id * 0x10), 0x00000001, 0x00000000);
  90. return ret;
  91. }
  92. static u32 *
  93. evo_wait(struct drm_device *dev, int id, int nr)
  94. {
  95. struct nouveau_device *device = nouveau_dev(dev);
  96. struct nouveau_drm *drm = nouveau_drm(dev);
  97. struct nvd0_display *disp = nvd0_display(dev);
  98. u32 put = nv_rd32(device, 0x640000 + (id * 0x1000)) / 4;
  99. if (put + nr >= (PAGE_SIZE / 4)) {
  100. disp->evo[id].ptr[put] = 0x20000000;
  101. nv_wr32(device, 0x640000 + (id * 0x1000), 0x00000000);
  102. if (!nv_wait(device, 0x640004 + (id * 0x1000), ~0, 0x00000000)) {
  103. NV_ERROR(drm, "evo %d dma stalled\n", id);
  104. return NULL;
  105. }
  106. put = 0;
  107. }
  108. return disp->evo[id].ptr + put;
  109. }
  110. static void
  111. evo_kick(u32 *push, struct drm_device *dev, int id)
  112. {
  113. struct nouveau_device *device = nouveau_dev(dev);
  114. struct nvd0_display *disp = nvd0_display(dev);
  115. nv_wr32(device, 0x640000 + (id * 0x1000), (push - disp->evo[id].ptr) << 2);
  116. }
  117. #define evo_mthd(p,m,s) *((p)++) = (((s) << 18) | (m))
  118. #define evo_data(p,d) *((p)++) = (d)
  119. static int
  120. evo_init_dma(struct drm_device *dev, int ch)
  121. {
  122. struct nouveau_device *device = nouveau_dev(dev);
  123. struct nouveau_drm *drm = nouveau_drm(dev);
  124. struct nvd0_display *disp = nvd0_display(dev);
  125. u32 flags;
  126. flags = 0x00000000;
  127. if (ch == EVO_MASTER)
  128. flags |= 0x01000000;
  129. nv_wr32(device, 0x610494 + (ch * 0x0010), (disp->evo[ch].handle >> 8) | 3);
  130. nv_wr32(device, 0x610498 + (ch * 0x0010), 0x00010000);
  131. nv_wr32(device, 0x61049c + (ch * 0x0010), 0x00000001);
  132. nv_mask(device, 0x610490 + (ch * 0x0010), 0x00000010, 0x00000010);
  133. nv_wr32(device, 0x640000 + (ch * 0x1000), 0x00000000);
  134. nv_wr32(device, 0x610490 + (ch * 0x0010), 0x00000013 | flags);
  135. if (!nv_wait(device, 0x610490 + (ch * 0x0010), 0x80000000, 0x00000000)) {
  136. NV_ERROR(drm, "PDISP: ch%d 0x%08x\n", ch,
  137. nv_rd32(device, 0x610490 + (ch * 0x0010)));
  138. return -EBUSY;
  139. }
  140. nv_mask(device, 0x610090, (1 << ch), (1 << ch));
  141. nv_mask(device, 0x6100a0, (1 << ch), (1 << ch));
  142. return 0;
  143. }
  144. static void
  145. evo_fini_dma(struct drm_device *dev, int ch)
  146. {
  147. struct nouveau_device *device = nouveau_dev(dev);
  148. if (!(nv_rd32(device, 0x610490 + (ch * 0x0010)) & 0x00000010))
  149. return;
  150. nv_mask(device, 0x610490 + (ch * 0x0010), 0x00000010, 0x00000000);
  151. nv_mask(device, 0x610490 + (ch * 0x0010), 0x00000003, 0x00000000);
  152. nv_wait(device, 0x610490 + (ch * 0x0010), 0x80000000, 0x00000000);
  153. nv_mask(device, 0x610090, (1 << ch), 0x00000000);
  154. nv_mask(device, 0x6100a0, (1 << ch), 0x00000000);
  155. }
  156. static inline void
  157. evo_piow(struct drm_device *dev, int ch, u16 mthd, u32 data)
  158. {
  159. struct nouveau_device *device = nouveau_dev(dev);
  160. nv_wr32(device, 0x640000 + (ch * 0x1000) + mthd, data);
  161. }
  162. static int
  163. evo_init_pio(struct drm_device *dev, int ch)
  164. {
  165. struct nouveau_device *device = nouveau_dev(dev);
  166. struct nouveau_drm *drm = nouveau_drm(dev);
  167. nv_wr32(device, 0x610490 + (ch * 0x0010), 0x00000001);
  168. if (!nv_wait(device, 0x610490 + (ch * 0x0010), 0x00010000, 0x00010000)) {
  169. NV_ERROR(drm, "PDISP: ch%d 0x%08x\n", ch,
  170. nv_rd32(device, 0x610490 + (ch * 0x0010)));
  171. return -EBUSY;
  172. }
  173. nv_mask(device, 0x610090, (1 << ch), (1 << ch));
  174. nv_mask(device, 0x6100a0, (1 << ch), (1 << ch));
  175. return 0;
  176. }
  177. static void
  178. evo_fini_pio(struct drm_device *dev, int ch)
  179. {
  180. struct nouveau_device *device = nouveau_dev(dev);
  181. if (!(nv_rd32(device, 0x610490 + (ch * 0x0010)) & 0x00000001))
  182. return;
  183. nv_mask(device, 0x610490 + (ch * 0x0010), 0x00000010, 0x00000010);
  184. nv_mask(device, 0x610490 + (ch * 0x0010), 0x00000001, 0x00000000);
  185. nv_wait(device, 0x610490 + (ch * 0x0010), 0x00010000, 0x00000000);
  186. nv_mask(device, 0x610090, (1 << ch), 0x00000000);
  187. nv_mask(device, 0x6100a0, (1 << ch), 0x00000000);
  188. }
  189. static bool
  190. evo_sync_wait(void *data)
  191. {
  192. return nouveau_bo_rd32(data, EVO_MAST_NTFY) != 0x00000000;
  193. }
  194. static int
  195. evo_sync(struct drm_device *dev, int ch)
  196. {
  197. struct nouveau_device *device = nouveau_dev(dev);
  198. struct nvd0_display *disp = nvd0_display(dev);
  199. u32 *push = evo_wait(dev, ch, 8);
  200. if (push) {
  201. nouveau_bo_wr32(disp->sync, EVO_MAST_NTFY, 0x00000000);
  202. evo_mthd(push, 0x0084, 1);
  203. evo_data(push, 0x80000000 | EVO_MAST_NTFY);
  204. evo_mthd(push, 0x0080, 2);
  205. evo_data(push, 0x00000000);
  206. evo_data(push, 0x00000000);
  207. evo_kick(push, dev, ch);
  208. if (nv_wait_cb(device, evo_sync_wait, disp->sync))
  209. return 0;
  210. }
  211. return -EBUSY;
  212. }
  213. /******************************************************************************
  214. * Page flipping channel
  215. *****************************************************************************/
  216. struct nouveau_bo *
  217. nvd0_display_crtc_sema(struct drm_device *dev, int crtc)
  218. {
  219. return nvd0_display(dev)->sync;
  220. }
  221. void
  222. nvd0_display_flip_stop(struct drm_crtc *crtc)
  223. {
  224. struct nvd0_display *disp = nvd0_display(crtc->dev);
  225. struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc);
  226. struct evo *evo = &disp->evo[EVO_FLIP(nv_crtc->index)];
  227. u32 *push;
  228. push = evo_wait(crtc->dev, evo->idx, 8);
  229. if (push) {
  230. evo_mthd(push, 0x0084, 1);
  231. evo_data(push, 0x00000000);
  232. evo_mthd(push, 0x0094, 1);
  233. evo_data(push, 0x00000000);
  234. evo_mthd(push, 0x00c0, 1);
  235. evo_data(push, 0x00000000);
  236. evo_mthd(push, 0x0080, 1);
  237. evo_data(push, 0x00000000);
  238. evo_kick(push, crtc->dev, evo->idx);
  239. }
  240. }
  241. int
  242. nvd0_display_flip_next(struct drm_crtc *crtc, struct drm_framebuffer *fb,
  243. struct nouveau_channel *chan, u32 swap_interval)
  244. {
  245. struct nouveau_framebuffer *nv_fb = nouveau_framebuffer(fb);
  246. struct nvd0_display *disp = nvd0_display(crtc->dev);
  247. struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc);
  248. struct evo *evo = &disp->evo[EVO_FLIP(nv_crtc->index)];
  249. u64 offset;
  250. u32 *push;
  251. int ret;
  252. swap_interval <<= 4;
  253. if (swap_interval == 0)
  254. swap_interval |= 0x100;
  255. push = evo_wait(crtc->dev, evo->idx, 128);
  256. if (unlikely(push == NULL))
  257. return -EBUSY;
  258. /* synchronise with the rendering channel, if necessary */
  259. if (likely(chan)) {
  260. ret = RING_SPACE(chan, 10);
  261. if (ret)
  262. return ret;
  263. offset = nvc0_fence_crtc(chan, nv_crtc->index);
  264. offset += evo->sem.offset;
  265. BEGIN_NVC0(chan, 0, NV84_SUBCHAN_SEMAPHORE_ADDRESS_HIGH, 4);
  266. OUT_RING (chan, upper_32_bits(offset));
  267. OUT_RING (chan, lower_32_bits(offset));
  268. OUT_RING (chan, 0xf00d0000 | evo->sem.value);
  269. OUT_RING (chan, 0x1002);
  270. BEGIN_NVC0(chan, 0, NV84_SUBCHAN_SEMAPHORE_ADDRESS_HIGH, 4);
  271. OUT_RING (chan, upper_32_bits(offset));
  272. OUT_RING (chan, lower_32_bits(offset ^ 0x10));
  273. OUT_RING (chan, 0x74b1e000);
  274. OUT_RING (chan, 0x1001);
  275. FIRE_RING (chan);
  276. } else {
  277. nouveau_bo_wr32(disp->sync, evo->sem.offset / 4,
  278. 0xf00d0000 | evo->sem.value);
  279. evo_sync(crtc->dev, EVO_MASTER);
  280. }
  281. /* queue the flip */
  282. evo_mthd(push, 0x0100, 1);
  283. evo_data(push, 0xfffe0000);
  284. evo_mthd(push, 0x0084, 1);
  285. evo_data(push, swap_interval);
  286. if (!(swap_interval & 0x00000100)) {
  287. evo_mthd(push, 0x00e0, 1);
  288. evo_data(push, 0x40000000);
  289. }
  290. evo_mthd(push, 0x0088, 4);
  291. evo_data(push, evo->sem.offset);
  292. evo_data(push, 0xf00d0000 | evo->sem.value);
  293. evo_data(push, 0x74b1e000);
  294. evo_data(push, NvEvoSync);
  295. evo_mthd(push, 0x00a0, 2);
  296. evo_data(push, 0x00000000);
  297. evo_data(push, 0x00000000);
  298. evo_mthd(push, 0x00c0, 1);
  299. evo_data(push, nv_fb->r_dma);
  300. evo_mthd(push, 0x0110, 2);
  301. evo_data(push, 0x00000000);
  302. evo_data(push, 0x00000000);
  303. evo_mthd(push, 0x0400, 5);
  304. evo_data(push, nv_fb->nvbo->bo.offset >> 8);
  305. evo_data(push, 0);
  306. evo_data(push, (fb->height << 16) | fb->width);
  307. evo_data(push, nv_fb->r_pitch);
  308. evo_data(push, nv_fb->r_format);
  309. evo_mthd(push, 0x0080, 1);
  310. evo_data(push, 0x00000000);
  311. evo_kick(push, crtc->dev, evo->idx);
  312. evo->sem.offset ^= 0x10;
  313. evo->sem.value++;
  314. return 0;
  315. }
  316. /******************************************************************************
  317. * CRTC
  318. *****************************************************************************/
  319. static int
  320. nvd0_crtc_set_dither(struct nouveau_crtc *nv_crtc, bool update)
  321. {
  322. struct nouveau_drm *drm = nouveau_drm(nv_crtc->base.dev);
  323. struct drm_device *dev = nv_crtc->base.dev;
  324. struct nouveau_connector *nv_connector;
  325. struct drm_connector *connector;
  326. u32 *push, mode = 0x00;
  327. u32 mthd;
  328. nv_connector = nouveau_crtc_connector_get(nv_crtc);
  329. connector = &nv_connector->base;
  330. if (nv_connector->dithering_mode == DITHERING_MODE_AUTO) {
  331. if (nv_crtc->base.fb->depth > connector->display_info.bpc * 3)
  332. mode = DITHERING_MODE_DYNAMIC2X2;
  333. } else {
  334. mode = nv_connector->dithering_mode;
  335. }
  336. if (nv_connector->dithering_depth == DITHERING_DEPTH_AUTO) {
  337. if (connector->display_info.bpc >= 8)
  338. mode |= DITHERING_DEPTH_8BPC;
  339. } else {
  340. mode |= nv_connector->dithering_depth;
  341. }
  342. if (nv_device(drm->device)->card_type < NV_E0)
  343. mthd = 0x0490 + (nv_crtc->index * 0x0300);
  344. else
  345. mthd = 0x04a0 + (nv_crtc->index * 0x0300);
  346. push = evo_wait(dev, EVO_MASTER, 4);
  347. if (push) {
  348. evo_mthd(push, mthd, 1);
  349. evo_data(push, mode);
  350. if (update) {
  351. evo_mthd(push, 0x0080, 1);
  352. evo_data(push, 0x00000000);
  353. }
  354. evo_kick(push, dev, EVO_MASTER);
  355. }
  356. return 0;
  357. }
  358. static int
  359. nvd0_crtc_set_scale(struct nouveau_crtc *nv_crtc, bool update)
  360. {
  361. struct drm_display_mode *omode, *umode = &nv_crtc->base.mode;
  362. struct drm_device *dev = nv_crtc->base.dev;
  363. struct drm_crtc *crtc = &nv_crtc->base;
  364. struct nouveau_connector *nv_connector;
  365. int mode = DRM_MODE_SCALE_NONE;
  366. u32 oX, oY, *push;
  367. /* start off at the resolution we programmed the crtc for, this
  368. * effectively handles NONE/FULL scaling
  369. */
  370. nv_connector = nouveau_crtc_connector_get(nv_crtc);
  371. if (nv_connector && nv_connector->native_mode)
  372. mode = nv_connector->scaling_mode;
  373. if (mode != DRM_MODE_SCALE_NONE)
  374. omode = nv_connector->native_mode;
  375. else
  376. omode = umode;
  377. oX = omode->hdisplay;
  378. oY = omode->vdisplay;
  379. if (omode->flags & DRM_MODE_FLAG_DBLSCAN)
  380. oY *= 2;
  381. /* add overscan compensation if necessary, will keep the aspect
  382. * ratio the same as the backend mode unless overridden by the
  383. * user setting both hborder and vborder properties.
  384. */
  385. if (nv_connector && ( nv_connector->underscan == UNDERSCAN_ON ||
  386. (nv_connector->underscan == UNDERSCAN_AUTO &&
  387. nv_connector->edid &&
  388. drm_detect_hdmi_monitor(nv_connector->edid)))) {
  389. u32 bX = nv_connector->underscan_hborder;
  390. u32 bY = nv_connector->underscan_vborder;
  391. u32 aspect = (oY << 19) / oX;
  392. if (bX) {
  393. oX -= (bX * 2);
  394. if (bY) oY -= (bY * 2);
  395. else oY = ((oX * aspect) + (aspect / 2)) >> 19;
  396. } else {
  397. oX -= (oX >> 4) + 32;
  398. if (bY) oY -= (bY * 2);
  399. else oY = ((oX * aspect) + (aspect / 2)) >> 19;
  400. }
  401. }
  402. /* handle CENTER/ASPECT scaling, taking into account the areas
  403. * removed already for overscan compensation
  404. */
  405. switch (mode) {
  406. case DRM_MODE_SCALE_CENTER:
  407. oX = min((u32)umode->hdisplay, oX);
  408. oY = min((u32)umode->vdisplay, oY);
  409. /* fall-through */
  410. case DRM_MODE_SCALE_ASPECT:
  411. if (oY < oX) {
  412. u32 aspect = (umode->hdisplay << 19) / umode->vdisplay;
  413. oX = ((oY * aspect) + (aspect / 2)) >> 19;
  414. } else {
  415. u32 aspect = (umode->vdisplay << 19) / umode->hdisplay;
  416. oY = ((oX * aspect) + (aspect / 2)) >> 19;
  417. }
  418. break;
  419. default:
  420. break;
  421. }
  422. push = evo_wait(dev, EVO_MASTER, 8);
  423. if (push) {
  424. evo_mthd(push, 0x04c0 + (nv_crtc->index * 0x300), 3);
  425. evo_data(push, (oY << 16) | oX);
  426. evo_data(push, (oY << 16) | oX);
  427. evo_data(push, (oY << 16) | oX);
  428. evo_mthd(push, 0x0494 + (nv_crtc->index * 0x300), 1);
  429. evo_data(push, 0x00000000);
  430. evo_mthd(push, 0x04b8 + (nv_crtc->index * 0x300), 1);
  431. evo_data(push, (umode->vdisplay << 16) | umode->hdisplay);
  432. evo_kick(push, dev, EVO_MASTER);
  433. if (update) {
  434. nvd0_display_flip_stop(crtc);
  435. nvd0_display_flip_next(crtc, crtc->fb, NULL, 1);
  436. }
  437. }
  438. return 0;
  439. }
  440. static int
  441. nvd0_crtc_set_image(struct nouveau_crtc *nv_crtc, struct drm_framebuffer *fb,
  442. int x, int y, bool update)
  443. {
  444. struct nouveau_framebuffer *nvfb = nouveau_framebuffer(fb);
  445. u32 *push;
  446. push = evo_wait(fb->dev, EVO_MASTER, 16);
  447. if (push) {
  448. evo_mthd(push, 0x0460 + (nv_crtc->index * 0x300), 1);
  449. evo_data(push, nvfb->nvbo->bo.offset >> 8);
  450. evo_mthd(push, 0x0468 + (nv_crtc->index * 0x300), 4);
  451. evo_data(push, (fb->height << 16) | fb->width);
  452. evo_data(push, nvfb->r_pitch);
  453. evo_data(push, nvfb->r_format);
  454. evo_data(push, nvfb->r_dma);
  455. evo_mthd(push, 0x04b0 + (nv_crtc->index * 0x300), 1);
  456. evo_data(push, (y << 16) | x);
  457. if (update) {
  458. evo_mthd(push, 0x0080, 1);
  459. evo_data(push, 0x00000000);
  460. }
  461. evo_kick(push, fb->dev, EVO_MASTER);
  462. }
  463. nv_crtc->fb.tile_flags = nvfb->r_dma;
  464. return 0;
  465. }
  466. static void
  467. nvd0_crtc_cursor_show(struct nouveau_crtc *nv_crtc, bool show, bool update)
  468. {
  469. struct drm_device *dev = nv_crtc->base.dev;
  470. u32 *push = evo_wait(dev, EVO_MASTER, 16);
  471. if (push) {
  472. if (show) {
  473. evo_mthd(push, 0x0480 + (nv_crtc->index * 0x300), 2);
  474. evo_data(push, 0x85000000);
  475. evo_data(push, nv_crtc->cursor.nvbo->bo.offset >> 8);
  476. evo_mthd(push, 0x048c + (nv_crtc->index * 0x300), 1);
  477. evo_data(push, NvEvoVRAM);
  478. } else {
  479. evo_mthd(push, 0x0480 + (nv_crtc->index * 0x300), 1);
  480. evo_data(push, 0x05000000);
  481. evo_mthd(push, 0x048c + (nv_crtc->index * 0x300), 1);
  482. evo_data(push, 0x00000000);
  483. }
  484. if (update) {
  485. evo_mthd(push, 0x0080, 1);
  486. evo_data(push, 0x00000000);
  487. }
  488. evo_kick(push, dev, EVO_MASTER);
  489. }
  490. }
  491. static void
  492. nvd0_crtc_dpms(struct drm_crtc *crtc, int mode)
  493. {
  494. }
  495. static void
  496. nvd0_crtc_prepare(struct drm_crtc *crtc)
  497. {
  498. struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc);
  499. u32 *push;
  500. nvd0_display_flip_stop(crtc);
  501. push = evo_wait(crtc->dev, EVO_MASTER, 2);
  502. if (push) {
  503. evo_mthd(push, 0x0474 + (nv_crtc->index * 0x300), 1);
  504. evo_data(push, 0x00000000);
  505. evo_mthd(push, 0x0440 + (nv_crtc->index * 0x300), 1);
  506. evo_data(push, 0x03000000);
  507. evo_mthd(push, 0x045c + (nv_crtc->index * 0x300), 1);
  508. evo_data(push, 0x00000000);
  509. evo_kick(push, crtc->dev, EVO_MASTER);
  510. }
  511. nvd0_crtc_cursor_show(nv_crtc, false, false);
  512. }
  513. static void
  514. nvd0_crtc_commit(struct drm_crtc *crtc)
  515. {
  516. struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc);
  517. u32 *push;
  518. push = evo_wait(crtc->dev, EVO_MASTER, 32);
  519. if (push) {
  520. evo_mthd(push, 0x0474 + (nv_crtc->index * 0x300), 1);
  521. evo_data(push, nv_crtc->fb.tile_flags);
  522. evo_mthd(push, 0x0440 + (nv_crtc->index * 0x300), 4);
  523. evo_data(push, 0x83000000);
  524. evo_data(push, nv_crtc->lut.nvbo->bo.offset >> 8);
  525. evo_data(push, 0x00000000);
  526. evo_data(push, 0x00000000);
  527. evo_mthd(push, 0x045c + (nv_crtc->index * 0x300), 1);
  528. evo_data(push, NvEvoVRAM);
  529. evo_mthd(push, 0x0430 + (nv_crtc->index * 0x300), 1);
  530. evo_data(push, 0xffffff00);
  531. evo_kick(push, crtc->dev, EVO_MASTER);
  532. }
  533. nvd0_crtc_cursor_show(nv_crtc, nv_crtc->cursor.visible, true);
  534. nvd0_display_flip_next(crtc, crtc->fb, NULL, 1);
  535. }
  536. static bool
  537. nvd0_crtc_mode_fixup(struct drm_crtc *crtc, const struct drm_display_mode *mode,
  538. struct drm_display_mode *adjusted_mode)
  539. {
  540. return true;
  541. }
  542. static int
  543. nvd0_crtc_swap_fbs(struct drm_crtc *crtc, struct drm_framebuffer *old_fb)
  544. {
  545. struct nouveau_framebuffer *nvfb = nouveau_framebuffer(crtc->fb);
  546. int ret;
  547. ret = nouveau_bo_pin(nvfb->nvbo, TTM_PL_FLAG_VRAM);
  548. if (ret)
  549. return ret;
  550. if (old_fb) {
  551. nvfb = nouveau_framebuffer(old_fb);
  552. nouveau_bo_unpin(nvfb->nvbo);
  553. }
  554. return 0;
  555. }
  556. static int
  557. nvd0_crtc_mode_set(struct drm_crtc *crtc, struct drm_display_mode *umode,
  558. struct drm_display_mode *mode, int x, int y,
  559. struct drm_framebuffer *old_fb)
  560. {
  561. struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc);
  562. struct nouveau_connector *nv_connector;
  563. u32 ilace = (mode->flags & DRM_MODE_FLAG_INTERLACE) ? 2 : 1;
  564. u32 vscan = (mode->flags & DRM_MODE_FLAG_DBLSCAN) ? 2 : 1;
  565. u32 hactive, hsynce, hbackp, hfrontp, hblanke, hblanks;
  566. u32 vactive, vsynce, vbackp, vfrontp, vblanke, vblanks;
  567. u32 vblan2e = 0, vblan2s = 1;
  568. u32 *push;
  569. int ret;
  570. hactive = mode->htotal;
  571. hsynce = mode->hsync_end - mode->hsync_start - 1;
  572. hbackp = mode->htotal - mode->hsync_end;
  573. hblanke = hsynce + hbackp;
  574. hfrontp = mode->hsync_start - mode->hdisplay;
  575. hblanks = mode->htotal - hfrontp - 1;
  576. vactive = mode->vtotal * vscan / ilace;
  577. vsynce = ((mode->vsync_end - mode->vsync_start) * vscan / ilace) - 1;
  578. vbackp = (mode->vtotal - mode->vsync_end) * vscan / ilace;
  579. vblanke = vsynce + vbackp;
  580. vfrontp = (mode->vsync_start - mode->vdisplay) * vscan / ilace;
  581. vblanks = vactive - vfrontp - 1;
  582. if (mode->flags & DRM_MODE_FLAG_INTERLACE) {
  583. vblan2e = vactive + vsynce + vbackp;
  584. vblan2s = vblan2e + (mode->vdisplay * vscan / ilace);
  585. vactive = (vactive * 2) + 1;
  586. }
  587. ret = nvd0_crtc_swap_fbs(crtc, old_fb);
  588. if (ret)
  589. return ret;
  590. push = evo_wait(crtc->dev, EVO_MASTER, 64);
  591. if (push) {
  592. evo_mthd(push, 0x0410 + (nv_crtc->index * 0x300), 6);
  593. evo_data(push, 0x00000000);
  594. evo_data(push, (vactive << 16) | hactive);
  595. evo_data(push, ( vsynce << 16) | hsynce);
  596. evo_data(push, (vblanke << 16) | hblanke);
  597. evo_data(push, (vblanks << 16) | hblanks);
  598. evo_data(push, (vblan2e << 16) | vblan2s);
  599. evo_mthd(push, 0x042c + (nv_crtc->index * 0x300), 1);
  600. evo_data(push, 0x00000000); /* ??? */
  601. evo_mthd(push, 0x0450 + (nv_crtc->index * 0x300), 3);
  602. evo_data(push, mode->clock * 1000);
  603. evo_data(push, 0x00200000); /* ??? */
  604. evo_data(push, mode->clock * 1000);
  605. evo_mthd(push, 0x04d0 + (nv_crtc->index * 0x300), 2);
  606. evo_data(push, 0x00000311);
  607. evo_data(push, 0x00000100);
  608. evo_kick(push, crtc->dev, EVO_MASTER);
  609. }
  610. nv_connector = nouveau_crtc_connector_get(nv_crtc);
  611. nvd0_crtc_set_dither(nv_crtc, false);
  612. nvd0_crtc_set_scale(nv_crtc, false);
  613. nvd0_crtc_set_image(nv_crtc, crtc->fb, x, y, false);
  614. return 0;
  615. }
  616. static int
  617. nvd0_crtc_mode_set_base(struct drm_crtc *crtc, int x, int y,
  618. struct drm_framebuffer *old_fb)
  619. {
  620. struct nouveau_drm *drm = nouveau_drm(crtc->dev);
  621. struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc);
  622. int ret;
  623. if (!crtc->fb) {
  624. NV_DEBUG(drm, "No FB bound\n");
  625. return 0;
  626. }
  627. ret = nvd0_crtc_swap_fbs(crtc, old_fb);
  628. if (ret)
  629. return ret;
  630. nvd0_display_flip_stop(crtc);
  631. nvd0_crtc_set_image(nv_crtc, crtc->fb, x, y, true);
  632. nvd0_display_flip_next(crtc, crtc->fb, NULL, 1);
  633. return 0;
  634. }
  635. static int
  636. nvd0_crtc_mode_set_base_atomic(struct drm_crtc *crtc,
  637. struct drm_framebuffer *fb, int x, int y,
  638. enum mode_set_atomic state)
  639. {
  640. struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc);
  641. nvd0_display_flip_stop(crtc);
  642. nvd0_crtc_set_image(nv_crtc, fb, x, y, true);
  643. return 0;
  644. }
  645. static void
  646. nvd0_crtc_lut_load(struct drm_crtc *crtc)
  647. {
  648. struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc);
  649. void __iomem *lut = nvbo_kmap_obj_iovirtual(nv_crtc->lut.nvbo);
  650. int i;
  651. for (i = 0; i < 256; i++) {
  652. writew(0x6000 + (nv_crtc->lut.r[i] >> 2), lut + (i * 0x20) + 0);
  653. writew(0x6000 + (nv_crtc->lut.g[i] >> 2), lut + (i * 0x20) + 2);
  654. writew(0x6000 + (nv_crtc->lut.b[i] >> 2), lut + (i * 0x20) + 4);
  655. }
  656. }
  657. static int
  658. nvd0_crtc_cursor_set(struct drm_crtc *crtc, struct drm_file *file_priv,
  659. uint32_t handle, uint32_t width, uint32_t height)
  660. {
  661. struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc);
  662. struct drm_device *dev = crtc->dev;
  663. struct drm_gem_object *gem;
  664. struct nouveau_bo *nvbo;
  665. bool visible = (handle != 0);
  666. int i, ret = 0;
  667. if (visible) {
  668. if (width != 64 || height != 64)
  669. return -EINVAL;
  670. gem = drm_gem_object_lookup(dev, file_priv, handle);
  671. if (unlikely(!gem))
  672. return -ENOENT;
  673. nvbo = nouveau_gem_object(gem);
  674. ret = nouveau_bo_map(nvbo);
  675. if (ret == 0) {
  676. for (i = 0; i < 64 * 64; i++) {
  677. u32 v = nouveau_bo_rd32(nvbo, i);
  678. nouveau_bo_wr32(nv_crtc->cursor.nvbo, i, v);
  679. }
  680. nouveau_bo_unmap(nvbo);
  681. }
  682. drm_gem_object_unreference_unlocked(gem);
  683. }
  684. if (visible != nv_crtc->cursor.visible) {
  685. nvd0_crtc_cursor_show(nv_crtc, visible, true);
  686. nv_crtc->cursor.visible = visible;
  687. }
  688. return ret;
  689. }
  690. static int
  691. nvd0_crtc_cursor_move(struct drm_crtc *crtc, int x, int y)
  692. {
  693. struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc);
  694. int ch = EVO_CURS(nv_crtc->index);
  695. evo_piow(crtc->dev, ch, 0x0084, (y << 16) | (x & 0xffff));
  696. evo_piow(crtc->dev, ch, 0x0080, 0x00000000);
  697. return 0;
  698. }
  699. static void
  700. nvd0_crtc_gamma_set(struct drm_crtc *crtc, u16 *r, u16 *g, u16 *b,
  701. uint32_t start, uint32_t size)
  702. {
  703. struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc);
  704. u32 end = max(start + size, (u32)256);
  705. u32 i;
  706. for (i = start; i < end; i++) {
  707. nv_crtc->lut.r[i] = r[i];
  708. nv_crtc->lut.g[i] = g[i];
  709. nv_crtc->lut.b[i] = b[i];
  710. }
  711. nvd0_crtc_lut_load(crtc);
  712. }
  713. static void
  714. nvd0_crtc_destroy(struct drm_crtc *crtc)
  715. {
  716. struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc);
  717. nouveau_bo_unmap(nv_crtc->cursor.nvbo);
  718. nouveau_bo_ref(NULL, &nv_crtc->cursor.nvbo);
  719. nouveau_bo_unmap(nv_crtc->lut.nvbo);
  720. nouveau_bo_ref(NULL, &nv_crtc->lut.nvbo);
  721. drm_crtc_cleanup(crtc);
  722. kfree(crtc);
  723. }
  724. static const struct drm_crtc_helper_funcs nvd0_crtc_hfunc = {
  725. .dpms = nvd0_crtc_dpms,
  726. .prepare = nvd0_crtc_prepare,
  727. .commit = nvd0_crtc_commit,
  728. .mode_fixup = nvd0_crtc_mode_fixup,
  729. .mode_set = nvd0_crtc_mode_set,
  730. .mode_set_base = nvd0_crtc_mode_set_base,
  731. .mode_set_base_atomic = nvd0_crtc_mode_set_base_atomic,
  732. .load_lut = nvd0_crtc_lut_load,
  733. };
  734. static const struct drm_crtc_funcs nvd0_crtc_func = {
  735. .cursor_set = nvd0_crtc_cursor_set,
  736. .cursor_move = nvd0_crtc_cursor_move,
  737. .gamma_set = nvd0_crtc_gamma_set,
  738. .set_config = drm_crtc_helper_set_config,
  739. .destroy = nvd0_crtc_destroy,
  740. .page_flip = nouveau_crtc_page_flip,
  741. };
  742. static void
  743. nvd0_cursor_set_pos(struct nouveau_crtc *nv_crtc, int x, int y)
  744. {
  745. }
  746. static void
  747. nvd0_cursor_set_offset(struct nouveau_crtc *nv_crtc, uint32_t offset)
  748. {
  749. }
  750. static int
  751. nvd0_crtc_create(struct drm_device *dev, int index)
  752. {
  753. struct nouveau_crtc *nv_crtc;
  754. struct drm_crtc *crtc;
  755. int ret, i;
  756. nv_crtc = kzalloc(sizeof(*nv_crtc), GFP_KERNEL);
  757. if (!nv_crtc)
  758. return -ENOMEM;
  759. nv_crtc->index = index;
  760. nv_crtc->set_dither = nvd0_crtc_set_dither;
  761. nv_crtc->set_scale = nvd0_crtc_set_scale;
  762. nv_crtc->cursor.set_offset = nvd0_cursor_set_offset;
  763. nv_crtc->cursor.set_pos = nvd0_cursor_set_pos;
  764. for (i = 0; i < 256; i++) {
  765. nv_crtc->lut.r[i] = i << 8;
  766. nv_crtc->lut.g[i] = i << 8;
  767. nv_crtc->lut.b[i] = i << 8;
  768. }
  769. crtc = &nv_crtc->base;
  770. drm_crtc_init(dev, crtc, &nvd0_crtc_func);
  771. drm_crtc_helper_add(crtc, &nvd0_crtc_hfunc);
  772. drm_mode_crtc_set_gamma_size(crtc, 256);
  773. ret = nouveau_bo_new(dev, 64 * 64 * 4, 0x100, TTM_PL_FLAG_VRAM,
  774. 0, 0x0000, NULL, &nv_crtc->cursor.nvbo);
  775. if (!ret) {
  776. ret = nouveau_bo_pin(nv_crtc->cursor.nvbo, TTM_PL_FLAG_VRAM);
  777. if (!ret)
  778. ret = nouveau_bo_map(nv_crtc->cursor.nvbo);
  779. if (ret)
  780. nouveau_bo_ref(NULL, &nv_crtc->cursor.nvbo);
  781. }
  782. if (ret)
  783. goto out;
  784. ret = nouveau_bo_new(dev, 8192, 0x100, TTM_PL_FLAG_VRAM,
  785. 0, 0x0000, NULL, &nv_crtc->lut.nvbo);
  786. if (!ret) {
  787. ret = nouveau_bo_pin(nv_crtc->lut.nvbo, TTM_PL_FLAG_VRAM);
  788. if (!ret)
  789. ret = nouveau_bo_map(nv_crtc->lut.nvbo);
  790. if (ret)
  791. nouveau_bo_ref(NULL, &nv_crtc->lut.nvbo);
  792. }
  793. if (ret)
  794. goto out;
  795. nvd0_crtc_lut_load(crtc);
  796. out:
  797. if (ret)
  798. nvd0_crtc_destroy(crtc);
  799. return ret;
  800. }
  801. /******************************************************************************
  802. * DAC
  803. *****************************************************************************/
  804. static void
  805. nvd0_dac_dpms(struct drm_encoder *encoder, int mode)
  806. {
  807. struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
  808. struct drm_device *dev = encoder->dev;
  809. struct nouveau_device *device = nouveau_dev(dev);
  810. int or = nv_encoder->or;
  811. u32 dpms_ctrl;
  812. dpms_ctrl = 0x80000000;
  813. if (mode == DRM_MODE_DPMS_STANDBY || mode == DRM_MODE_DPMS_OFF)
  814. dpms_ctrl |= 0x00000001;
  815. if (mode == DRM_MODE_DPMS_SUSPEND || mode == DRM_MODE_DPMS_OFF)
  816. dpms_ctrl |= 0x00000004;
  817. nv_wait(device, 0x61a004 + (or * 0x0800), 0x80000000, 0x00000000);
  818. nv_mask(device, 0x61a004 + (or * 0x0800), 0xc000007f, dpms_ctrl);
  819. nv_wait(device, 0x61a004 + (or * 0x0800), 0x80000000, 0x00000000);
  820. }
  821. static bool
  822. nvd0_dac_mode_fixup(struct drm_encoder *encoder,
  823. const struct drm_display_mode *mode,
  824. struct drm_display_mode *adjusted_mode)
  825. {
  826. struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
  827. struct nouveau_connector *nv_connector;
  828. nv_connector = nouveau_encoder_connector_get(nv_encoder);
  829. if (nv_connector && nv_connector->native_mode) {
  830. if (nv_connector->scaling_mode != DRM_MODE_SCALE_NONE) {
  831. int id = adjusted_mode->base.id;
  832. *adjusted_mode = *nv_connector->native_mode;
  833. adjusted_mode->base.id = id;
  834. }
  835. }
  836. return true;
  837. }
  838. static void
  839. nvd0_dac_commit(struct drm_encoder *encoder)
  840. {
  841. }
  842. static void
  843. nvd0_dac_mode_set(struct drm_encoder *encoder, struct drm_display_mode *mode,
  844. struct drm_display_mode *adjusted_mode)
  845. {
  846. struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
  847. struct nouveau_crtc *nv_crtc = nouveau_crtc(encoder->crtc);
  848. u32 syncs, magic, *push;
  849. syncs = 0x00000001;
  850. if (mode->flags & DRM_MODE_FLAG_NHSYNC)
  851. syncs |= 0x00000008;
  852. if (mode->flags & DRM_MODE_FLAG_NVSYNC)
  853. syncs |= 0x00000010;
  854. magic = 0x31ec6000 | (nv_crtc->index << 25);
  855. if (mode->flags & DRM_MODE_FLAG_INTERLACE)
  856. magic |= 0x00000001;
  857. nvd0_dac_dpms(encoder, DRM_MODE_DPMS_ON);
  858. push = evo_wait(encoder->dev, EVO_MASTER, 8);
  859. if (push) {
  860. evo_mthd(push, 0x0404 + (nv_crtc->index * 0x300), 2);
  861. evo_data(push, syncs);
  862. evo_data(push, magic);
  863. evo_mthd(push, 0x0180 + (nv_encoder->or * 0x020), 2);
  864. evo_data(push, 1 << nv_crtc->index);
  865. evo_data(push, 0x00ff);
  866. evo_kick(push, encoder->dev, EVO_MASTER);
  867. }
  868. nv_encoder->crtc = encoder->crtc;
  869. }
  870. static void
  871. nvd0_dac_disconnect(struct drm_encoder *encoder)
  872. {
  873. struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
  874. struct drm_device *dev = encoder->dev;
  875. u32 *push;
  876. if (nv_encoder->crtc) {
  877. nvd0_crtc_prepare(nv_encoder->crtc);
  878. push = evo_wait(dev, EVO_MASTER, 4);
  879. if (push) {
  880. evo_mthd(push, 0x0180 + (nv_encoder->or * 0x20), 1);
  881. evo_data(push, 0x00000000);
  882. evo_mthd(push, 0x0080, 1);
  883. evo_data(push, 0x00000000);
  884. evo_kick(push, dev, EVO_MASTER);
  885. }
  886. nv_encoder->crtc = NULL;
  887. }
  888. }
  889. static enum drm_connector_status
  890. nvd0_dac_detect(struct drm_encoder *encoder, struct drm_connector *connector)
  891. {
  892. enum drm_connector_status status = connector_status_disconnected;
  893. struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
  894. struct drm_device *dev = encoder->dev;
  895. struct nouveau_device *device = nouveau_dev(dev);
  896. int or = nv_encoder->or;
  897. u32 load;
  898. nv_wr32(device, 0x61a00c + (or * 0x800), 0x00100000);
  899. udelay(9500);
  900. nv_wr32(device, 0x61a00c + (or * 0x800), 0x80000000);
  901. load = nv_rd32(device, 0x61a00c + (or * 0x800));
  902. if ((load & 0x38000000) == 0x38000000)
  903. status = connector_status_connected;
  904. nv_wr32(device, 0x61a00c + (or * 0x800), 0x00000000);
  905. return status;
  906. }
  907. static void
  908. nvd0_dac_destroy(struct drm_encoder *encoder)
  909. {
  910. drm_encoder_cleanup(encoder);
  911. kfree(encoder);
  912. }
  913. static const struct drm_encoder_helper_funcs nvd0_dac_hfunc = {
  914. .dpms = nvd0_dac_dpms,
  915. .mode_fixup = nvd0_dac_mode_fixup,
  916. .prepare = nvd0_dac_disconnect,
  917. .commit = nvd0_dac_commit,
  918. .mode_set = nvd0_dac_mode_set,
  919. .disable = nvd0_dac_disconnect,
  920. .get_crtc = nvd0_display_crtc_get,
  921. .detect = nvd0_dac_detect
  922. };
  923. static const struct drm_encoder_funcs nvd0_dac_func = {
  924. .destroy = nvd0_dac_destroy,
  925. };
  926. static int
  927. nvd0_dac_create(struct drm_connector *connector, struct dcb_output *dcbe)
  928. {
  929. struct drm_device *dev = connector->dev;
  930. struct nouveau_encoder *nv_encoder;
  931. struct drm_encoder *encoder;
  932. nv_encoder = kzalloc(sizeof(*nv_encoder), GFP_KERNEL);
  933. if (!nv_encoder)
  934. return -ENOMEM;
  935. nv_encoder->dcb = dcbe;
  936. nv_encoder->or = ffs(dcbe->or) - 1;
  937. encoder = to_drm_encoder(nv_encoder);
  938. encoder->possible_crtcs = dcbe->heads;
  939. encoder->possible_clones = 0;
  940. drm_encoder_init(dev, encoder, &nvd0_dac_func, DRM_MODE_ENCODER_DAC);
  941. drm_encoder_helper_add(encoder, &nvd0_dac_hfunc);
  942. drm_mode_connector_attach_encoder(connector, encoder);
  943. return 0;
  944. }
  945. /******************************************************************************
  946. * Audio
  947. *****************************************************************************/
  948. static void
  949. nvd0_audio_mode_set(struct drm_encoder *encoder, struct drm_display_mode *mode)
  950. {
  951. struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
  952. struct nouveau_connector *nv_connector;
  953. struct drm_device *dev = encoder->dev;
  954. struct nouveau_device *device = nouveau_dev(dev);
  955. int i, or = nv_encoder->or * 0x30;
  956. nv_connector = nouveau_encoder_connector_get(nv_encoder);
  957. if (!drm_detect_monitor_audio(nv_connector->edid))
  958. return;
  959. nv_mask(device, 0x10ec10 + or, 0x80000003, 0x80000001);
  960. drm_edid_to_eld(&nv_connector->base, nv_connector->edid);
  961. if (nv_connector->base.eld[0]) {
  962. u8 *eld = nv_connector->base.eld;
  963. for (i = 0; i < eld[2] * 4; i++)
  964. nv_wr32(device, 0x10ec00 + or, (i << 8) | eld[i]);
  965. for (i = eld[2] * 4; i < 0x60; i++)
  966. nv_wr32(device, 0x10ec00 + or, (i << 8) | 0x00);
  967. nv_mask(device, 0x10ec10 + or, 0x80000002, 0x80000002);
  968. }
  969. }
  970. static void
  971. nvd0_audio_disconnect(struct drm_encoder *encoder)
  972. {
  973. struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
  974. struct drm_device *dev = encoder->dev;
  975. struct nouveau_device *device = nouveau_dev(dev);
  976. int or = nv_encoder->or * 0x30;
  977. nv_mask(device, 0x10ec10 + or, 0x80000003, 0x80000000);
  978. }
  979. /******************************************************************************
  980. * HDMI
  981. *****************************************************************************/
  982. static void
  983. nvd0_hdmi_mode_set(struct drm_encoder *encoder, struct drm_display_mode *mode)
  984. {
  985. struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
  986. struct nouveau_crtc *nv_crtc = nouveau_crtc(encoder->crtc);
  987. struct nouveau_connector *nv_connector;
  988. struct drm_device *dev = encoder->dev;
  989. struct nouveau_device *device = nouveau_dev(dev);
  990. int head = nv_crtc->index * 0x800;
  991. u32 rekey = 56; /* binary driver, and tegra constant */
  992. u32 max_ac_packet;
  993. nv_connector = nouveau_encoder_connector_get(nv_encoder);
  994. if (!drm_detect_hdmi_monitor(nv_connector->edid))
  995. return;
  996. max_ac_packet = mode->htotal - mode->hdisplay;
  997. max_ac_packet -= rekey;
  998. max_ac_packet -= 18; /* constant from tegra */
  999. max_ac_packet /= 32;
  1000. /* AVI InfoFrame */
  1001. nv_mask(device, 0x616714 + head, 0x00000001, 0x00000000);
  1002. nv_wr32(device, 0x61671c + head, 0x000d0282);
  1003. nv_wr32(device, 0x616720 + head, 0x0000006f);
  1004. nv_wr32(device, 0x616724 + head, 0x00000000);
  1005. nv_wr32(device, 0x616728 + head, 0x00000000);
  1006. nv_wr32(device, 0x61672c + head, 0x00000000);
  1007. nv_mask(device, 0x616714 + head, 0x00000001, 0x00000001);
  1008. /* ??? InfoFrame? */
  1009. nv_mask(device, 0x6167a4 + head, 0x00000001, 0x00000000);
  1010. nv_wr32(device, 0x6167ac + head, 0x00000010);
  1011. nv_mask(device, 0x6167a4 + head, 0x00000001, 0x00000001);
  1012. /* HDMI_CTRL */
  1013. nv_mask(device, 0x616798 + head, 0x401f007f, 0x40000000 | rekey |
  1014. max_ac_packet << 16);
  1015. /* NFI, audio doesn't work without it though.. */
  1016. nv_mask(device, 0x616548 + head, 0x00000070, 0x00000000);
  1017. nvd0_audio_mode_set(encoder, mode);
  1018. }
  1019. static void
  1020. nvd0_hdmi_disconnect(struct drm_encoder *encoder)
  1021. {
  1022. struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
  1023. struct nouveau_crtc *nv_crtc = nouveau_crtc(nv_encoder->crtc);
  1024. struct drm_device *dev = encoder->dev;
  1025. struct nouveau_device *device = nouveau_dev(dev);
  1026. int head = nv_crtc->index * 0x800;
  1027. nvd0_audio_disconnect(encoder);
  1028. nv_mask(device, 0x616798 + head, 0x40000000, 0x00000000);
  1029. nv_mask(device, 0x6167a4 + head, 0x00000001, 0x00000000);
  1030. nv_mask(device, 0x616714 + head, 0x00000001, 0x00000000);
  1031. }
  1032. /******************************************************************************
  1033. * SOR
  1034. *****************************************************************************/
  1035. static inline u32
  1036. nvd0_sor_dp_lane_map(struct drm_device *dev, struct dcb_output *dcb, u8 lane)
  1037. {
  1038. static const u8 nvd0[] = { 16, 8, 0, 24 };
  1039. return nvd0[lane];
  1040. }
  1041. static void
  1042. nvd0_sor_dp_train_set(struct drm_device *dev, struct dcb_output *dcb, u8 pattern)
  1043. {
  1044. struct nouveau_device *device = nouveau_dev(dev);
  1045. const u32 or = ffs(dcb->or) - 1, link = !(dcb->sorconf.link & 1);
  1046. const u32 loff = (or * 0x800) + (link * 0x80);
  1047. nv_mask(device, 0x61c110 + loff, 0x0f0f0f0f, 0x01010101 * pattern);
  1048. }
  1049. static void
  1050. nvd0_sor_dp_train_adj(struct drm_device *dev, struct dcb_output *dcb,
  1051. u8 lane, u8 swing, u8 preem)
  1052. {
  1053. struct nouveau_device *device = nouveau_dev(dev);
  1054. struct nouveau_drm *drm = nouveau_drm(dev);
  1055. const u32 or = ffs(dcb->or) - 1, link = !(dcb->sorconf.link & 1);
  1056. const u32 loff = (or * 0x800) + (link * 0x80);
  1057. u32 shift = nvd0_sor_dp_lane_map(dev, dcb, lane);
  1058. u32 mask = 0x000000ff << shift;
  1059. u8 *table, *entry, *config = NULL;
  1060. switch (swing) {
  1061. case 0: preem += 0; break;
  1062. case 1: preem += 4; break;
  1063. case 2: preem += 7; break;
  1064. case 3: preem += 9; break;
  1065. }
  1066. table = nouveau_dp_bios_data(dev, dcb, &entry);
  1067. if (table) {
  1068. if (table[0] == 0x30) {
  1069. config = entry + table[4];
  1070. config += table[5] * preem;
  1071. } else
  1072. if (table[0] == 0x40) {
  1073. config = table + table[1];
  1074. config += table[2] * table[3];
  1075. config += table[6] * preem;
  1076. }
  1077. }
  1078. if (!config) {
  1079. NV_ERROR(drm, "PDISP: unsupported DP table for chipset\n");
  1080. return;
  1081. }
  1082. nv_mask(device, 0x61c118 + loff, mask, config[1] << shift);
  1083. nv_mask(device, 0x61c120 + loff, mask, config[2] << shift);
  1084. nv_mask(device, 0x61c130 + loff, 0x0000ff00, config[3] << 8);
  1085. nv_mask(device, 0x61c13c + loff, 0x00000000, 0x00000000);
  1086. }
  1087. static void
  1088. nvd0_sor_dp_link_set(struct drm_device *dev, struct dcb_output *dcb, int crtc,
  1089. int link_nr, u32 link_bw, bool enhframe)
  1090. {
  1091. struct nouveau_device *device = nouveau_dev(dev);
  1092. const u32 or = ffs(dcb->or) - 1, link = !(dcb->sorconf.link & 1);
  1093. const u32 loff = (or * 0x800) + (link * 0x80);
  1094. const u32 soff = (or * 0x800);
  1095. u32 dpctrl = nv_rd32(device, 0x61c10c + loff) & ~0x001f4000;
  1096. u32 clksor = nv_rd32(device, 0x612300 + soff) & ~0x007c0000;
  1097. u32 script = 0x0000, lane_mask = 0;
  1098. u8 *table, *entry;
  1099. int i;
  1100. link_bw /= 27000;
  1101. table = nouveau_dp_bios_data(dev, dcb, &entry);
  1102. if (table) {
  1103. if (table[0] == 0x30) entry = ROMPTR(dev, entry[10]);
  1104. else if (table[0] == 0x40) entry = ROMPTR(dev, entry[9]);
  1105. else entry = NULL;
  1106. while (entry) {
  1107. if (entry[0] >= link_bw)
  1108. break;
  1109. entry += 3;
  1110. }
  1111. nouveau_bios_run_init_table(dev, script, dcb, crtc);
  1112. }
  1113. clksor |= link_bw << 18;
  1114. dpctrl |= ((1 << link_nr) - 1) << 16;
  1115. if (enhframe)
  1116. dpctrl |= 0x00004000;
  1117. for (i = 0; i < link_nr; i++)
  1118. lane_mask |= 1 << (nvd0_sor_dp_lane_map(dev, dcb, i) >> 3);
  1119. nv_wr32(device, 0x612300 + soff, clksor);
  1120. nv_wr32(device, 0x61c10c + loff, dpctrl);
  1121. nv_mask(device, 0x61c130 + loff, 0x0000000f, lane_mask);
  1122. }
  1123. static void
  1124. nvd0_sor_dp_link_get(struct drm_device *dev, struct dcb_output *dcb,
  1125. u32 *link_nr, u32 *link_bw)
  1126. {
  1127. struct nouveau_device *device = nouveau_dev(dev);
  1128. const u32 or = ffs(dcb->or) - 1, link = !(dcb->sorconf.link & 1);
  1129. const u32 loff = (or * 0x800) + (link * 0x80);
  1130. const u32 soff = (or * 0x800);
  1131. u32 dpctrl = nv_rd32(device, 0x61c10c + loff) & 0x000f0000;
  1132. u32 clksor = nv_rd32(device, 0x612300 + soff);
  1133. if (dpctrl > 0x00030000) *link_nr = 4;
  1134. else if (dpctrl > 0x00010000) *link_nr = 2;
  1135. else *link_nr = 1;
  1136. *link_bw = (clksor & 0x007c0000) >> 18;
  1137. *link_bw *= 27000;
  1138. }
  1139. static void
  1140. nvd0_sor_dp_calc_tu(struct drm_device *dev, struct dcb_output *dcb,
  1141. u32 crtc, u32 datarate)
  1142. {
  1143. struct nouveau_device *device = nouveau_dev(dev);
  1144. const u32 symbol = 100000;
  1145. const u32 TU = 64;
  1146. u32 link_nr, link_bw;
  1147. u64 ratio, value;
  1148. nvd0_sor_dp_link_get(dev, dcb, &link_nr, &link_bw);
  1149. ratio = datarate;
  1150. ratio *= symbol;
  1151. do_div(ratio, link_nr * link_bw);
  1152. value = (symbol - ratio) * TU;
  1153. value *= ratio;
  1154. do_div(value, symbol);
  1155. do_div(value, symbol);
  1156. value += 5;
  1157. value |= 0x08000000;
  1158. nv_wr32(device, 0x616610 + (crtc * 0x800), value);
  1159. }
  1160. static void
  1161. nvd0_sor_dpms(struct drm_encoder *encoder, int mode)
  1162. {
  1163. struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
  1164. struct drm_device *dev = encoder->dev;
  1165. struct nouveau_device *device = nouveau_dev(dev);
  1166. struct drm_encoder *partner;
  1167. int or = nv_encoder->or;
  1168. u32 dpms_ctrl;
  1169. nv_encoder->last_dpms = mode;
  1170. list_for_each_entry(partner, &dev->mode_config.encoder_list, head) {
  1171. struct nouveau_encoder *nv_partner = nouveau_encoder(partner);
  1172. if (partner->encoder_type != DRM_MODE_ENCODER_TMDS)
  1173. continue;
  1174. if (nv_partner != nv_encoder &&
  1175. nv_partner->dcb->or == nv_encoder->dcb->or) {
  1176. if (nv_partner->last_dpms == DRM_MODE_DPMS_ON)
  1177. return;
  1178. break;
  1179. }
  1180. }
  1181. dpms_ctrl = (mode == DRM_MODE_DPMS_ON);
  1182. dpms_ctrl |= 0x80000000;
  1183. nv_wait(device, 0x61c004 + (or * 0x0800), 0x80000000, 0x00000000);
  1184. nv_mask(device, 0x61c004 + (or * 0x0800), 0x80000001, dpms_ctrl);
  1185. nv_wait(device, 0x61c004 + (or * 0x0800), 0x80000000, 0x00000000);
  1186. nv_wait(device, 0x61c030 + (or * 0x0800), 0x10000000, 0x00000000);
  1187. if (nv_encoder->dcb->type == DCB_OUTPUT_DP) {
  1188. struct dp_train_func func = {
  1189. .link_set = nvd0_sor_dp_link_set,
  1190. .train_set = nvd0_sor_dp_train_set,
  1191. .train_adj = nvd0_sor_dp_train_adj
  1192. };
  1193. nouveau_dp_dpms(encoder, mode, nv_encoder->dp.datarate, &func);
  1194. }
  1195. }
  1196. static bool
  1197. nvd0_sor_mode_fixup(struct drm_encoder *encoder,
  1198. const struct drm_display_mode *mode,
  1199. struct drm_display_mode *adjusted_mode)
  1200. {
  1201. struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
  1202. struct nouveau_connector *nv_connector;
  1203. nv_connector = nouveau_encoder_connector_get(nv_encoder);
  1204. if (nv_connector && nv_connector->native_mode) {
  1205. if (nv_connector->scaling_mode != DRM_MODE_SCALE_NONE) {
  1206. int id = adjusted_mode->base.id;
  1207. *adjusted_mode = *nv_connector->native_mode;
  1208. adjusted_mode->base.id = id;
  1209. }
  1210. }
  1211. return true;
  1212. }
  1213. static void
  1214. nvd0_sor_disconnect(struct drm_encoder *encoder)
  1215. {
  1216. struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
  1217. struct drm_device *dev = encoder->dev;
  1218. u32 *push;
  1219. if (nv_encoder->crtc) {
  1220. nvd0_crtc_prepare(nv_encoder->crtc);
  1221. push = evo_wait(dev, EVO_MASTER, 4);
  1222. if (push) {
  1223. evo_mthd(push, 0x0200 + (nv_encoder->or * 0x20), 1);
  1224. evo_data(push, 0x00000000);
  1225. evo_mthd(push, 0x0080, 1);
  1226. evo_data(push, 0x00000000);
  1227. evo_kick(push, dev, EVO_MASTER);
  1228. }
  1229. nvd0_hdmi_disconnect(encoder);
  1230. nv_encoder->crtc = NULL;
  1231. nv_encoder->last_dpms = DRM_MODE_DPMS_OFF;
  1232. }
  1233. }
  1234. static void
  1235. nvd0_sor_prepare(struct drm_encoder *encoder)
  1236. {
  1237. nvd0_sor_disconnect(encoder);
  1238. if (nouveau_encoder(encoder)->dcb->type == DCB_OUTPUT_DP)
  1239. evo_sync(encoder->dev, EVO_MASTER);
  1240. }
  1241. static void
  1242. nvd0_sor_commit(struct drm_encoder *encoder)
  1243. {
  1244. }
  1245. static void
  1246. nvd0_sor_mode_set(struct drm_encoder *encoder, struct drm_display_mode *umode,
  1247. struct drm_display_mode *mode)
  1248. {
  1249. struct drm_device *dev = encoder->dev;
  1250. struct nouveau_drm *drm = nouveau_drm(dev);
  1251. struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
  1252. struct nouveau_crtc *nv_crtc = nouveau_crtc(encoder->crtc);
  1253. struct nouveau_connector *nv_connector;
  1254. struct nvbios *bios = &drm->vbios;
  1255. u32 mode_ctrl = (1 << nv_crtc->index);
  1256. u32 syncs, magic, *push;
  1257. u32 or_config;
  1258. syncs = 0x00000001;
  1259. if (mode->flags & DRM_MODE_FLAG_NHSYNC)
  1260. syncs |= 0x00000008;
  1261. if (mode->flags & DRM_MODE_FLAG_NVSYNC)
  1262. syncs |= 0x00000010;
  1263. magic = 0x31ec6000 | (nv_crtc->index << 25);
  1264. if (mode->flags & DRM_MODE_FLAG_INTERLACE)
  1265. magic |= 0x00000001;
  1266. nv_connector = nouveau_encoder_connector_get(nv_encoder);
  1267. switch (nv_encoder->dcb->type) {
  1268. case DCB_OUTPUT_TMDS:
  1269. if (nv_encoder->dcb->sorconf.link & 1) {
  1270. if (mode->clock < 165000)
  1271. mode_ctrl |= 0x00000100;
  1272. else
  1273. mode_ctrl |= 0x00000500;
  1274. } else {
  1275. mode_ctrl |= 0x00000200;
  1276. }
  1277. or_config = (mode_ctrl & 0x00000f00) >> 8;
  1278. if (mode->clock >= 165000)
  1279. or_config |= 0x0100;
  1280. nvd0_hdmi_mode_set(encoder, mode);
  1281. break;
  1282. case DCB_OUTPUT_LVDS:
  1283. or_config = (mode_ctrl & 0x00000f00) >> 8;
  1284. if (bios->fp_no_ddc) {
  1285. if (bios->fp.dual_link)
  1286. or_config |= 0x0100;
  1287. if (bios->fp.if_is_24bit)
  1288. or_config |= 0x0200;
  1289. } else {
  1290. if (nv_connector->type == DCB_CONNECTOR_LVDS_SPWG) {
  1291. if (((u8 *)nv_connector->edid)[121] == 2)
  1292. or_config |= 0x0100;
  1293. } else
  1294. if (mode->clock >= bios->fp.duallink_transition_clk) {
  1295. or_config |= 0x0100;
  1296. }
  1297. if (or_config & 0x0100) {
  1298. if (bios->fp.strapless_is_24bit & 2)
  1299. or_config |= 0x0200;
  1300. } else {
  1301. if (bios->fp.strapless_is_24bit & 1)
  1302. or_config |= 0x0200;
  1303. }
  1304. if (nv_connector->base.display_info.bpc == 8)
  1305. or_config |= 0x0200;
  1306. }
  1307. break;
  1308. case DCB_OUTPUT_DP:
  1309. if (nv_connector->base.display_info.bpc == 6) {
  1310. nv_encoder->dp.datarate = mode->clock * 18 / 8;
  1311. syncs |= 0x00000002 << 6;
  1312. } else {
  1313. nv_encoder->dp.datarate = mode->clock * 24 / 8;
  1314. syncs |= 0x00000005 << 6;
  1315. }
  1316. if (nv_encoder->dcb->sorconf.link & 1)
  1317. mode_ctrl |= 0x00000800;
  1318. else
  1319. mode_ctrl |= 0x00000900;
  1320. or_config = (mode_ctrl & 0x00000f00) >> 8;
  1321. break;
  1322. default:
  1323. BUG_ON(1);
  1324. break;
  1325. }
  1326. nvd0_sor_dpms(encoder, DRM_MODE_DPMS_ON);
  1327. if (nv_encoder->dcb->type == DCB_OUTPUT_DP) {
  1328. nvd0_sor_dp_calc_tu(dev, nv_encoder->dcb, nv_crtc->index,
  1329. nv_encoder->dp.datarate);
  1330. }
  1331. push = evo_wait(dev, EVO_MASTER, 8);
  1332. if (push) {
  1333. evo_mthd(push, 0x0404 + (nv_crtc->index * 0x300), 2);
  1334. evo_data(push, syncs);
  1335. evo_data(push, magic);
  1336. evo_mthd(push, 0x0200 + (nv_encoder->or * 0x020), 2);
  1337. evo_data(push, mode_ctrl);
  1338. evo_data(push, or_config);
  1339. evo_kick(push, dev, EVO_MASTER);
  1340. }
  1341. nv_encoder->crtc = encoder->crtc;
  1342. }
  1343. static void
  1344. nvd0_sor_destroy(struct drm_encoder *encoder)
  1345. {
  1346. drm_encoder_cleanup(encoder);
  1347. kfree(encoder);
  1348. }
  1349. static const struct drm_encoder_helper_funcs nvd0_sor_hfunc = {
  1350. .dpms = nvd0_sor_dpms,
  1351. .mode_fixup = nvd0_sor_mode_fixup,
  1352. .prepare = nvd0_sor_prepare,
  1353. .commit = nvd0_sor_commit,
  1354. .mode_set = nvd0_sor_mode_set,
  1355. .disable = nvd0_sor_disconnect,
  1356. .get_crtc = nvd0_display_crtc_get,
  1357. };
  1358. static const struct drm_encoder_funcs nvd0_sor_func = {
  1359. .destroy = nvd0_sor_destroy,
  1360. };
  1361. static int
  1362. nvd0_sor_create(struct drm_connector *connector, struct dcb_output *dcbe)
  1363. {
  1364. struct drm_device *dev = connector->dev;
  1365. struct nouveau_encoder *nv_encoder;
  1366. struct drm_encoder *encoder;
  1367. nv_encoder = kzalloc(sizeof(*nv_encoder), GFP_KERNEL);
  1368. if (!nv_encoder)
  1369. return -ENOMEM;
  1370. nv_encoder->dcb = dcbe;
  1371. nv_encoder->or = ffs(dcbe->or) - 1;
  1372. nv_encoder->last_dpms = DRM_MODE_DPMS_OFF;
  1373. encoder = to_drm_encoder(nv_encoder);
  1374. encoder->possible_crtcs = dcbe->heads;
  1375. encoder->possible_clones = 0;
  1376. drm_encoder_init(dev, encoder, &nvd0_sor_func, DRM_MODE_ENCODER_TMDS);
  1377. drm_encoder_helper_add(encoder, &nvd0_sor_hfunc);
  1378. drm_mode_connector_attach_encoder(connector, encoder);
  1379. return 0;
  1380. }
  1381. /******************************************************************************
  1382. * IRQ
  1383. *****************************************************************************/
  1384. static struct dcb_output *
  1385. lookup_dcb(struct drm_device *dev, int id, u32 mc)
  1386. {
  1387. struct nouveau_drm *drm = nouveau_drm(dev);
  1388. int type, or, i, link = -1;
  1389. if (id < 4) {
  1390. type = DCB_OUTPUT_ANALOG;
  1391. or = id;
  1392. } else {
  1393. switch (mc & 0x00000f00) {
  1394. case 0x00000000: link = 0; type = DCB_OUTPUT_LVDS; break;
  1395. case 0x00000100: link = 0; type = DCB_OUTPUT_TMDS; break;
  1396. case 0x00000200: link = 1; type = DCB_OUTPUT_TMDS; break;
  1397. case 0x00000500: link = 0; type = DCB_OUTPUT_TMDS; break;
  1398. case 0x00000800: link = 0; type = DCB_OUTPUT_DP; break;
  1399. case 0x00000900: link = 1; type = DCB_OUTPUT_DP; break;
  1400. default:
  1401. NV_ERROR(drm, "PDISP: unknown SOR mc 0x%08x\n", mc);
  1402. return NULL;
  1403. }
  1404. or = id - 4;
  1405. }
  1406. for (i = 0; i < drm->vbios.dcb.entries; i++) {
  1407. struct dcb_output *dcb = &drm->vbios.dcb.entry[i];
  1408. if (dcb->type == type && (dcb->or & (1 << or)) &&
  1409. (link < 0 || link == !(dcb->sorconf.link & 1)))
  1410. return dcb;
  1411. }
  1412. NV_ERROR(drm, "PDISP: DCB for %d/0x%08x not found\n", id, mc);
  1413. return NULL;
  1414. }
  1415. static void
  1416. nvd0_display_unk1_handler(struct drm_device *dev, u32 crtc, u32 mask)
  1417. {
  1418. struct nouveau_device *device = nouveau_dev(dev);
  1419. struct dcb_output *dcb;
  1420. int i;
  1421. for (i = 0; mask && i < 8; i++) {
  1422. u32 mcc = nv_rd32(device, 0x640180 + (i * 0x20));
  1423. if (!(mcc & (1 << crtc)))
  1424. continue;
  1425. dcb = lookup_dcb(dev, i, mcc);
  1426. if (!dcb)
  1427. continue;
  1428. nouveau_bios_run_display_table(dev, 0x0000, -1, dcb, crtc);
  1429. }
  1430. nv_wr32(device, 0x6101d4, 0x00000000);
  1431. nv_wr32(device, 0x6109d4, 0x00000000);
  1432. nv_wr32(device, 0x6101d0, 0x80000000);
  1433. }
  1434. static void
  1435. nvd0_display_unk2_handler(struct drm_device *dev, u32 crtc, u32 mask)
  1436. {
  1437. struct nouveau_device *device = nouveau_dev(dev);
  1438. struct nouveau_drm *drm = nouveau_drm(dev);
  1439. struct dcb_output *dcb;
  1440. u32 or, tmp, pclk;
  1441. int i;
  1442. for (i = 0; mask && i < 8; i++) {
  1443. u32 mcc = nv_rd32(device, 0x640180 + (i * 0x20));
  1444. if (!(mcc & (1 << crtc)))
  1445. continue;
  1446. dcb = lookup_dcb(dev, i, mcc);
  1447. if (!dcb)
  1448. continue;
  1449. nouveau_bios_run_display_table(dev, 0x0000, -2, dcb, crtc);
  1450. }
  1451. pclk = nv_rd32(device, 0x660450 + (crtc * 0x300)) / 1000;
  1452. NV_DEBUG(drm, "PDISP: crtc %d pclk %d mask 0x%08x\n",
  1453. crtc, pclk, mask);
  1454. if (pclk && (mask & 0x00010000)) {
  1455. nv50_crtc_set_clock(dev, crtc, pclk);
  1456. }
  1457. for (i = 0; mask && i < 8; i++) {
  1458. u32 mcp = nv_rd32(device, 0x660180 + (i * 0x20));
  1459. u32 cfg = nv_rd32(device, 0x660184 + (i * 0x20));
  1460. if (!(mcp & (1 << crtc)))
  1461. continue;
  1462. dcb = lookup_dcb(dev, i, mcp);
  1463. if (!dcb)
  1464. continue;
  1465. or = ffs(dcb->or) - 1;
  1466. nouveau_bios_run_display_table(dev, cfg, pclk, dcb, crtc);
  1467. nv_wr32(device, 0x612200 + (crtc * 0x800), 0x00000000);
  1468. switch (dcb->type) {
  1469. case DCB_OUTPUT_ANALOG:
  1470. nv_wr32(device, 0x612280 + (or * 0x800), 0x00000000);
  1471. break;
  1472. case DCB_OUTPUT_TMDS:
  1473. case DCB_OUTPUT_LVDS:
  1474. case DCB_OUTPUT_DP:
  1475. if (cfg & 0x00000100)
  1476. tmp = 0x00000101;
  1477. else
  1478. tmp = 0x00000000;
  1479. nv_mask(device, 0x612300 + (or * 0x800), 0x00000707, tmp);
  1480. break;
  1481. default:
  1482. break;
  1483. }
  1484. break;
  1485. }
  1486. nv_wr32(device, 0x6101d4, 0x00000000);
  1487. nv_wr32(device, 0x6109d4, 0x00000000);
  1488. nv_wr32(device, 0x6101d0, 0x80000000);
  1489. }
  1490. static void
  1491. nvd0_display_unk4_handler(struct drm_device *dev, u32 crtc, u32 mask)
  1492. {
  1493. struct nouveau_device *device = nouveau_dev(dev);
  1494. struct dcb_output *dcb;
  1495. int pclk, i;
  1496. pclk = nv_rd32(device, 0x660450 + (crtc * 0x300)) / 1000;
  1497. for (i = 0; mask && i < 8; i++) {
  1498. u32 mcp = nv_rd32(device, 0x660180 + (i * 0x20));
  1499. u32 cfg = nv_rd32(device, 0x660184 + (i * 0x20));
  1500. if (!(mcp & (1 << crtc)))
  1501. continue;
  1502. dcb = lookup_dcb(dev, i, mcp);
  1503. if (!dcb)
  1504. continue;
  1505. nouveau_bios_run_display_table(dev, cfg, -pclk, dcb, crtc);
  1506. }
  1507. nv_wr32(device, 0x6101d4, 0x00000000);
  1508. nv_wr32(device, 0x6109d4, 0x00000000);
  1509. nv_wr32(device, 0x6101d0, 0x80000000);
  1510. }
  1511. static void
  1512. nvd0_display_bh(unsigned long data)
  1513. {
  1514. struct drm_device *dev = (struct drm_device *)data;
  1515. struct nouveau_device *device = nouveau_dev(dev);
  1516. struct nouveau_drm *drm = nouveau_drm(dev);
  1517. struct nvd0_display *disp = nvd0_display(dev);
  1518. u32 mask = 0, crtc = ~0;
  1519. int i;
  1520. if (drm_debug & (DRM_UT_DRIVER | DRM_UT_KMS)) {
  1521. NV_INFO(drm, "PDISP: modeset req %d\n", disp->modeset);
  1522. NV_INFO(drm, " STAT: 0x%08x 0x%08x 0x%08x\n",
  1523. nv_rd32(device, 0x6101d0),
  1524. nv_rd32(device, 0x6101d4), nv_rd32(device, 0x6109d4));
  1525. for (i = 0; i < 8; i++) {
  1526. NV_INFO(drm, " %s%d: 0x%08x 0x%08x\n",
  1527. i < 4 ? "DAC" : "SOR", i,
  1528. nv_rd32(device, 0x640180 + (i * 0x20)),
  1529. nv_rd32(device, 0x660180 + (i * 0x20)));
  1530. }
  1531. }
  1532. while (!mask && ++crtc < dev->mode_config.num_crtc)
  1533. mask = nv_rd32(device, 0x6101d4 + (crtc * 0x800));
  1534. if (disp->modeset & 0x00000001)
  1535. nvd0_display_unk1_handler(dev, crtc, mask);
  1536. if (disp->modeset & 0x00000002)
  1537. nvd0_display_unk2_handler(dev, crtc, mask);
  1538. if (disp->modeset & 0x00000004)
  1539. nvd0_display_unk4_handler(dev, crtc, mask);
  1540. }
  1541. void
  1542. nvd0_display_intr(struct drm_device *dev)
  1543. {
  1544. struct nvd0_display *disp = nvd0_display(dev);
  1545. struct nouveau_device *device = nouveau_dev(dev);
  1546. struct nouveau_drm *drm = nouveau_drm(dev);
  1547. u32 intr = nv_rd32(device, 0x610088);
  1548. if (intr & 0x00000001) {
  1549. u32 stat = nv_rd32(device, 0x61008c);
  1550. nv_wr32(device, 0x61008c, stat);
  1551. intr &= ~0x00000001;
  1552. }
  1553. if (intr & 0x00000002) {
  1554. u32 stat = nv_rd32(device, 0x61009c);
  1555. int chid = ffs(stat) - 1;
  1556. if (chid >= 0) {
  1557. u32 mthd = nv_rd32(device, 0x6101f0 + (chid * 12));
  1558. u32 data = nv_rd32(device, 0x6101f4 + (chid * 12));
  1559. u32 unkn = nv_rd32(device, 0x6101f8 + (chid * 12));
  1560. NV_INFO(drm, "EvoCh: chid %d mthd 0x%04x data 0x%08x "
  1561. "0x%08x 0x%08x\n",
  1562. chid, (mthd & 0x0000ffc), data, mthd, unkn);
  1563. nv_wr32(device, 0x61009c, (1 << chid));
  1564. nv_wr32(device, 0x6101f0 + (chid * 12), 0x90000000);
  1565. }
  1566. intr &= ~0x00000002;
  1567. }
  1568. if (intr & 0x00100000) {
  1569. u32 stat = nv_rd32(device, 0x6100ac);
  1570. if (stat & 0x00000007) {
  1571. disp->modeset = stat;
  1572. tasklet_schedule(&disp->tasklet);
  1573. nv_wr32(device, 0x6100ac, (stat & 0x00000007));
  1574. stat &= ~0x00000007;
  1575. }
  1576. if (stat) {
  1577. NV_INFO(drm, "PDISP: unknown intr24 0x%08x\n", stat);
  1578. nv_wr32(device, 0x6100ac, stat);
  1579. }
  1580. intr &= ~0x00100000;
  1581. }
  1582. intr &= ~0x0f000000; /* vblank, handled in core */
  1583. if (intr)
  1584. NV_INFO(drm, "PDISP: unknown intr 0x%08x\n", intr);
  1585. }
  1586. /******************************************************************************
  1587. * Init
  1588. *****************************************************************************/
  1589. void
  1590. nvd0_display_fini(struct drm_device *dev)
  1591. {
  1592. int i;
  1593. /* fini cursors + overlays + flips */
  1594. for (i = 1; i >= 0; i--) {
  1595. evo_fini_pio(dev, EVO_CURS(i));
  1596. evo_fini_pio(dev, EVO_OIMM(i));
  1597. evo_fini_dma(dev, EVO_OVLY(i));
  1598. evo_fini_dma(dev, EVO_FLIP(i));
  1599. }
  1600. /* fini master */
  1601. evo_fini_dma(dev, EVO_MASTER);
  1602. }
  1603. int
  1604. nvd0_display_init(struct drm_device *dev)
  1605. {
  1606. struct nvd0_display *disp = nvd0_display(dev);
  1607. struct nouveau_device *device = nouveau_dev(dev);
  1608. struct nouveau_drm *drm = nouveau_drm(dev);
  1609. int ret, i;
  1610. u32 *push;
  1611. if (nv_rd32(device, 0x6100ac) & 0x00000100) {
  1612. nv_wr32(device, 0x6100ac, 0x00000100);
  1613. nv_mask(device, 0x6194e8, 0x00000001, 0x00000000);
  1614. if (!nv_wait(device, 0x6194e8, 0x00000002, 0x00000000)) {
  1615. NV_ERROR(drm, "PDISP: 0x6194e8 0x%08x\n",
  1616. nv_rd32(device, 0x6194e8));
  1617. return -EBUSY;
  1618. }
  1619. }
  1620. /* nfi what these are exactly, i do know that SOR_MODE_CTRL won't
  1621. * work at all unless you do the SOR part below.
  1622. */
  1623. for (i = 0; i < 3; i++) {
  1624. u32 dac = nv_rd32(device, 0x61a000 + (i * 0x800));
  1625. nv_wr32(device, 0x6101c0 + (i * 0x800), dac);
  1626. }
  1627. for (i = 0; i < 4; i++) {
  1628. u32 sor = nv_rd32(device, 0x61c000 + (i * 0x800));
  1629. nv_wr32(device, 0x6301c4 + (i * 0x800), sor);
  1630. }
  1631. for (i = 0; i < dev->mode_config.num_crtc; i++) {
  1632. u32 crtc0 = nv_rd32(device, 0x616104 + (i * 0x800));
  1633. u32 crtc1 = nv_rd32(device, 0x616108 + (i * 0x800));
  1634. u32 crtc2 = nv_rd32(device, 0x61610c + (i * 0x800));
  1635. nv_wr32(device, 0x6101b4 + (i * 0x800), crtc0);
  1636. nv_wr32(device, 0x6101b8 + (i * 0x800), crtc1);
  1637. nv_wr32(device, 0x6101bc + (i * 0x800), crtc2);
  1638. }
  1639. /* point at our hash table / objects, enable interrupts */
  1640. nv_wr32(device, 0x610010, (disp->mem->addr >> 8) | 9);
  1641. nv_mask(device, 0x6100b0, 0x00000307, 0x00000307);
  1642. /* init master */
  1643. ret = evo_init_dma(dev, EVO_MASTER);
  1644. if (ret)
  1645. goto error;
  1646. /* init flips + overlays + cursors */
  1647. for (i = 0; i < dev->mode_config.num_crtc; i++) {
  1648. if ((ret = evo_init_dma(dev, EVO_FLIP(i))) ||
  1649. (ret = evo_init_dma(dev, EVO_OVLY(i))) ||
  1650. (ret = evo_init_pio(dev, EVO_OIMM(i))) ||
  1651. (ret = evo_init_pio(dev, EVO_CURS(i))))
  1652. goto error;
  1653. }
  1654. push = evo_wait(dev, EVO_MASTER, 32);
  1655. if (!push) {
  1656. ret = -EBUSY;
  1657. goto error;
  1658. }
  1659. evo_mthd(push, 0x0088, 1);
  1660. evo_data(push, NvEvoSync);
  1661. evo_mthd(push, 0x0084, 1);
  1662. evo_data(push, 0x00000000);
  1663. evo_mthd(push, 0x0084, 1);
  1664. evo_data(push, 0x80000000);
  1665. evo_mthd(push, 0x008c, 1);
  1666. evo_data(push, 0x00000000);
  1667. evo_kick(push, dev, EVO_MASTER);
  1668. error:
  1669. if (ret)
  1670. nvd0_display_fini(dev);
  1671. return ret;
  1672. }
  1673. void
  1674. nvd0_display_destroy(struct drm_device *dev)
  1675. {
  1676. struct nvd0_display *disp = nvd0_display(dev);
  1677. struct pci_dev *pdev = dev->pdev;
  1678. int i;
  1679. for (i = 0; i < EVO_DMA_NR; i++) {
  1680. struct evo *evo = &disp->evo[i];
  1681. pci_free_consistent(pdev, PAGE_SIZE, evo->ptr, evo->handle);
  1682. }
  1683. nouveau_gpuobj_ref(NULL, &disp->mem);
  1684. nouveau_bo_unmap(disp->sync);
  1685. nouveau_bo_ref(NULL, &disp->sync);
  1686. nouveau_display(dev)->priv = NULL;
  1687. kfree(disp);
  1688. }
  1689. int
  1690. nvd0_display_create(struct drm_device *dev)
  1691. {
  1692. struct nouveau_device *device = nouveau_dev(dev);
  1693. struct nouveau_drm *drm = nouveau_drm(dev);
  1694. struct nouveau_bar *bar = nouveau_bar(device);
  1695. struct nouveau_fb *pfb = nouveau_fb(device);
  1696. struct dcb_table *dcb = &drm->vbios.dcb;
  1697. struct drm_connector *connector, *tmp;
  1698. struct pci_dev *pdev = dev->pdev;
  1699. struct nvd0_display *disp;
  1700. struct dcb_output *dcbe;
  1701. int crtcs, ret, i;
  1702. disp = kzalloc(sizeof(*disp), GFP_KERNEL);
  1703. if (!disp)
  1704. return -ENOMEM;
  1705. nouveau_display(dev)->priv = disp;
  1706. nouveau_display(dev)->dtor = nvd0_display_destroy;
  1707. nouveau_display(dev)->init = nvd0_display_init;
  1708. nouveau_display(dev)->fini = nvd0_display_fini;
  1709. /* create crtc objects to represent the hw heads */
  1710. crtcs = nv_rd32(device, 0x022448);
  1711. for (i = 0; i < crtcs; i++) {
  1712. ret = nvd0_crtc_create(dev, i);
  1713. if (ret)
  1714. goto out;
  1715. }
  1716. /* create encoder/connector objects based on VBIOS DCB table */
  1717. for (i = 0, dcbe = &dcb->entry[0]; i < dcb->entries; i++, dcbe++) {
  1718. connector = nouveau_connector_create(dev, dcbe->connector);
  1719. if (IS_ERR(connector))
  1720. continue;
  1721. if (dcbe->location != DCB_LOC_ON_CHIP) {
  1722. NV_WARN(drm, "skipping off-chip encoder %d/%d\n",
  1723. dcbe->type, ffs(dcbe->or) - 1);
  1724. continue;
  1725. }
  1726. switch (dcbe->type) {
  1727. case DCB_OUTPUT_TMDS:
  1728. case DCB_OUTPUT_LVDS:
  1729. case DCB_OUTPUT_DP:
  1730. nvd0_sor_create(connector, dcbe);
  1731. break;
  1732. case DCB_OUTPUT_ANALOG:
  1733. nvd0_dac_create(connector, dcbe);
  1734. break;
  1735. default:
  1736. NV_WARN(drm, "skipping unsupported encoder %d/%d\n",
  1737. dcbe->type, ffs(dcbe->or) - 1);
  1738. continue;
  1739. }
  1740. }
  1741. /* cull any connectors we created that don't have an encoder */
  1742. list_for_each_entry_safe(connector, tmp, &dev->mode_config.connector_list, head) {
  1743. if (connector->encoder_ids[0])
  1744. continue;
  1745. NV_WARN(drm, "%s has no encoders, removing\n",
  1746. drm_get_connector_name(connector));
  1747. connector->funcs->destroy(connector);
  1748. }
  1749. /* setup interrupt handling */
  1750. tasklet_init(&disp->tasklet, nvd0_display_bh, (unsigned long)dev);
  1751. /* small shared memory area we use for notifiers and semaphores */
  1752. ret = nouveau_bo_new(dev, 4096, 0x1000, TTM_PL_FLAG_VRAM,
  1753. 0, 0x0000, NULL, &disp->sync);
  1754. if (!ret) {
  1755. ret = nouveau_bo_pin(disp->sync, TTM_PL_FLAG_VRAM);
  1756. if (!ret)
  1757. ret = nouveau_bo_map(disp->sync);
  1758. if (ret)
  1759. nouveau_bo_ref(NULL, &disp->sync);
  1760. }
  1761. if (ret)
  1762. goto out;
  1763. /* hash table and dma objects for the memory areas we care about */
  1764. ret = nouveau_gpuobj_new(nv_object(device), NULL, 0x4000, 0x10000,
  1765. NVOBJ_FLAG_ZERO_ALLOC, &disp->mem);
  1766. if (ret)
  1767. goto out;
  1768. /* create evo dma channels */
  1769. for (i = 0; i < EVO_DMA_NR; i++) {
  1770. struct evo *evo = &disp->evo[i];
  1771. u64 offset = disp->sync->bo.offset;
  1772. u32 dmao = 0x1000 + (i * 0x100);
  1773. u32 hash = 0x0000 + (i * 0x040);
  1774. evo->idx = i;
  1775. evo->sem.offset = EVO_SYNC(evo->idx, 0x00);
  1776. evo->ptr = pci_alloc_consistent(pdev, PAGE_SIZE, &evo->handle);
  1777. if (!evo->ptr) {
  1778. ret = -ENOMEM;
  1779. goto out;
  1780. }
  1781. nv_wo32(disp->mem, dmao + 0x00, 0x00000049);
  1782. nv_wo32(disp->mem, dmao + 0x04, (offset + 0x0000) >> 8);
  1783. nv_wo32(disp->mem, dmao + 0x08, (offset + 0x0fff) >> 8);
  1784. nv_wo32(disp->mem, dmao + 0x0c, 0x00000000);
  1785. nv_wo32(disp->mem, dmao + 0x10, 0x00000000);
  1786. nv_wo32(disp->mem, dmao + 0x14, 0x00000000);
  1787. nv_wo32(disp->mem, hash + 0x00, NvEvoSync);
  1788. nv_wo32(disp->mem, hash + 0x04, 0x00000001 | (i << 27) |
  1789. ((dmao + 0x00) << 9));
  1790. nv_wo32(disp->mem, dmao + 0x20, 0x00000049);
  1791. nv_wo32(disp->mem, dmao + 0x24, 0x00000000);
  1792. nv_wo32(disp->mem, dmao + 0x28, (pfb->ram.size - 1) >> 8);
  1793. nv_wo32(disp->mem, dmao + 0x2c, 0x00000000);
  1794. nv_wo32(disp->mem, dmao + 0x30, 0x00000000);
  1795. nv_wo32(disp->mem, dmao + 0x34, 0x00000000);
  1796. nv_wo32(disp->mem, hash + 0x08, NvEvoVRAM);
  1797. nv_wo32(disp->mem, hash + 0x0c, 0x00000001 | (i << 27) |
  1798. ((dmao + 0x20) << 9));
  1799. nv_wo32(disp->mem, dmao + 0x40, 0x00000009);
  1800. nv_wo32(disp->mem, dmao + 0x44, 0x00000000);
  1801. nv_wo32(disp->mem, dmao + 0x48, (pfb->ram.size - 1) >> 8);
  1802. nv_wo32(disp->mem, dmao + 0x4c, 0x00000000);
  1803. nv_wo32(disp->mem, dmao + 0x50, 0x00000000);
  1804. nv_wo32(disp->mem, dmao + 0x54, 0x00000000);
  1805. nv_wo32(disp->mem, hash + 0x10, NvEvoVRAM_LP);
  1806. nv_wo32(disp->mem, hash + 0x14, 0x00000001 | (i << 27) |
  1807. ((dmao + 0x40) << 9));
  1808. nv_wo32(disp->mem, dmao + 0x60, 0x0fe00009);
  1809. nv_wo32(disp->mem, dmao + 0x64, 0x00000000);
  1810. nv_wo32(disp->mem, dmao + 0x68, (pfb->ram.size - 1) >> 8);
  1811. nv_wo32(disp->mem, dmao + 0x6c, 0x00000000);
  1812. nv_wo32(disp->mem, dmao + 0x70, 0x00000000);
  1813. nv_wo32(disp->mem, dmao + 0x74, 0x00000000);
  1814. nv_wo32(disp->mem, hash + 0x18, NvEvoFB32);
  1815. nv_wo32(disp->mem, hash + 0x1c, 0x00000001 | (i << 27) |
  1816. ((dmao + 0x60) << 9));
  1817. }
  1818. bar->flush(bar);
  1819. out:
  1820. if (ret)
  1821. nvd0_display_destroy(dev);
  1822. return ret;
  1823. }