nv50_display.c 62 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297
  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/client.h>
  36. #include <core/gpuobj.h>
  37. #include <core/class.h>
  38. #include <subdev/timer.h>
  39. #include <subdev/bar.h>
  40. #include <subdev/fb.h>
  41. #include <subdev/i2c.h>
  42. #define EVO_DMA_NR 9
  43. #define EVO_MASTER (0x00)
  44. #define EVO_FLIP(c) (0x01 + (c))
  45. #define EVO_OVLY(c) (0x05 + (c))
  46. #define EVO_OIMM(c) (0x09 + (c))
  47. #define EVO_CURS(c) (0x0d + (c))
  48. /* offsets in shared sync bo of various structures */
  49. #define EVO_SYNC(c, o) ((c) * 0x0100 + (o))
  50. #define EVO_MAST_NTFY EVO_SYNC( 0, 0x00)
  51. #define EVO_FLIP_SEM0(c) EVO_SYNC((c) + 1, 0x00)
  52. #define EVO_FLIP_SEM1(c) EVO_SYNC((c) + 1, 0x10)
  53. #define EVO_CORE_HANDLE (0xd1500000)
  54. #define EVO_CHAN_HANDLE(t,i) (0xd15c0000 | (((t) & 0x00ff) << 8) | (i))
  55. #define EVO_CHAN_OCLASS(t,c) ((nv_hclass(c) & 0xff00) | ((t) & 0x00ff))
  56. #define EVO_PUSH_HANDLE(t,i) (0xd15b0000 | (i) | \
  57. (((NV50_DISP_##t##_CLASS) & 0x00ff) << 8))
  58. /******************************************************************************
  59. * EVO channel
  60. *****************************************************************************/
  61. struct nv50_chan {
  62. struct nouveau_object *user;
  63. u32 handle;
  64. };
  65. static int
  66. nv50_chan_create(struct nouveau_object *core, u32 bclass, u8 head,
  67. void *data, u32 size, struct nv50_chan *chan)
  68. {
  69. struct nouveau_object *client = nv_pclass(core, NV_CLIENT_CLASS);
  70. const u32 oclass = EVO_CHAN_OCLASS(bclass, core);
  71. const u32 handle = EVO_CHAN_HANDLE(bclass, head);
  72. int ret;
  73. ret = nouveau_object_new(client, EVO_CORE_HANDLE, handle,
  74. oclass, data, size, &chan->user);
  75. if (ret)
  76. return ret;
  77. chan->handle = handle;
  78. return 0;
  79. }
  80. static void
  81. nv50_chan_destroy(struct nouveau_object *core, struct nv50_chan *chan)
  82. {
  83. struct nouveau_object *client = nv_pclass(core, NV_CLIENT_CLASS);
  84. if (chan->handle)
  85. nouveau_object_del(client, EVO_CORE_HANDLE, chan->handle);
  86. }
  87. /******************************************************************************
  88. * PIO EVO channel
  89. *****************************************************************************/
  90. struct nv50_pioc {
  91. struct nv50_chan base;
  92. };
  93. static void
  94. nv50_pioc_destroy(struct nouveau_object *core, struct nv50_pioc *pioc)
  95. {
  96. nv50_chan_destroy(core, &pioc->base);
  97. }
  98. static int
  99. nv50_pioc_create(struct nouveau_object *core, u32 bclass, u8 head,
  100. void *data, u32 size, struct nv50_pioc *pioc)
  101. {
  102. return nv50_chan_create(core, bclass, head, data, size, &pioc->base);
  103. }
  104. /******************************************************************************
  105. * DMA EVO channel
  106. *****************************************************************************/
  107. struct nv50_dmac {
  108. struct nv50_chan base;
  109. dma_addr_t handle;
  110. u32 *ptr;
  111. /* Protects against concurrent pushbuf access to this channel, lock is
  112. * grabbed by evo_wait (if the pushbuf reservation is successful) and
  113. * dropped again by evo_kick. */
  114. struct mutex lock;
  115. };
  116. static void
  117. nv50_dmac_destroy(struct nouveau_object *core, struct nv50_dmac *dmac)
  118. {
  119. if (dmac->ptr) {
  120. struct pci_dev *pdev = nv_device(core)->pdev;
  121. pci_free_consistent(pdev, PAGE_SIZE, dmac->ptr, dmac->handle);
  122. }
  123. nv50_chan_destroy(core, &dmac->base);
  124. }
  125. static int
  126. nv50_dmac_create_fbdma(struct nouveau_object *core, u32 parent)
  127. {
  128. struct nouveau_fb *pfb = nouveau_fb(core);
  129. struct nouveau_object *client = nv_pclass(core, NV_CLIENT_CLASS);
  130. struct nouveau_object *object;
  131. int ret = nouveau_object_new(client, parent, NvEvoVRAM_LP,
  132. NV_DMA_IN_MEMORY_CLASS,
  133. &(struct nv_dma_class) {
  134. .flags = NV_DMA_TARGET_VRAM |
  135. NV_DMA_ACCESS_RDWR,
  136. .start = 0,
  137. .limit = pfb->ram.size - 1,
  138. .conf0 = NV50_DMA_CONF0_ENABLE |
  139. NV50_DMA_CONF0_PART_256,
  140. }, sizeof(struct nv_dma_class), &object);
  141. if (ret)
  142. return ret;
  143. ret = nouveau_object_new(client, parent, NvEvoFB16,
  144. NV_DMA_IN_MEMORY_CLASS,
  145. &(struct nv_dma_class) {
  146. .flags = NV_DMA_TARGET_VRAM |
  147. NV_DMA_ACCESS_RDWR,
  148. .start = 0,
  149. .limit = pfb->ram.size - 1,
  150. .conf0 = NV50_DMA_CONF0_ENABLE | 0x70 |
  151. NV50_DMA_CONF0_PART_256,
  152. }, sizeof(struct nv_dma_class), &object);
  153. if (ret)
  154. return ret;
  155. ret = nouveau_object_new(client, parent, NvEvoFB32,
  156. NV_DMA_IN_MEMORY_CLASS,
  157. &(struct nv_dma_class) {
  158. .flags = NV_DMA_TARGET_VRAM |
  159. NV_DMA_ACCESS_RDWR,
  160. .start = 0,
  161. .limit = pfb->ram.size - 1,
  162. .conf0 = NV50_DMA_CONF0_ENABLE | 0x7a |
  163. NV50_DMA_CONF0_PART_256,
  164. }, sizeof(struct nv_dma_class), &object);
  165. return ret;
  166. }
  167. static int
  168. nvc0_dmac_create_fbdma(struct nouveau_object *core, u32 parent)
  169. {
  170. struct nouveau_fb *pfb = nouveau_fb(core);
  171. struct nouveau_object *client = nv_pclass(core, NV_CLIENT_CLASS);
  172. struct nouveau_object *object;
  173. int ret = nouveau_object_new(client, parent, NvEvoVRAM_LP,
  174. NV_DMA_IN_MEMORY_CLASS,
  175. &(struct nv_dma_class) {
  176. .flags = NV_DMA_TARGET_VRAM |
  177. NV_DMA_ACCESS_RDWR,
  178. .start = 0,
  179. .limit = pfb->ram.size - 1,
  180. .conf0 = NVC0_DMA_CONF0_ENABLE,
  181. }, sizeof(struct nv_dma_class), &object);
  182. if (ret)
  183. return ret;
  184. ret = nouveau_object_new(client, parent, NvEvoFB16,
  185. NV_DMA_IN_MEMORY_CLASS,
  186. &(struct nv_dma_class) {
  187. .flags = NV_DMA_TARGET_VRAM |
  188. NV_DMA_ACCESS_RDWR,
  189. .start = 0,
  190. .limit = pfb->ram.size - 1,
  191. .conf0 = NVC0_DMA_CONF0_ENABLE | 0xfe,
  192. }, sizeof(struct nv_dma_class), &object);
  193. if (ret)
  194. return ret;
  195. ret = nouveau_object_new(client, parent, NvEvoFB32,
  196. NV_DMA_IN_MEMORY_CLASS,
  197. &(struct nv_dma_class) {
  198. .flags = NV_DMA_TARGET_VRAM |
  199. NV_DMA_ACCESS_RDWR,
  200. .start = 0,
  201. .limit = pfb->ram.size - 1,
  202. .conf0 = NVC0_DMA_CONF0_ENABLE | 0xfe,
  203. }, sizeof(struct nv_dma_class), &object);
  204. return ret;
  205. }
  206. static int
  207. nvd0_dmac_create_fbdma(struct nouveau_object *core, u32 parent)
  208. {
  209. struct nouveau_fb *pfb = nouveau_fb(core);
  210. struct nouveau_object *client = nv_pclass(core, NV_CLIENT_CLASS);
  211. struct nouveau_object *object;
  212. int ret = nouveau_object_new(client, parent, NvEvoVRAM_LP,
  213. NV_DMA_IN_MEMORY_CLASS,
  214. &(struct nv_dma_class) {
  215. .flags = NV_DMA_TARGET_VRAM |
  216. NV_DMA_ACCESS_RDWR,
  217. .start = 0,
  218. .limit = pfb->ram.size - 1,
  219. .conf0 = NVD0_DMA_CONF0_ENABLE |
  220. NVD0_DMA_CONF0_PAGE_LP,
  221. }, sizeof(struct nv_dma_class), &object);
  222. if (ret)
  223. return ret;
  224. ret = nouveau_object_new(client, parent, NvEvoFB32,
  225. NV_DMA_IN_MEMORY_CLASS,
  226. &(struct nv_dma_class) {
  227. .flags = NV_DMA_TARGET_VRAM |
  228. NV_DMA_ACCESS_RDWR,
  229. .start = 0,
  230. .limit = pfb->ram.size - 1,
  231. .conf0 = NVD0_DMA_CONF0_ENABLE | 0xfe |
  232. NVD0_DMA_CONF0_PAGE_LP,
  233. }, sizeof(struct nv_dma_class), &object);
  234. return ret;
  235. }
  236. static int
  237. nv50_dmac_create(struct nouveau_object *core, u32 bclass, u8 head,
  238. void *data, u32 size, u64 syncbuf,
  239. struct nv50_dmac *dmac)
  240. {
  241. struct nouveau_fb *pfb = nouveau_fb(core);
  242. struct nouveau_object *client = nv_pclass(core, NV_CLIENT_CLASS);
  243. struct nouveau_object *object;
  244. u32 pushbuf = *(u32 *)data;
  245. int ret;
  246. mutex_init(&dmac->lock);
  247. dmac->ptr = pci_alloc_consistent(nv_device(core)->pdev, PAGE_SIZE,
  248. &dmac->handle);
  249. if (!dmac->ptr)
  250. return -ENOMEM;
  251. ret = nouveau_object_new(client, NVDRM_DEVICE, pushbuf,
  252. NV_DMA_FROM_MEMORY_CLASS,
  253. &(struct nv_dma_class) {
  254. .flags = NV_DMA_TARGET_PCI_US |
  255. NV_DMA_ACCESS_RD,
  256. .start = dmac->handle + 0x0000,
  257. .limit = dmac->handle + 0x0fff,
  258. }, sizeof(struct nv_dma_class), &object);
  259. if (ret)
  260. return ret;
  261. ret = nv50_chan_create(core, bclass, head, data, size, &dmac->base);
  262. if (ret)
  263. return ret;
  264. ret = nouveau_object_new(client, dmac->base.handle, NvEvoSync,
  265. NV_DMA_IN_MEMORY_CLASS,
  266. &(struct nv_dma_class) {
  267. .flags = NV_DMA_TARGET_VRAM |
  268. NV_DMA_ACCESS_RDWR,
  269. .start = syncbuf + 0x0000,
  270. .limit = syncbuf + 0x0fff,
  271. }, sizeof(struct nv_dma_class), &object);
  272. if (ret)
  273. return ret;
  274. ret = nouveau_object_new(client, dmac->base.handle, NvEvoVRAM,
  275. NV_DMA_IN_MEMORY_CLASS,
  276. &(struct nv_dma_class) {
  277. .flags = NV_DMA_TARGET_VRAM |
  278. NV_DMA_ACCESS_RDWR,
  279. .start = 0,
  280. .limit = pfb->ram.size - 1,
  281. }, sizeof(struct nv_dma_class), &object);
  282. if (ret)
  283. return ret;
  284. if (nv_device(core)->card_type < NV_C0)
  285. ret = nv50_dmac_create_fbdma(core, dmac->base.handle);
  286. else
  287. if (nv_device(core)->card_type < NV_D0)
  288. ret = nvc0_dmac_create_fbdma(core, dmac->base.handle);
  289. else
  290. ret = nvd0_dmac_create_fbdma(core, dmac->base.handle);
  291. return ret;
  292. }
  293. struct nv50_mast {
  294. struct nv50_dmac base;
  295. };
  296. struct nv50_curs {
  297. struct nv50_pioc base;
  298. };
  299. struct nv50_sync {
  300. struct nv50_dmac base;
  301. u32 addr;
  302. u32 data;
  303. };
  304. struct nv50_ovly {
  305. struct nv50_dmac base;
  306. };
  307. struct nv50_oimm {
  308. struct nv50_pioc base;
  309. };
  310. struct nv50_head {
  311. struct nouveau_crtc base;
  312. struct nv50_curs curs;
  313. struct nv50_sync sync;
  314. struct nv50_ovly ovly;
  315. struct nv50_oimm oimm;
  316. };
  317. #define nv50_head(c) ((struct nv50_head *)nouveau_crtc(c))
  318. #define nv50_curs(c) (&nv50_head(c)->curs)
  319. #define nv50_sync(c) (&nv50_head(c)->sync)
  320. #define nv50_ovly(c) (&nv50_head(c)->ovly)
  321. #define nv50_oimm(c) (&nv50_head(c)->oimm)
  322. #define nv50_chan(c) (&(c)->base.base)
  323. #define nv50_vers(c) nv_mclass(nv50_chan(c)->user)
  324. struct nv50_disp {
  325. struct nouveau_object *core;
  326. struct nv50_mast mast;
  327. u32 modeset;
  328. struct nouveau_bo *sync;
  329. };
  330. static struct nv50_disp *
  331. nv50_disp(struct drm_device *dev)
  332. {
  333. return nouveau_display(dev)->priv;
  334. }
  335. #define nv50_mast(d) (&nv50_disp(d)->mast)
  336. static struct drm_crtc *
  337. nv50_display_crtc_get(struct drm_encoder *encoder)
  338. {
  339. return nouveau_encoder(encoder)->crtc;
  340. }
  341. /******************************************************************************
  342. * EVO channel helpers
  343. *****************************************************************************/
  344. static u32 *
  345. evo_wait(void *evoc, int nr)
  346. {
  347. struct nv50_dmac *dmac = evoc;
  348. u32 put = nv_ro32(dmac->base.user, 0x0000) / 4;
  349. mutex_lock(&dmac->lock);
  350. if (put + nr >= (PAGE_SIZE / 4) - 8) {
  351. dmac->ptr[put] = 0x20000000;
  352. nv_wo32(dmac->base.user, 0x0000, 0x00000000);
  353. if (!nv_wait(dmac->base.user, 0x0004, ~0, 0x00000000)) {
  354. mutex_unlock(&dmac->lock);
  355. NV_ERROR(dmac->base.user, "channel stalled\n");
  356. return NULL;
  357. }
  358. put = 0;
  359. }
  360. return dmac->ptr + put;
  361. }
  362. static void
  363. evo_kick(u32 *push, void *evoc)
  364. {
  365. struct nv50_dmac *dmac = evoc;
  366. nv_wo32(dmac->base.user, 0x0000, (push - dmac->ptr) << 2);
  367. mutex_unlock(&dmac->lock);
  368. }
  369. #define evo_mthd(p,m,s) *((p)++) = (((s) << 18) | (m))
  370. #define evo_data(p,d) *((p)++) = (d)
  371. static bool
  372. evo_sync_wait(void *data)
  373. {
  374. if (nouveau_bo_rd32(data, EVO_MAST_NTFY) != 0x00000000)
  375. return true;
  376. usleep_range(1, 2);
  377. return false;
  378. }
  379. static int
  380. evo_sync(struct drm_device *dev)
  381. {
  382. struct nouveau_device *device = nouveau_dev(dev);
  383. struct nv50_disp *disp = nv50_disp(dev);
  384. struct nv50_mast *mast = nv50_mast(dev);
  385. u32 *push = evo_wait(mast, 8);
  386. if (push) {
  387. nouveau_bo_wr32(disp->sync, EVO_MAST_NTFY, 0x00000000);
  388. evo_mthd(push, 0x0084, 1);
  389. evo_data(push, 0x80000000 | EVO_MAST_NTFY);
  390. evo_mthd(push, 0x0080, 2);
  391. evo_data(push, 0x00000000);
  392. evo_data(push, 0x00000000);
  393. evo_kick(push, mast);
  394. if (nv_wait_cb(device, evo_sync_wait, disp->sync))
  395. return 0;
  396. }
  397. return -EBUSY;
  398. }
  399. /******************************************************************************
  400. * Page flipping channel
  401. *****************************************************************************/
  402. struct nouveau_bo *
  403. nv50_display_crtc_sema(struct drm_device *dev, int crtc)
  404. {
  405. return nv50_disp(dev)->sync;
  406. }
  407. struct nv50_display_flip {
  408. struct nv50_disp *disp;
  409. struct nv50_sync *chan;
  410. };
  411. static bool
  412. nv50_display_flip_wait(void *data)
  413. {
  414. struct nv50_display_flip *flip = data;
  415. if (nouveau_bo_rd32(flip->disp->sync, flip->chan->addr / 4) ==
  416. flip->chan->data);
  417. return true;
  418. usleep_range(1, 2);
  419. return false;
  420. }
  421. void
  422. nv50_display_flip_stop(struct drm_crtc *crtc)
  423. {
  424. struct nouveau_device *device = nouveau_dev(crtc->dev);
  425. struct nv50_display_flip flip = {
  426. .disp = nv50_disp(crtc->dev),
  427. .chan = nv50_sync(crtc),
  428. };
  429. u32 *push;
  430. push = evo_wait(flip.chan, 8);
  431. if (push) {
  432. evo_mthd(push, 0x0084, 1);
  433. evo_data(push, 0x00000000);
  434. evo_mthd(push, 0x0094, 1);
  435. evo_data(push, 0x00000000);
  436. evo_mthd(push, 0x00c0, 1);
  437. evo_data(push, 0x00000000);
  438. evo_mthd(push, 0x0080, 1);
  439. evo_data(push, 0x00000000);
  440. evo_kick(push, flip.chan);
  441. }
  442. nv_wait_cb(device, nv50_display_flip_wait, &flip);
  443. }
  444. int
  445. nv50_display_flip_next(struct drm_crtc *crtc, struct drm_framebuffer *fb,
  446. struct nouveau_channel *chan, u32 swap_interval)
  447. {
  448. struct nouveau_framebuffer *nv_fb = nouveau_framebuffer(fb);
  449. struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc);
  450. struct nv50_sync *sync = nv50_sync(crtc);
  451. int head = nv_crtc->index, ret;
  452. u32 *push;
  453. swap_interval <<= 4;
  454. if (swap_interval == 0)
  455. swap_interval |= 0x100;
  456. if (chan == NULL)
  457. evo_sync(crtc->dev);
  458. push = evo_wait(sync, 128);
  459. if (unlikely(push == NULL))
  460. return -EBUSY;
  461. if (chan && nv_mclass(chan->object) < NV84_CHANNEL_IND_CLASS) {
  462. ret = RING_SPACE(chan, 8);
  463. if (ret)
  464. return ret;
  465. BEGIN_NV04(chan, 0, NV11_SUBCHAN_DMA_SEMAPHORE, 2);
  466. OUT_RING (chan, NvEvoSema0 + head);
  467. OUT_RING (chan, sync->addr ^ 0x10);
  468. BEGIN_NV04(chan, 0, NV11_SUBCHAN_SEMAPHORE_RELEASE, 1);
  469. OUT_RING (chan, sync->data + 1);
  470. BEGIN_NV04(chan, 0, NV11_SUBCHAN_SEMAPHORE_OFFSET, 2);
  471. OUT_RING (chan, sync->addr);
  472. OUT_RING (chan, sync->data);
  473. } else
  474. if (chan && nv_mclass(chan->object) < NVC0_CHANNEL_IND_CLASS) {
  475. u64 addr = nv84_fence_crtc(chan, head) + sync->addr;
  476. ret = RING_SPACE(chan, 12);
  477. if (ret)
  478. return ret;
  479. BEGIN_NV04(chan, 0, NV11_SUBCHAN_DMA_SEMAPHORE, 1);
  480. OUT_RING (chan, chan->vram);
  481. BEGIN_NV04(chan, 0, NV84_SUBCHAN_SEMAPHORE_ADDRESS_HIGH, 4);
  482. OUT_RING (chan, upper_32_bits(addr ^ 0x10));
  483. OUT_RING (chan, lower_32_bits(addr ^ 0x10));
  484. OUT_RING (chan, sync->data + 1);
  485. OUT_RING (chan, NV84_SUBCHAN_SEMAPHORE_TRIGGER_WRITE_LONG);
  486. BEGIN_NV04(chan, 0, NV84_SUBCHAN_SEMAPHORE_ADDRESS_HIGH, 4);
  487. OUT_RING (chan, upper_32_bits(addr));
  488. OUT_RING (chan, lower_32_bits(addr));
  489. OUT_RING (chan, sync->data);
  490. OUT_RING (chan, NV84_SUBCHAN_SEMAPHORE_TRIGGER_ACQUIRE_EQUAL);
  491. } else
  492. if (chan) {
  493. u64 addr = nv84_fence_crtc(chan, head) + sync->addr;
  494. ret = RING_SPACE(chan, 10);
  495. if (ret)
  496. return ret;
  497. BEGIN_NVC0(chan, 0, NV84_SUBCHAN_SEMAPHORE_ADDRESS_HIGH, 4);
  498. OUT_RING (chan, upper_32_bits(addr ^ 0x10));
  499. OUT_RING (chan, lower_32_bits(addr ^ 0x10));
  500. OUT_RING (chan, sync->data + 1);
  501. OUT_RING (chan, NV84_SUBCHAN_SEMAPHORE_TRIGGER_WRITE_LONG |
  502. NVC0_SUBCHAN_SEMAPHORE_TRIGGER_YIELD);
  503. BEGIN_NVC0(chan, 0, NV84_SUBCHAN_SEMAPHORE_ADDRESS_HIGH, 4);
  504. OUT_RING (chan, upper_32_bits(addr));
  505. OUT_RING (chan, lower_32_bits(addr));
  506. OUT_RING (chan, sync->data);
  507. OUT_RING (chan, NV84_SUBCHAN_SEMAPHORE_TRIGGER_ACQUIRE_EQUAL |
  508. NVC0_SUBCHAN_SEMAPHORE_TRIGGER_YIELD);
  509. }
  510. if (chan) {
  511. sync->addr ^= 0x10;
  512. sync->data++;
  513. FIRE_RING (chan);
  514. }
  515. /* queue the flip */
  516. evo_mthd(push, 0x0100, 1);
  517. evo_data(push, 0xfffe0000);
  518. evo_mthd(push, 0x0084, 1);
  519. evo_data(push, swap_interval);
  520. if (!(swap_interval & 0x00000100)) {
  521. evo_mthd(push, 0x00e0, 1);
  522. evo_data(push, 0x40000000);
  523. }
  524. evo_mthd(push, 0x0088, 4);
  525. evo_data(push, sync->addr);
  526. evo_data(push, sync->data++);
  527. evo_data(push, sync->data);
  528. evo_data(push, NvEvoSync);
  529. evo_mthd(push, 0x00a0, 2);
  530. evo_data(push, 0x00000000);
  531. evo_data(push, 0x00000000);
  532. evo_mthd(push, 0x00c0, 1);
  533. evo_data(push, nv_fb->r_dma);
  534. evo_mthd(push, 0x0110, 2);
  535. evo_data(push, 0x00000000);
  536. evo_data(push, 0x00000000);
  537. if (nv50_vers(sync) < NVD0_DISP_SYNC_CLASS) {
  538. evo_mthd(push, 0x0800, 5);
  539. evo_data(push, nv_fb->nvbo->bo.offset >> 8);
  540. evo_data(push, 0);
  541. evo_data(push, (fb->height << 16) | fb->width);
  542. evo_data(push, nv_fb->r_pitch);
  543. evo_data(push, nv_fb->r_format);
  544. } else {
  545. evo_mthd(push, 0x0400, 5);
  546. evo_data(push, nv_fb->nvbo->bo.offset >> 8);
  547. evo_data(push, 0);
  548. evo_data(push, (fb->height << 16) | fb->width);
  549. evo_data(push, nv_fb->r_pitch);
  550. evo_data(push, nv_fb->r_format);
  551. }
  552. evo_mthd(push, 0x0080, 1);
  553. evo_data(push, 0x00000000);
  554. evo_kick(push, sync);
  555. return 0;
  556. }
  557. /******************************************************************************
  558. * CRTC
  559. *****************************************************************************/
  560. static int
  561. nv50_crtc_set_dither(struct nouveau_crtc *nv_crtc, bool update)
  562. {
  563. struct nv50_mast *mast = nv50_mast(nv_crtc->base.dev);
  564. struct nouveau_connector *nv_connector;
  565. struct drm_connector *connector;
  566. u32 *push, mode = 0x00;
  567. nv_connector = nouveau_crtc_connector_get(nv_crtc);
  568. connector = &nv_connector->base;
  569. if (nv_connector->dithering_mode == DITHERING_MODE_AUTO) {
  570. if (nv_crtc->base.fb->depth > connector->display_info.bpc * 3)
  571. mode = DITHERING_MODE_DYNAMIC2X2;
  572. } else {
  573. mode = nv_connector->dithering_mode;
  574. }
  575. if (nv_connector->dithering_depth == DITHERING_DEPTH_AUTO) {
  576. if (connector->display_info.bpc >= 8)
  577. mode |= DITHERING_DEPTH_8BPC;
  578. } else {
  579. mode |= nv_connector->dithering_depth;
  580. }
  581. push = evo_wait(mast, 4);
  582. if (push) {
  583. if (nv50_vers(mast) < NVD0_DISP_MAST_CLASS) {
  584. evo_mthd(push, 0x08a0 + (nv_crtc->index * 0x0400), 1);
  585. evo_data(push, mode);
  586. } else
  587. if (nv50_vers(mast) < NVE0_DISP_MAST_CLASS) {
  588. evo_mthd(push, 0x0490 + (nv_crtc->index * 0x0300), 1);
  589. evo_data(push, mode);
  590. } else {
  591. evo_mthd(push, 0x04a0 + (nv_crtc->index * 0x0300), 1);
  592. evo_data(push, mode);
  593. }
  594. if (update) {
  595. evo_mthd(push, 0x0080, 1);
  596. evo_data(push, 0x00000000);
  597. }
  598. evo_kick(push, mast);
  599. }
  600. return 0;
  601. }
  602. static int
  603. nv50_crtc_set_scale(struct nouveau_crtc *nv_crtc, bool update)
  604. {
  605. struct nv50_mast *mast = nv50_mast(nv_crtc->base.dev);
  606. struct drm_display_mode *omode, *umode = &nv_crtc->base.mode;
  607. struct drm_crtc *crtc = &nv_crtc->base;
  608. struct nouveau_connector *nv_connector;
  609. int mode = DRM_MODE_SCALE_NONE;
  610. u32 oX, oY, *push;
  611. /* start off at the resolution we programmed the crtc for, this
  612. * effectively handles NONE/FULL scaling
  613. */
  614. nv_connector = nouveau_crtc_connector_get(nv_crtc);
  615. if (nv_connector && nv_connector->native_mode)
  616. mode = nv_connector->scaling_mode;
  617. if (mode != DRM_MODE_SCALE_NONE)
  618. omode = nv_connector->native_mode;
  619. else
  620. omode = umode;
  621. oX = omode->hdisplay;
  622. oY = omode->vdisplay;
  623. if (omode->flags & DRM_MODE_FLAG_DBLSCAN)
  624. oY *= 2;
  625. /* add overscan compensation if necessary, will keep the aspect
  626. * ratio the same as the backend mode unless overridden by the
  627. * user setting both hborder and vborder properties.
  628. */
  629. if (nv_connector && ( nv_connector->underscan == UNDERSCAN_ON ||
  630. (nv_connector->underscan == UNDERSCAN_AUTO &&
  631. nv_connector->edid &&
  632. drm_detect_hdmi_monitor(nv_connector->edid)))) {
  633. u32 bX = nv_connector->underscan_hborder;
  634. u32 bY = nv_connector->underscan_vborder;
  635. u32 aspect = (oY << 19) / oX;
  636. if (bX) {
  637. oX -= (bX * 2);
  638. if (bY) oY -= (bY * 2);
  639. else oY = ((oX * aspect) + (aspect / 2)) >> 19;
  640. } else {
  641. oX -= (oX >> 4) + 32;
  642. if (bY) oY -= (bY * 2);
  643. else oY = ((oX * aspect) + (aspect / 2)) >> 19;
  644. }
  645. }
  646. /* handle CENTER/ASPECT scaling, taking into account the areas
  647. * removed already for overscan compensation
  648. */
  649. switch (mode) {
  650. case DRM_MODE_SCALE_CENTER:
  651. oX = min((u32)umode->hdisplay, oX);
  652. oY = min((u32)umode->vdisplay, oY);
  653. /* fall-through */
  654. case DRM_MODE_SCALE_ASPECT:
  655. if (oY < oX) {
  656. u32 aspect = (umode->hdisplay << 19) / umode->vdisplay;
  657. oX = ((oY * aspect) + (aspect / 2)) >> 19;
  658. } else {
  659. u32 aspect = (umode->vdisplay << 19) / umode->hdisplay;
  660. oY = ((oX * aspect) + (aspect / 2)) >> 19;
  661. }
  662. break;
  663. default:
  664. break;
  665. }
  666. push = evo_wait(mast, 8);
  667. if (push) {
  668. if (nv50_vers(mast) < NVD0_DISP_MAST_CLASS) {
  669. /*XXX: SCALE_CTRL_ACTIVE??? */
  670. evo_mthd(push, 0x08d8 + (nv_crtc->index * 0x400), 2);
  671. evo_data(push, (oY << 16) | oX);
  672. evo_data(push, (oY << 16) | oX);
  673. evo_mthd(push, 0x08a4 + (nv_crtc->index * 0x400), 1);
  674. evo_data(push, 0x00000000);
  675. evo_mthd(push, 0x08c8 + (nv_crtc->index * 0x400), 1);
  676. evo_data(push, umode->vdisplay << 16 | umode->hdisplay);
  677. } else {
  678. evo_mthd(push, 0x04c0 + (nv_crtc->index * 0x300), 3);
  679. evo_data(push, (oY << 16) | oX);
  680. evo_data(push, (oY << 16) | oX);
  681. evo_data(push, (oY << 16) | oX);
  682. evo_mthd(push, 0x0494 + (nv_crtc->index * 0x300), 1);
  683. evo_data(push, 0x00000000);
  684. evo_mthd(push, 0x04b8 + (nv_crtc->index * 0x300), 1);
  685. evo_data(push, umode->vdisplay << 16 | umode->hdisplay);
  686. }
  687. evo_kick(push, mast);
  688. if (update) {
  689. nv50_display_flip_stop(crtc);
  690. nv50_display_flip_next(crtc, crtc->fb, NULL, 1);
  691. }
  692. }
  693. return 0;
  694. }
  695. static int
  696. nv50_crtc_set_color_vibrance(struct nouveau_crtc *nv_crtc, bool update)
  697. {
  698. struct nv50_mast *mast = nv50_mast(nv_crtc->base.dev);
  699. u32 *push, hue, vib;
  700. int adj;
  701. adj = (nv_crtc->color_vibrance > 0) ? 50 : 0;
  702. vib = ((nv_crtc->color_vibrance * 2047 + adj) / 100) & 0xfff;
  703. hue = ((nv_crtc->vibrant_hue * 2047) / 100) & 0xfff;
  704. push = evo_wait(mast, 16);
  705. if (push) {
  706. if (nv50_vers(mast) < NVD0_DISP_MAST_CLASS) {
  707. evo_mthd(push, 0x08a8 + (nv_crtc->index * 0x400), 1);
  708. evo_data(push, (hue << 20) | (vib << 8));
  709. } else {
  710. evo_mthd(push, 0x0498 + (nv_crtc->index * 0x300), 1);
  711. evo_data(push, (hue << 20) | (vib << 8));
  712. }
  713. if (update) {
  714. evo_mthd(push, 0x0080, 1);
  715. evo_data(push, 0x00000000);
  716. }
  717. evo_kick(push, mast);
  718. }
  719. return 0;
  720. }
  721. static int
  722. nv50_crtc_set_image(struct nouveau_crtc *nv_crtc, struct drm_framebuffer *fb,
  723. int x, int y, bool update)
  724. {
  725. struct nouveau_framebuffer *nvfb = nouveau_framebuffer(fb);
  726. struct nv50_mast *mast = nv50_mast(nv_crtc->base.dev);
  727. u32 *push;
  728. push = evo_wait(mast, 16);
  729. if (push) {
  730. if (nv50_vers(mast) < NVD0_DISP_MAST_CLASS) {
  731. evo_mthd(push, 0x0860 + (nv_crtc->index * 0x400), 1);
  732. evo_data(push, nvfb->nvbo->bo.offset >> 8);
  733. evo_mthd(push, 0x0868 + (nv_crtc->index * 0x400), 3);
  734. evo_data(push, (fb->height << 16) | fb->width);
  735. evo_data(push, nvfb->r_pitch);
  736. evo_data(push, nvfb->r_format);
  737. evo_mthd(push, 0x08c0 + (nv_crtc->index * 0x400), 1);
  738. evo_data(push, (y << 16) | x);
  739. if (nv50_vers(mast) > NV50_DISP_MAST_CLASS) {
  740. evo_mthd(push, 0x0874 + (nv_crtc->index * 0x400), 1);
  741. evo_data(push, nvfb->r_dma);
  742. }
  743. } else {
  744. evo_mthd(push, 0x0460 + (nv_crtc->index * 0x300), 1);
  745. evo_data(push, nvfb->nvbo->bo.offset >> 8);
  746. evo_mthd(push, 0x0468 + (nv_crtc->index * 0x300), 4);
  747. evo_data(push, (fb->height << 16) | fb->width);
  748. evo_data(push, nvfb->r_pitch);
  749. evo_data(push, nvfb->r_format);
  750. evo_data(push, nvfb->r_dma);
  751. evo_mthd(push, 0x04b0 + (nv_crtc->index * 0x300), 1);
  752. evo_data(push, (y << 16) | x);
  753. }
  754. if (update) {
  755. evo_mthd(push, 0x0080, 1);
  756. evo_data(push, 0x00000000);
  757. }
  758. evo_kick(push, mast);
  759. }
  760. nv_crtc->fb.tile_flags = nvfb->r_dma;
  761. return 0;
  762. }
  763. static void
  764. nv50_crtc_cursor_show(struct nouveau_crtc *nv_crtc)
  765. {
  766. struct nv50_mast *mast = nv50_mast(nv_crtc->base.dev);
  767. u32 *push = evo_wait(mast, 16);
  768. if (push) {
  769. if (nv50_vers(mast) < NV84_DISP_MAST_CLASS) {
  770. evo_mthd(push, 0x0880 + (nv_crtc->index * 0x400), 2);
  771. evo_data(push, 0x85000000);
  772. evo_data(push, nv_crtc->cursor.nvbo->bo.offset >> 8);
  773. } else
  774. if (nv50_vers(mast) < NVD0_DISP_MAST_CLASS) {
  775. evo_mthd(push, 0x0880 + (nv_crtc->index * 0x400), 2);
  776. evo_data(push, 0x85000000);
  777. evo_data(push, nv_crtc->cursor.nvbo->bo.offset >> 8);
  778. evo_mthd(push, 0x089c + (nv_crtc->index * 0x400), 1);
  779. evo_data(push, NvEvoVRAM);
  780. } else {
  781. evo_mthd(push, 0x0480 + (nv_crtc->index * 0x300), 2);
  782. evo_data(push, 0x85000000);
  783. evo_data(push, nv_crtc->cursor.nvbo->bo.offset >> 8);
  784. evo_mthd(push, 0x048c + (nv_crtc->index * 0x300), 1);
  785. evo_data(push, NvEvoVRAM);
  786. }
  787. evo_kick(push, mast);
  788. }
  789. }
  790. static void
  791. nv50_crtc_cursor_hide(struct nouveau_crtc *nv_crtc)
  792. {
  793. struct nv50_mast *mast = nv50_mast(nv_crtc->base.dev);
  794. u32 *push = evo_wait(mast, 16);
  795. if (push) {
  796. if (nv50_vers(mast) < NV84_DISP_MAST_CLASS) {
  797. evo_mthd(push, 0x0880 + (nv_crtc->index * 0x400), 1);
  798. evo_data(push, 0x05000000);
  799. } else
  800. if (nv50_vers(mast) < NVD0_DISP_MAST_CLASS) {
  801. evo_mthd(push, 0x0880 + (nv_crtc->index * 0x400), 1);
  802. evo_data(push, 0x05000000);
  803. evo_mthd(push, 0x089c + (nv_crtc->index * 0x400), 1);
  804. evo_data(push, 0x00000000);
  805. } else {
  806. evo_mthd(push, 0x0480 + (nv_crtc->index * 0x300), 1);
  807. evo_data(push, 0x05000000);
  808. evo_mthd(push, 0x048c + (nv_crtc->index * 0x300), 1);
  809. evo_data(push, 0x00000000);
  810. }
  811. evo_kick(push, mast);
  812. }
  813. }
  814. static void
  815. nv50_crtc_cursor_show_hide(struct nouveau_crtc *nv_crtc, bool show, bool update)
  816. {
  817. struct nv50_mast *mast = nv50_mast(nv_crtc->base.dev);
  818. if (show)
  819. nv50_crtc_cursor_show(nv_crtc);
  820. else
  821. nv50_crtc_cursor_hide(nv_crtc);
  822. if (update) {
  823. u32 *push = evo_wait(mast, 2);
  824. if (push) {
  825. evo_mthd(push, 0x0080, 1);
  826. evo_data(push, 0x00000000);
  827. evo_kick(push, mast);
  828. }
  829. }
  830. }
  831. static void
  832. nv50_crtc_dpms(struct drm_crtc *crtc, int mode)
  833. {
  834. }
  835. static void
  836. nv50_crtc_prepare(struct drm_crtc *crtc)
  837. {
  838. struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc);
  839. struct nv50_mast *mast = nv50_mast(crtc->dev);
  840. u32 *push;
  841. nv50_display_flip_stop(crtc);
  842. push = evo_wait(mast, 2);
  843. if (push) {
  844. if (nv50_vers(mast) < NV84_DISP_MAST_CLASS) {
  845. evo_mthd(push, 0x0874 + (nv_crtc->index * 0x400), 1);
  846. evo_data(push, 0x00000000);
  847. evo_mthd(push, 0x0840 + (nv_crtc->index * 0x400), 1);
  848. evo_data(push, 0x40000000);
  849. } else
  850. if (nv50_vers(mast) < NVD0_DISP_MAST_CLASS) {
  851. evo_mthd(push, 0x0874 + (nv_crtc->index * 0x400), 1);
  852. evo_data(push, 0x00000000);
  853. evo_mthd(push, 0x0840 + (nv_crtc->index * 0x400), 1);
  854. evo_data(push, 0x40000000);
  855. evo_mthd(push, 0x085c + (nv_crtc->index * 0x400), 1);
  856. evo_data(push, 0x00000000);
  857. } else {
  858. evo_mthd(push, 0x0474 + (nv_crtc->index * 0x300), 1);
  859. evo_data(push, 0x00000000);
  860. evo_mthd(push, 0x0440 + (nv_crtc->index * 0x300), 1);
  861. evo_data(push, 0x03000000);
  862. evo_mthd(push, 0x045c + (nv_crtc->index * 0x300), 1);
  863. evo_data(push, 0x00000000);
  864. }
  865. evo_kick(push, mast);
  866. }
  867. nv50_crtc_cursor_show_hide(nv_crtc, false, false);
  868. }
  869. static void
  870. nv50_crtc_commit(struct drm_crtc *crtc)
  871. {
  872. struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc);
  873. struct nv50_mast *mast = nv50_mast(crtc->dev);
  874. u32 *push;
  875. push = evo_wait(mast, 32);
  876. if (push) {
  877. if (nv50_vers(mast) < NV84_DISP_MAST_CLASS) {
  878. evo_mthd(push, 0x0874 + (nv_crtc->index * 0x400), 1);
  879. evo_data(push, NvEvoVRAM_LP);
  880. evo_mthd(push, 0x0840 + (nv_crtc->index * 0x400), 2);
  881. evo_data(push, 0xc0000000);
  882. evo_data(push, nv_crtc->lut.nvbo->bo.offset >> 8);
  883. } else
  884. if (nv50_vers(mast) < NVD0_DISP_MAST_CLASS) {
  885. evo_mthd(push, 0x0874 + (nv_crtc->index * 0x400), 1);
  886. evo_data(push, nv_crtc->fb.tile_flags);
  887. evo_mthd(push, 0x0840 + (nv_crtc->index * 0x400), 2);
  888. evo_data(push, 0xc0000000);
  889. evo_data(push, nv_crtc->lut.nvbo->bo.offset >> 8);
  890. evo_mthd(push, 0x085c + (nv_crtc->index * 0x400), 1);
  891. evo_data(push, NvEvoVRAM);
  892. } else {
  893. evo_mthd(push, 0x0474 + (nv_crtc->index * 0x300), 1);
  894. evo_data(push, nv_crtc->fb.tile_flags);
  895. evo_mthd(push, 0x0440 + (nv_crtc->index * 0x300), 4);
  896. evo_data(push, 0x83000000);
  897. evo_data(push, nv_crtc->lut.nvbo->bo.offset >> 8);
  898. evo_data(push, 0x00000000);
  899. evo_data(push, 0x00000000);
  900. evo_mthd(push, 0x045c + (nv_crtc->index * 0x300), 1);
  901. evo_data(push, NvEvoVRAM);
  902. evo_mthd(push, 0x0430 + (nv_crtc->index * 0x300), 1);
  903. evo_data(push, 0xffffff00);
  904. }
  905. evo_kick(push, mast);
  906. }
  907. nv50_crtc_cursor_show_hide(nv_crtc, nv_crtc->cursor.visible, true);
  908. nv50_display_flip_next(crtc, crtc->fb, NULL, 1);
  909. }
  910. static bool
  911. nv50_crtc_mode_fixup(struct drm_crtc *crtc, const struct drm_display_mode *mode,
  912. struct drm_display_mode *adjusted_mode)
  913. {
  914. return true;
  915. }
  916. static int
  917. nv50_crtc_swap_fbs(struct drm_crtc *crtc, struct drm_framebuffer *old_fb)
  918. {
  919. struct nouveau_framebuffer *nvfb = nouveau_framebuffer(crtc->fb);
  920. int ret;
  921. ret = nouveau_bo_pin(nvfb->nvbo, TTM_PL_FLAG_VRAM);
  922. if (ret)
  923. return ret;
  924. if (old_fb) {
  925. nvfb = nouveau_framebuffer(old_fb);
  926. nouveau_bo_unpin(nvfb->nvbo);
  927. }
  928. return 0;
  929. }
  930. static int
  931. nv50_crtc_mode_set(struct drm_crtc *crtc, struct drm_display_mode *umode,
  932. struct drm_display_mode *mode, int x, int y,
  933. struct drm_framebuffer *old_fb)
  934. {
  935. struct nv50_mast *mast = nv50_mast(crtc->dev);
  936. struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc);
  937. struct nouveau_connector *nv_connector;
  938. u32 ilace = (mode->flags & DRM_MODE_FLAG_INTERLACE) ? 2 : 1;
  939. u32 vscan = (mode->flags & DRM_MODE_FLAG_DBLSCAN) ? 2 : 1;
  940. u32 hactive, hsynce, hbackp, hfrontp, hblanke, hblanks;
  941. u32 vactive, vsynce, vbackp, vfrontp, vblanke, vblanks;
  942. u32 vblan2e = 0, vblan2s = 1;
  943. u32 *push;
  944. int ret;
  945. hactive = mode->htotal;
  946. hsynce = mode->hsync_end - mode->hsync_start - 1;
  947. hbackp = mode->htotal - mode->hsync_end;
  948. hblanke = hsynce + hbackp;
  949. hfrontp = mode->hsync_start - mode->hdisplay;
  950. hblanks = mode->htotal - hfrontp - 1;
  951. vactive = mode->vtotal * vscan / ilace;
  952. vsynce = ((mode->vsync_end - mode->vsync_start) * vscan / ilace) - 1;
  953. vbackp = (mode->vtotal - mode->vsync_end) * vscan / ilace;
  954. vblanke = vsynce + vbackp;
  955. vfrontp = (mode->vsync_start - mode->vdisplay) * vscan / ilace;
  956. vblanks = vactive - vfrontp - 1;
  957. if (mode->flags & DRM_MODE_FLAG_INTERLACE) {
  958. vblan2e = vactive + vsynce + vbackp;
  959. vblan2s = vblan2e + (mode->vdisplay * vscan / ilace);
  960. vactive = (vactive * 2) + 1;
  961. }
  962. ret = nv50_crtc_swap_fbs(crtc, old_fb);
  963. if (ret)
  964. return ret;
  965. push = evo_wait(mast, 64);
  966. if (push) {
  967. if (nv50_vers(mast) < NVD0_DISP_MAST_CLASS) {
  968. evo_mthd(push, 0x0804 + (nv_crtc->index * 0x400), 2);
  969. evo_data(push, 0x00800000 | mode->clock);
  970. evo_data(push, (ilace == 2) ? 2 : 0);
  971. evo_mthd(push, 0x0810 + (nv_crtc->index * 0x400), 6);
  972. evo_data(push, 0x00000000);
  973. evo_data(push, (vactive << 16) | hactive);
  974. evo_data(push, ( vsynce << 16) | hsynce);
  975. evo_data(push, (vblanke << 16) | hblanke);
  976. evo_data(push, (vblanks << 16) | hblanks);
  977. evo_data(push, (vblan2e << 16) | vblan2s);
  978. evo_mthd(push, 0x082c + (nv_crtc->index * 0x400), 1);
  979. evo_data(push, 0x00000000);
  980. evo_mthd(push, 0x0900 + (nv_crtc->index * 0x400), 2);
  981. evo_data(push, 0x00000311);
  982. evo_data(push, 0x00000100);
  983. } else {
  984. evo_mthd(push, 0x0410 + (nv_crtc->index * 0x300), 6);
  985. evo_data(push, 0x00000000);
  986. evo_data(push, (vactive << 16) | hactive);
  987. evo_data(push, ( vsynce << 16) | hsynce);
  988. evo_data(push, (vblanke << 16) | hblanke);
  989. evo_data(push, (vblanks << 16) | hblanks);
  990. evo_data(push, (vblan2e << 16) | vblan2s);
  991. evo_mthd(push, 0x042c + (nv_crtc->index * 0x300), 1);
  992. evo_data(push, 0x00000000); /* ??? */
  993. evo_mthd(push, 0x0450 + (nv_crtc->index * 0x300), 3);
  994. evo_data(push, mode->clock * 1000);
  995. evo_data(push, 0x00200000); /* ??? */
  996. evo_data(push, mode->clock * 1000);
  997. evo_mthd(push, 0x04d0 + (nv_crtc->index * 0x300), 2);
  998. evo_data(push, 0x00000311);
  999. evo_data(push, 0x00000100);
  1000. }
  1001. evo_kick(push, mast);
  1002. }
  1003. nv_connector = nouveau_crtc_connector_get(nv_crtc);
  1004. nv50_crtc_set_dither(nv_crtc, false);
  1005. nv50_crtc_set_scale(nv_crtc, false);
  1006. nv50_crtc_set_color_vibrance(nv_crtc, false);
  1007. nv50_crtc_set_image(nv_crtc, crtc->fb, x, y, false);
  1008. return 0;
  1009. }
  1010. static int
  1011. nv50_crtc_mode_set_base(struct drm_crtc *crtc, int x, int y,
  1012. struct drm_framebuffer *old_fb)
  1013. {
  1014. struct nouveau_drm *drm = nouveau_drm(crtc->dev);
  1015. struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc);
  1016. int ret;
  1017. if (!crtc->fb) {
  1018. NV_DEBUG(drm, "No FB bound\n");
  1019. return 0;
  1020. }
  1021. ret = nv50_crtc_swap_fbs(crtc, old_fb);
  1022. if (ret)
  1023. return ret;
  1024. nv50_display_flip_stop(crtc);
  1025. nv50_crtc_set_image(nv_crtc, crtc->fb, x, y, true);
  1026. nv50_display_flip_next(crtc, crtc->fb, NULL, 1);
  1027. return 0;
  1028. }
  1029. static int
  1030. nv50_crtc_mode_set_base_atomic(struct drm_crtc *crtc,
  1031. struct drm_framebuffer *fb, int x, int y,
  1032. enum mode_set_atomic state)
  1033. {
  1034. struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc);
  1035. nv50_display_flip_stop(crtc);
  1036. nv50_crtc_set_image(nv_crtc, fb, x, y, true);
  1037. return 0;
  1038. }
  1039. static void
  1040. nv50_crtc_lut_load(struct drm_crtc *crtc)
  1041. {
  1042. struct nv50_disp *disp = nv50_disp(crtc->dev);
  1043. struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc);
  1044. void __iomem *lut = nvbo_kmap_obj_iovirtual(nv_crtc->lut.nvbo);
  1045. int i;
  1046. for (i = 0; i < 256; i++) {
  1047. u16 r = nv_crtc->lut.r[i] >> 2;
  1048. u16 g = nv_crtc->lut.g[i] >> 2;
  1049. u16 b = nv_crtc->lut.b[i] >> 2;
  1050. if (nv_mclass(disp->core) < NVD0_DISP_CLASS) {
  1051. writew(r + 0x0000, lut + (i * 0x08) + 0);
  1052. writew(g + 0x0000, lut + (i * 0x08) + 2);
  1053. writew(b + 0x0000, lut + (i * 0x08) + 4);
  1054. } else {
  1055. writew(r + 0x6000, lut + (i * 0x20) + 0);
  1056. writew(g + 0x6000, lut + (i * 0x20) + 2);
  1057. writew(b + 0x6000, lut + (i * 0x20) + 4);
  1058. }
  1059. }
  1060. }
  1061. static int
  1062. nv50_crtc_cursor_set(struct drm_crtc *crtc, struct drm_file *file_priv,
  1063. uint32_t handle, uint32_t width, uint32_t height)
  1064. {
  1065. struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc);
  1066. struct drm_device *dev = crtc->dev;
  1067. struct drm_gem_object *gem;
  1068. struct nouveau_bo *nvbo;
  1069. bool visible = (handle != 0);
  1070. int i, ret = 0;
  1071. if (visible) {
  1072. if (width != 64 || height != 64)
  1073. return -EINVAL;
  1074. gem = drm_gem_object_lookup(dev, file_priv, handle);
  1075. if (unlikely(!gem))
  1076. return -ENOENT;
  1077. nvbo = nouveau_gem_object(gem);
  1078. ret = nouveau_bo_map(nvbo);
  1079. if (ret == 0) {
  1080. for (i = 0; i < 64 * 64; i++) {
  1081. u32 v = nouveau_bo_rd32(nvbo, i);
  1082. nouveau_bo_wr32(nv_crtc->cursor.nvbo, i, v);
  1083. }
  1084. nouveau_bo_unmap(nvbo);
  1085. }
  1086. drm_gem_object_unreference_unlocked(gem);
  1087. }
  1088. if (visible != nv_crtc->cursor.visible) {
  1089. nv50_crtc_cursor_show_hide(nv_crtc, visible, true);
  1090. nv_crtc->cursor.visible = visible;
  1091. }
  1092. return ret;
  1093. }
  1094. static int
  1095. nv50_crtc_cursor_move(struct drm_crtc *crtc, int x, int y)
  1096. {
  1097. struct nv50_curs *curs = nv50_curs(crtc);
  1098. struct nv50_chan *chan = nv50_chan(curs);
  1099. nv_wo32(chan->user, 0x0084, (y << 16) | (x & 0xffff));
  1100. nv_wo32(chan->user, 0x0080, 0x00000000);
  1101. return 0;
  1102. }
  1103. static void
  1104. nv50_crtc_gamma_set(struct drm_crtc *crtc, u16 *r, u16 *g, u16 *b,
  1105. uint32_t start, uint32_t size)
  1106. {
  1107. struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc);
  1108. u32 end = max(start + size, (u32)256);
  1109. u32 i;
  1110. for (i = start; i < end; i++) {
  1111. nv_crtc->lut.r[i] = r[i];
  1112. nv_crtc->lut.g[i] = g[i];
  1113. nv_crtc->lut.b[i] = b[i];
  1114. }
  1115. nv50_crtc_lut_load(crtc);
  1116. }
  1117. static void
  1118. nv50_crtc_destroy(struct drm_crtc *crtc)
  1119. {
  1120. struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc);
  1121. struct nv50_disp *disp = nv50_disp(crtc->dev);
  1122. struct nv50_head *head = nv50_head(crtc);
  1123. nv50_dmac_destroy(disp->core, &head->ovly.base);
  1124. nv50_pioc_destroy(disp->core, &head->oimm.base);
  1125. nv50_dmac_destroy(disp->core, &head->sync.base);
  1126. nv50_pioc_destroy(disp->core, &head->curs.base);
  1127. nouveau_bo_unmap(nv_crtc->cursor.nvbo);
  1128. if (nv_crtc->cursor.nvbo)
  1129. nouveau_bo_unpin(nv_crtc->cursor.nvbo);
  1130. nouveau_bo_ref(NULL, &nv_crtc->cursor.nvbo);
  1131. nouveau_bo_unmap(nv_crtc->lut.nvbo);
  1132. if (nv_crtc->lut.nvbo)
  1133. nouveau_bo_unpin(nv_crtc->lut.nvbo);
  1134. nouveau_bo_ref(NULL, &nv_crtc->lut.nvbo);
  1135. drm_crtc_cleanup(crtc);
  1136. kfree(crtc);
  1137. }
  1138. static const struct drm_crtc_helper_funcs nv50_crtc_hfunc = {
  1139. .dpms = nv50_crtc_dpms,
  1140. .prepare = nv50_crtc_prepare,
  1141. .commit = nv50_crtc_commit,
  1142. .mode_fixup = nv50_crtc_mode_fixup,
  1143. .mode_set = nv50_crtc_mode_set,
  1144. .mode_set_base = nv50_crtc_mode_set_base,
  1145. .mode_set_base_atomic = nv50_crtc_mode_set_base_atomic,
  1146. .load_lut = nv50_crtc_lut_load,
  1147. };
  1148. static const struct drm_crtc_funcs nv50_crtc_func = {
  1149. .cursor_set = nv50_crtc_cursor_set,
  1150. .cursor_move = nv50_crtc_cursor_move,
  1151. .gamma_set = nv50_crtc_gamma_set,
  1152. .set_config = drm_crtc_helper_set_config,
  1153. .destroy = nv50_crtc_destroy,
  1154. .page_flip = nouveau_crtc_page_flip,
  1155. };
  1156. static void
  1157. nv50_cursor_set_pos(struct nouveau_crtc *nv_crtc, int x, int y)
  1158. {
  1159. }
  1160. static void
  1161. nv50_cursor_set_offset(struct nouveau_crtc *nv_crtc, uint32_t offset)
  1162. {
  1163. }
  1164. static int
  1165. nv50_crtc_create(struct drm_device *dev, struct nouveau_object *core, int index)
  1166. {
  1167. struct nv50_disp *disp = nv50_disp(dev);
  1168. struct nv50_head *head;
  1169. struct drm_crtc *crtc;
  1170. int ret, i;
  1171. head = kzalloc(sizeof(*head), GFP_KERNEL);
  1172. if (!head)
  1173. return -ENOMEM;
  1174. head->base.index = index;
  1175. head->base.set_dither = nv50_crtc_set_dither;
  1176. head->base.set_scale = nv50_crtc_set_scale;
  1177. head->base.set_color_vibrance = nv50_crtc_set_color_vibrance;
  1178. head->base.color_vibrance = 50;
  1179. head->base.vibrant_hue = 0;
  1180. head->base.cursor.set_offset = nv50_cursor_set_offset;
  1181. head->base.cursor.set_pos = nv50_cursor_set_pos;
  1182. for (i = 0; i < 256; i++) {
  1183. head->base.lut.r[i] = i << 8;
  1184. head->base.lut.g[i] = i << 8;
  1185. head->base.lut.b[i] = i << 8;
  1186. }
  1187. crtc = &head->base.base;
  1188. drm_crtc_init(dev, crtc, &nv50_crtc_func);
  1189. drm_crtc_helper_add(crtc, &nv50_crtc_hfunc);
  1190. drm_mode_crtc_set_gamma_size(crtc, 256);
  1191. ret = nouveau_bo_new(dev, 8192, 0x100, TTM_PL_FLAG_VRAM,
  1192. 0, 0x0000, NULL, &head->base.lut.nvbo);
  1193. if (!ret) {
  1194. ret = nouveau_bo_pin(head->base.lut.nvbo, TTM_PL_FLAG_VRAM);
  1195. if (!ret) {
  1196. ret = nouveau_bo_map(head->base.lut.nvbo);
  1197. if (ret)
  1198. nouveau_bo_unpin(head->base.lut.nvbo);
  1199. }
  1200. if (ret)
  1201. nouveau_bo_ref(NULL, &head->base.lut.nvbo);
  1202. }
  1203. if (ret)
  1204. goto out;
  1205. nv50_crtc_lut_load(crtc);
  1206. /* allocate cursor resources */
  1207. ret = nv50_pioc_create(disp->core, NV50_DISP_CURS_CLASS, index,
  1208. &(struct nv50_display_curs_class) {
  1209. .head = index,
  1210. }, sizeof(struct nv50_display_curs_class),
  1211. &head->curs.base);
  1212. if (ret)
  1213. goto out;
  1214. ret = nouveau_bo_new(dev, 64 * 64 * 4, 0x100, TTM_PL_FLAG_VRAM,
  1215. 0, 0x0000, NULL, &head->base.cursor.nvbo);
  1216. if (!ret) {
  1217. ret = nouveau_bo_pin(head->base.cursor.nvbo, TTM_PL_FLAG_VRAM);
  1218. if (!ret) {
  1219. ret = nouveau_bo_map(head->base.cursor.nvbo);
  1220. if (ret)
  1221. nouveau_bo_unpin(head->base.lut.nvbo);
  1222. }
  1223. if (ret)
  1224. nouveau_bo_ref(NULL, &head->base.cursor.nvbo);
  1225. }
  1226. if (ret)
  1227. goto out;
  1228. /* allocate page flip / sync resources */
  1229. ret = nv50_dmac_create(disp->core, NV50_DISP_SYNC_CLASS, index,
  1230. &(struct nv50_display_sync_class) {
  1231. .pushbuf = EVO_PUSH_HANDLE(SYNC, index),
  1232. .head = index,
  1233. }, sizeof(struct nv50_display_sync_class),
  1234. disp->sync->bo.offset, &head->sync.base);
  1235. if (ret)
  1236. goto out;
  1237. head->sync.addr = EVO_FLIP_SEM0(index);
  1238. head->sync.data = 0x00000000;
  1239. /* allocate overlay resources */
  1240. ret = nv50_pioc_create(disp->core, NV50_DISP_OIMM_CLASS, index,
  1241. &(struct nv50_display_oimm_class) {
  1242. .head = index,
  1243. }, sizeof(struct nv50_display_oimm_class),
  1244. &head->oimm.base);
  1245. if (ret)
  1246. goto out;
  1247. ret = nv50_dmac_create(disp->core, NV50_DISP_OVLY_CLASS, index,
  1248. &(struct nv50_display_ovly_class) {
  1249. .pushbuf = EVO_PUSH_HANDLE(OVLY, index),
  1250. .head = index,
  1251. }, sizeof(struct nv50_display_ovly_class),
  1252. disp->sync->bo.offset, &head->ovly.base);
  1253. if (ret)
  1254. goto out;
  1255. out:
  1256. if (ret)
  1257. nv50_crtc_destroy(crtc);
  1258. return ret;
  1259. }
  1260. /******************************************************************************
  1261. * DAC
  1262. *****************************************************************************/
  1263. static void
  1264. nv50_dac_dpms(struct drm_encoder *encoder, int mode)
  1265. {
  1266. struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
  1267. struct nv50_disp *disp = nv50_disp(encoder->dev);
  1268. int or = nv_encoder->or;
  1269. u32 dpms_ctrl;
  1270. dpms_ctrl = 0x00000000;
  1271. if (mode == DRM_MODE_DPMS_STANDBY || mode == DRM_MODE_DPMS_OFF)
  1272. dpms_ctrl |= 0x00000001;
  1273. if (mode == DRM_MODE_DPMS_SUSPEND || mode == DRM_MODE_DPMS_OFF)
  1274. dpms_ctrl |= 0x00000004;
  1275. nv_call(disp->core, NV50_DISP_DAC_PWR + or, dpms_ctrl);
  1276. }
  1277. static bool
  1278. nv50_dac_mode_fixup(struct drm_encoder *encoder,
  1279. const struct drm_display_mode *mode,
  1280. struct drm_display_mode *adjusted_mode)
  1281. {
  1282. struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
  1283. struct nouveau_connector *nv_connector;
  1284. nv_connector = nouveau_encoder_connector_get(nv_encoder);
  1285. if (nv_connector && nv_connector->native_mode) {
  1286. if (nv_connector->scaling_mode != DRM_MODE_SCALE_NONE) {
  1287. int id = adjusted_mode->base.id;
  1288. *adjusted_mode = *nv_connector->native_mode;
  1289. adjusted_mode->base.id = id;
  1290. }
  1291. }
  1292. return true;
  1293. }
  1294. static void
  1295. nv50_dac_commit(struct drm_encoder *encoder)
  1296. {
  1297. }
  1298. static void
  1299. nv50_dac_mode_set(struct drm_encoder *encoder, struct drm_display_mode *mode,
  1300. struct drm_display_mode *adjusted_mode)
  1301. {
  1302. struct nv50_mast *mast = nv50_mast(encoder->dev);
  1303. struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
  1304. struct nouveau_crtc *nv_crtc = nouveau_crtc(encoder->crtc);
  1305. u32 *push;
  1306. nv50_dac_dpms(encoder, DRM_MODE_DPMS_ON);
  1307. push = evo_wait(mast, 8);
  1308. if (push) {
  1309. if (nv50_vers(mast) < NVD0_DISP_MAST_CLASS) {
  1310. u32 syncs = 0x00000000;
  1311. if (mode->flags & DRM_MODE_FLAG_NHSYNC)
  1312. syncs |= 0x00000001;
  1313. if (mode->flags & DRM_MODE_FLAG_NVSYNC)
  1314. syncs |= 0x00000002;
  1315. evo_mthd(push, 0x0400 + (nv_encoder->or * 0x080), 2);
  1316. evo_data(push, 1 << nv_crtc->index);
  1317. evo_data(push, syncs);
  1318. } else {
  1319. u32 magic = 0x31ec6000 | (nv_crtc->index << 25);
  1320. u32 syncs = 0x00000001;
  1321. if (mode->flags & DRM_MODE_FLAG_NHSYNC)
  1322. syncs |= 0x00000008;
  1323. if (mode->flags & DRM_MODE_FLAG_NVSYNC)
  1324. syncs |= 0x00000010;
  1325. if (mode->flags & DRM_MODE_FLAG_INTERLACE)
  1326. magic |= 0x00000001;
  1327. evo_mthd(push, 0x0404 + (nv_crtc->index * 0x300), 2);
  1328. evo_data(push, syncs);
  1329. evo_data(push, magic);
  1330. evo_mthd(push, 0x0180 + (nv_encoder->or * 0x020), 1);
  1331. evo_data(push, 1 << nv_crtc->index);
  1332. }
  1333. evo_kick(push, mast);
  1334. }
  1335. nv_encoder->crtc = encoder->crtc;
  1336. }
  1337. static void
  1338. nv50_dac_disconnect(struct drm_encoder *encoder)
  1339. {
  1340. struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
  1341. struct nv50_mast *mast = nv50_mast(encoder->dev);
  1342. const int or = nv_encoder->or;
  1343. u32 *push;
  1344. if (nv_encoder->crtc) {
  1345. nv50_crtc_prepare(nv_encoder->crtc);
  1346. push = evo_wait(mast, 4);
  1347. if (push) {
  1348. if (nv50_vers(mast) < NVD0_DISP_MAST_CLASS) {
  1349. evo_mthd(push, 0x0400 + (or * 0x080), 1);
  1350. evo_data(push, 0x00000000);
  1351. } else {
  1352. evo_mthd(push, 0x0180 + (or * 0x020), 1);
  1353. evo_data(push, 0x00000000);
  1354. }
  1355. evo_kick(push, mast);
  1356. }
  1357. }
  1358. nv_encoder->crtc = NULL;
  1359. }
  1360. static enum drm_connector_status
  1361. nv50_dac_detect(struct drm_encoder *encoder, struct drm_connector *connector)
  1362. {
  1363. struct nv50_disp *disp = nv50_disp(encoder->dev);
  1364. int ret, or = nouveau_encoder(encoder)->or;
  1365. u32 load = 0;
  1366. ret = nv_exec(disp->core, NV50_DISP_DAC_LOAD + or, &load, sizeof(load));
  1367. if (ret || load != 7)
  1368. return connector_status_disconnected;
  1369. return connector_status_connected;
  1370. }
  1371. static void
  1372. nv50_dac_destroy(struct drm_encoder *encoder)
  1373. {
  1374. drm_encoder_cleanup(encoder);
  1375. kfree(encoder);
  1376. }
  1377. static const struct drm_encoder_helper_funcs nv50_dac_hfunc = {
  1378. .dpms = nv50_dac_dpms,
  1379. .mode_fixup = nv50_dac_mode_fixup,
  1380. .prepare = nv50_dac_disconnect,
  1381. .commit = nv50_dac_commit,
  1382. .mode_set = nv50_dac_mode_set,
  1383. .disable = nv50_dac_disconnect,
  1384. .get_crtc = nv50_display_crtc_get,
  1385. .detect = nv50_dac_detect
  1386. };
  1387. static const struct drm_encoder_funcs nv50_dac_func = {
  1388. .destroy = nv50_dac_destroy,
  1389. };
  1390. static int
  1391. nv50_dac_create(struct drm_connector *connector, struct dcb_output *dcbe)
  1392. {
  1393. struct nouveau_drm *drm = nouveau_drm(connector->dev);
  1394. struct nouveau_i2c *i2c = nouveau_i2c(drm->device);
  1395. struct nouveau_encoder *nv_encoder;
  1396. struct drm_encoder *encoder;
  1397. int type = DRM_MODE_ENCODER_DAC;
  1398. nv_encoder = kzalloc(sizeof(*nv_encoder), GFP_KERNEL);
  1399. if (!nv_encoder)
  1400. return -ENOMEM;
  1401. nv_encoder->dcb = dcbe;
  1402. nv_encoder->or = ffs(dcbe->or) - 1;
  1403. nv_encoder->i2c = i2c->find(i2c, dcbe->i2c_index);
  1404. encoder = to_drm_encoder(nv_encoder);
  1405. encoder->possible_crtcs = dcbe->heads;
  1406. encoder->possible_clones = 0;
  1407. drm_encoder_init(connector->dev, encoder, &nv50_dac_func, type);
  1408. drm_encoder_helper_add(encoder, &nv50_dac_hfunc);
  1409. drm_mode_connector_attach_encoder(connector, encoder);
  1410. return 0;
  1411. }
  1412. /******************************************************************************
  1413. * Audio
  1414. *****************************************************************************/
  1415. static void
  1416. nv50_audio_mode_set(struct drm_encoder *encoder, struct drm_display_mode *mode)
  1417. {
  1418. struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
  1419. struct nouveau_connector *nv_connector;
  1420. struct nv50_disp *disp = nv50_disp(encoder->dev);
  1421. nv_connector = nouveau_encoder_connector_get(nv_encoder);
  1422. if (!drm_detect_monitor_audio(nv_connector->edid))
  1423. return;
  1424. drm_edid_to_eld(&nv_connector->base, nv_connector->edid);
  1425. nv_exec(disp->core, NVA3_DISP_SOR_HDA_ELD + nv_encoder->or,
  1426. nv_connector->base.eld,
  1427. nv_connector->base.eld[2] * 4);
  1428. }
  1429. static void
  1430. nv50_audio_disconnect(struct drm_encoder *encoder)
  1431. {
  1432. struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
  1433. struct nv50_disp *disp = nv50_disp(encoder->dev);
  1434. nv_exec(disp->core, NVA3_DISP_SOR_HDA_ELD + nv_encoder->or, NULL, 0);
  1435. }
  1436. /******************************************************************************
  1437. * HDMI
  1438. *****************************************************************************/
  1439. static void
  1440. nv50_hdmi_mode_set(struct drm_encoder *encoder, struct drm_display_mode *mode)
  1441. {
  1442. struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
  1443. struct nouveau_crtc *nv_crtc = nouveau_crtc(encoder->crtc);
  1444. struct nouveau_connector *nv_connector;
  1445. struct nv50_disp *disp = nv50_disp(encoder->dev);
  1446. const u32 moff = (nv_crtc->index << 3) | nv_encoder->or;
  1447. u32 rekey = 56; /* binary driver, and tegra constant */
  1448. u32 max_ac_packet;
  1449. nv_connector = nouveau_encoder_connector_get(nv_encoder);
  1450. if (!drm_detect_hdmi_monitor(nv_connector->edid))
  1451. return;
  1452. max_ac_packet = mode->htotal - mode->hdisplay;
  1453. max_ac_packet -= rekey;
  1454. max_ac_packet -= 18; /* constant from tegra */
  1455. max_ac_packet /= 32;
  1456. nv_call(disp->core, NV84_DISP_SOR_HDMI_PWR + moff,
  1457. NV84_DISP_SOR_HDMI_PWR_STATE_ON |
  1458. (max_ac_packet << 16) | rekey);
  1459. nv50_audio_mode_set(encoder, mode);
  1460. }
  1461. static void
  1462. nv50_hdmi_disconnect(struct drm_encoder *encoder)
  1463. {
  1464. struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
  1465. struct nouveau_crtc *nv_crtc = nouveau_crtc(nv_encoder->crtc);
  1466. struct nv50_disp *disp = nv50_disp(encoder->dev);
  1467. const u32 moff = (nv_crtc->index << 3) | nv_encoder->or;
  1468. nv50_audio_disconnect(encoder);
  1469. nv_call(disp->core, NV84_DISP_SOR_HDMI_PWR + moff, 0x00000000);
  1470. }
  1471. /******************************************************************************
  1472. * SOR
  1473. *****************************************************************************/
  1474. static void
  1475. nv50_sor_dpms(struct drm_encoder *encoder, int mode)
  1476. {
  1477. struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
  1478. struct drm_device *dev = encoder->dev;
  1479. struct nv50_disp *disp = nv50_disp(dev);
  1480. struct drm_encoder *partner;
  1481. int or = nv_encoder->or;
  1482. nv_encoder->last_dpms = mode;
  1483. list_for_each_entry(partner, &dev->mode_config.encoder_list, head) {
  1484. struct nouveau_encoder *nv_partner = nouveau_encoder(partner);
  1485. if (partner->encoder_type != DRM_MODE_ENCODER_TMDS)
  1486. continue;
  1487. if (nv_partner != nv_encoder &&
  1488. nv_partner->dcb->or == nv_encoder->dcb->or) {
  1489. if (nv_partner->last_dpms == DRM_MODE_DPMS_ON)
  1490. return;
  1491. break;
  1492. }
  1493. }
  1494. nv_call(disp->core, NV50_DISP_SOR_PWR + or, (mode == DRM_MODE_DPMS_ON));
  1495. }
  1496. static bool
  1497. nv50_sor_mode_fixup(struct drm_encoder *encoder,
  1498. const struct drm_display_mode *mode,
  1499. struct drm_display_mode *adjusted_mode)
  1500. {
  1501. struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
  1502. struct nouveau_connector *nv_connector;
  1503. nv_connector = nouveau_encoder_connector_get(nv_encoder);
  1504. if (nv_connector && nv_connector->native_mode) {
  1505. if (nv_connector->scaling_mode != DRM_MODE_SCALE_NONE) {
  1506. int id = adjusted_mode->base.id;
  1507. *adjusted_mode = *nv_connector->native_mode;
  1508. adjusted_mode->base.id = id;
  1509. }
  1510. }
  1511. return true;
  1512. }
  1513. static void
  1514. nv50_sor_disconnect(struct drm_encoder *encoder)
  1515. {
  1516. struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
  1517. struct nv50_mast *mast = nv50_mast(encoder->dev);
  1518. const int or = nv_encoder->or;
  1519. u32 *push;
  1520. if (nv_encoder->crtc) {
  1521. nv50_crtc_prepare(nv_encoder->crtc);
  1522. push = evo_wait(mast, 4);
  1523. if (push) {
  1524. if (nv50_vers(mast) < NVD0_DISP_MAST_CLASS) {
  1525. evo_mthd(push, 0x0600 + (or * 0x40), 1);
  1526. evo_data(push, 0x00000000);
  1527. } else {
  1528. evo_mthd(push, 0x0200 + (or * 0x20), 1);
  1529. evo_data(push, 0x00000000);
  1530. }
  1531. evo_kick(push, mast);
  1532. }
  1533. nv50_hdmi_disconnect(encoder);
  1534. }
  1535. nv_encoder->last_dpms = DRM_MODE_DPMS_OFF;
  1536. nv_encoder->crtc = NULL;
  1537. }
  1538. static void
  1539. nv50_sor_commit(struct drm_encoder *encoder)
  1540. {
  1541. }
  1542. static void
  1543. nv50_sor_mode_set(struct drm_encoder *encoder, struct drm_display_mode *umode,
  1544. struct drm_display_mode *mode)
  1545. {
  1546. struct nv50_disp *disp = nv50_disp(encoder->dev);
  1547. struct nv50_mast *mast = nv50_mast(encoder->dev);
  1548. struct drm_device *dev = encoder->dev;
  1549. struct nouveau_drm *drm = nouveau_drm(dev);
  1550. struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
  1551. struct nouveau_crtc *nv_crtc = nouveau_crtc(encoder->crtc);
  1552. struct nouveau_connector *nv_connector;
  1553. struct nvbios *bios = &drm->vbios;
  1554. u32 *push, lvds = 0;
  1555. u8 owner = 1 << nv_crtc->index;
  1556. u8 proto = 0xf;
  1557. u8 depth = 0x0;
  1558. nv_connector = nouveau_encoder_connector_get(nv_encoder);
  1559. switch (nv_encoder->dcb->type) {
  1560. case DCB_OUTPUT_TMDS:
  1561. if (nv_encoder->dcb->sorconf.link & 1) {
  1562. if (mode->clock < 165000)
  1563. proto = 0x1;
  1564. else
  1565. proto = 0x5;
  1566. } else {
  1567. proto = 0x2;
  1568. }
  1569. nv50_hdmi_mode_set(encoder, mode);
  1570. break;
  1571. case DCB_OUTPUT_LVDS:
  1572. proto = 0x0;
  1573. if (bios->fp_no_ddc) {
  1574. if (bios->fp.dual_link)
  1575. lvds |= 0x0100;
  1576. if (bios->fp.if_is_24bit)
  1577. lvds |= 0x0200;
  1578. } else {
  1579. if (nv_connector->type == DCB_CONNECTOR_LVDS_SPWG) {
  1580. if (((u8 *)nv_connector->edid)[121] == 2)
  1581. lvds |= 0x0100;
  1582. } else
  1583. if (mode->clock >= bios->fp.duallink_transition_clk) {
  1584. lvds |= 0x0100;
  1585. }
  1586. if (lvds & 0x0100) {
  1587. if (bios->fp.strapless_is_24bit & 2)
  1588. lvds |= 0x0200;
  1589. } else {
  1590. if (bios->fp.strapless_is_24bit & 1)
  1591. lvds |= 0x0200;
  1592. }
  1593. if (nv_connector->base.display_info.bpc == 8)
  1594. lvds |= 0x0200;
  1595. }
  1596. nv_call(disp->core, NV50_DISP_SOR_LVDS_SCRIPT + nv_encoder->or, lvds);
  1597. break;
  1598. case DCB_OUTPUT_DP:
  1599. if (nv_connector->base.display_info.bpc == 6) {
  1600. nv_encoder->dp.datarate = mode->clock * 18 / 8;
  1601. depth = 0x2;
  1602. } else
  1603. if (nv_connector->base.display_info.bpc == 8) {
  1604. nv_encoder->dp.datarate = mode->clock * 24 / 8;
  1605. depth = 0x5;
  1606. } else {
  1607. nv_encoder->dp.datarate = mode->clock * 30 / 8;
  1608. depth = 0x6;
  1609. }
  1610. if (nv_encoder->dcb->sorconf.link & 1)
  1611. proto = 0x8;
  1612. else
  1613. proto = 0x9;
  1614. break;
  1615. default:
  1616. BUG_ON(1);
  1617. break;
  1618. }
  1619. nv50_sor_dpms(encoder, DRM_MODE_DPMS_ON);
  1620. push = evo_wait(nv50_mast(dev), 8);
  1621. if (push) {
  1622. if (nv50_vers(mast) < NVD0_DISP_CLASS) {
  1623. u32 ctrl = (depth << 16) | (proto << 8) | owner;
  1624. if (mode->flags & DRM_MODE_FLAG_NHSYNC)
  1625. ctrl |= 0x00001000;
  1626. if (mode->flags & DRM_MODE_FLAG_NVSYNC)
  1627. ctrl |= 0x00002000;
  1628. evo_mthd(push, 0x0600 + (nv_encoder->or * 0x040), 1);
  1629. evo_data(push, ctrl);
  1630. } else {
  1631. u32 magic = 0x31ec6000 | (nv_crtc->index << 25);
  1632. u32 syncs = 0x00000001;
  1633. if (mode->flags & DRM_MODE_FLAG_NHSYNC)
  1634. syncs |= 0x00000008;
  1635. if (mode->flags & DRM_MODE_FLAG_NVSYNC)
  1636. syncs |= 0x00000010;
  1637. if (mode->flags & DRM_MODE_FLAG_INTERLACE)
  1638. magic |= 0x00000001;
  1639. evo_mthd(push, 0x0404 + (nv_crtc->index * 0x300), 2);
  1640. evo_data(push, syncs | (depth << 6));
  1641. evo_data(push, magic);
  1642. evo_mthd(push, 0x0200 + (nv_encoder->or * 0x020), 1);
  1643. evo_data(push, owner | (proto << 8));
  1644. }
  1645. evo_kick(push, mast);
  1646. }
  1647. nv_encoder->crtc = encoder->crtc;
  1648. }
  1649. static void
  1650. nv50_sor_destroy(struct drm_encoder *encoder)
  1651. {
  1652. drm_encoder_cleanup(encoder);
  1653. kfree(encoder);
  1654. }
  1655. static const struct drm_encoder_helper_funcs nv50_sor_hfunc = {
  1656. .dpms = nv50_sor_dpms,
  1657. .mode_fixup = nv50_sor_mode_fixup,
  1658. .prepare = nv50_sor_disconnect,
  1659. .commit = nv50_sor_commit,
  1660. .mode_set = nv50_sor_mode_set,
  1661. .disable = nv50_sor_disconnect,
  1662. .get_crtc = nv50_display_crtc_get,
  1663. };
  1664. static const struct drm_encoder_funcs nv50_sor_func = {
  1665. .destroy = nv50_sor_destroy,
  1666. };
  1667. static int
  1668. nv50_sor_create(struct drm_connector *connector, struct dcb_output *dcbe)
  1669. {
  1670. struct nouveau_drm *drm = nouveau_drm(connector->dev);
  1671. struct nouveau_i2c *i2c = nouveau_i2c(drm->device);
  1672. struct nouveau_encoder *nv_encoder;
  1673. struct drm_encoder *encoder;
  1674. int type;
  1675. switch (dcbe->type) {
  1676. case DCB_OUTPUT_LVDS: type = DRM_MODE_ENCODER_LVDS; break;
  1677. case DCB_OUTPUT_TMDS:
  1678. case DCB_OUTPUT_DP:
  1679. default:
  1680. type = DRM_MODE_ENCODER_TMDS;
  1681. break;
  1682. }
  1683. nv_encoder = kzalloc(sizeof(*nv_encoder), GFP_KERNEL);
  1684. if (!nv_encoder)
  1685. return -ENOMEM;
  1686. nv_encoder->dcb = dcbe;
  1687. nv_encoder->or = ffs(dcbe->or) - 1;
  1688. nv_encoder->i2c = i2c->find(i2c, dcbe->i2c_index);
  1689. nv_encoder->last_dpms = DRM_MODE_DPMS_OFF;
  1690. encoder = to_drm_encoder(nv_encoder);
  1691. encoder->possible_crtcs = dcbe->heads;
  1692. encoder->possible_clones = 0;
  1693. drm_encoder_init(connector->dev, encoder, &nv50_sor_func, type);
  1694. drm_encoder_helper_add(encoder, &nv50_sor_hfunc);
  1695. drm_mode_connector_attach_encoder(connector, encoder);
  1696. return 0;
  1697. }
  1698. /******************************************************************************
  1699. * PIOR
  1700. *****************************************************************************/
  1701. static void
  1702. nv50_pior_dpms(struct drm_encoder *encoder, int mode)
  1703. {
  1704. struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
  1705. struct nv50_disp *disp = nv50_disp(encoder->dev);
  1706. u32 mthd = (nv_encoder->dcb->type << 12) | nv_encoder->or;
  1707. u32 ctrl = (mode == DRM_MODE_DPMS_ON);
  1708. nv_call(disp->core, NV50_DISP_PIOR_PWR + mthd, ctrl);
  1709. }
  1710. static bool
  1711. nv50_pior_mode_fixup(struct drm_encoder *encoder,
  1712. const struct drm_display_mode *mode,
  1713. struct drm_display_mode *adjusted_mode)
  1714. {
  1715. struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
  1716. struct nouveau_connector *nv_connector;
  1717. nv_connector = nouveau_encoder_connector_get(nv_encoder);
  1718. if (nv_connector && nv_connector->native_mode) {
  1719. if (nv_connector->scaling_mode != DRM_MODE_SCALE_NONE) {
  1720. int id = adjusted_mode->base.id;
  1721. *adjusted_mode = *nv_connector->native_mode;
  1722. adjusted_mode->base.id = id;
  1723. }
  1724. }
  1725. adjusted_mode->clock *= 2;
  1726. return true;
  1727. }
  1728. static void
  1729. nv50_pior_commit(struct drm_encoder *encoder)
  1730. {
  1731. }
  1732. static void
  1733. nv50_pior_mode_set(struct drm_encoder *encoder, struct drm_display_mode *mode,
  1734. struct drm_display_mode *adjusted_mode)
  1735. {
  1736. struct nv50_mast *mast = nv50_mast(encoder->dev);
  1737. struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
  1738. struct nouveau_crtc *nv_crtc = nouveau_crtc(encoder->crtc);
  1739. struct nouveau_connector *nv_connector;
  1740. u8 owner = 1 << nv_crtc->index;
  1741. u8 proto, depth;
  1742. u32 *push;
  1743. nv_connector = nouveau_encoder_connector_get(nv_encoder);
  1744. switch (nv_connector->base.display_info.bpc) {
  1745. case 10: depth = 0x6; break;
  1746. case 8: depth = 0x5; break;
  1747. case 6: depth = 0x2; break;
  1748. default: depth = 0x0; break;
  1749. }
  1750. switch (nv_encoder->dcb->type) {
  1751. case DCB_OUTPUT_TMDS:
  1752. case DCB_OUTPUT_DP:
  1753. proto = 0x0;
  1754. break;
  1755. default:
  1756. BUG_ON(1);
  1757. break;
  1758. }
  1759. nv50_pior_dpms(encoder, DRM_MODE_DPMS_ON);
  1760. push = evo_wait(mast, 8);
  1761. if (push) {
  1762. if (nv50_vers(mast) < NVD0_DISP_MAST_CLASS) {
  1763. u32 ctrl = (depth << 16) | (proto << 8) | owner;
  1764. if (mode->flags & DRM_MODE_FLAG_NHSYNC)
  1765. ctrl |= 0x00001000;
  1766. if (mode->flags & DRM_MODE_FLAG_NVSYNC)
  1767. ctrl |= 0x00002000;
  1768. evo_mthd(push, 0x0700 + (nv_encoder->or * 0x040), 1);
  1769. evo_data(push, ctrl);
  1770. }
  1771. evo_kick(push, mast);
  1772. }
  1773. nv_encoder->crtc = encoder->crtc;
  1774. }
  1775. static void
  1776. nv50_pior_disconnect(struct drm_encoder *encoder)
  1777. {
  1778. struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
  1779. struct nv50_mast *mast = nv50_mast(encoder->dev);
  1780. const int or = nv_encoder->or;
  1781. u32 *push;
  1782. if (nv_encoder->crtc) {
  1783. nv50_crtc_prepare(nv_encoder->crtc);
  1784. push = evo_wait(mast, 4);
  1785. if (push) {
  1786. if (nv50_vers(mast) < NVD0_DISP_MAST_CLASS) {
  1787. evo_mthd(push, 0x0700 + (or * 0x040), 1);
  1788. evo_data(push, 0x00000000);
  1789. }
  1790. evo_kick(push, mast);
  1791. }
  1792. }
  1793. nv_encoder->crtc = NULL;
  1794. }
  1795. static void
  1796. nv50_pior_destroy(struct drm_encoder *encoder)
  1797. {
  1798. drm_encoder_cleanup(encoder);
  1799. kfree(encoder);
  1800. }
  1801. static const struct drm_encoder_helper_funcs nv50_pior_hfunc = {
  1802. .dpms = nv50_pior_dpms,
  1803. .mode_fixup = nv50_pior_mode_fixup,
  1804. .prepare = nv50_pior_disconnect,
  1805. .commit = nv50_pior_commit,
  1806. .mode_set = nv50_pior_mode_set,
  1807. .disable = nv50_pior_disconnect,
  1808. .get_crtc = nv50_display_crtc_get,
  1809. };
  1810. static const struct drm_encoder_funcs nv50_pior_func = {
  1811. .destroy = nv50_pior_destroy,
  1812. };
  1813. static int
  1814. nv50_pior_create(struct drm_connector *connector, struct dcb_output *dcbe)
  1815. {
  1816. struct nouveau_drm *drm = nouveau_drm(connector->dev);
  1817. struct nouveau_i2c *i2c = nouveau_i2c(drm->device);
  1818. struct nouveau_i2c_port *ddc = NULL;
  1819. struct nouveau_encoder *nv_encoder;
  1820. struct drm_encoder *encoder;
  1821. int type;
  1822. switch (dcbe->type) {
  1823. case DCB_OUTPUT_TMDS:
  1824. ddc = i2c->find_type(i2c, NV_I2C_TYPE_EXTDDC(dcbe->extdev));
  1825. type = DRM_MODE_ENCODER_TMDS;
  1826. break;
  1827. case DCB_OUTPUT_DP:
  1828. ddc = i2c->find_type(i2c, NV_I2C_TYPE_EXTAUX(dcbe->extdev));
  1829. type = DRM_MODE_ENCODER_TMDS;
  1830. break;
  1831. default:
  1832. return -ENODEV;
  1833. }
  1834. nv_encoder = kzalloc(sizeof(*nv_encoder), GFP_KERNEL);
  1835. if (!nv_encoder)
  1836. return -ENOMEM;
  1837. nv_encoder->dcb = dcbe;
  1838. nv_encoder->or = ffs(dcbe->or) - 1;
  1839. nv_encoder->i2c = ddc;
  1840. encoder = to_drm_encoder(nv_encoder);
  1841. encoder->possible_crtcs = dcbe->heads;
  1842. encoder->possible_clones = 0;
  1843. drm_encoder_init(connector->dev, encoder, &nv50_pior_func, type);
  1844. drm_encoder_helper_add(encoder, &nv50_pior_hfunc);
  1845. drm_mode_connector_attach_encoder(connector, encoder);
  1846. return 0;
  1847. }
  1848. /******************************************************************************
  1849. * Init
  1850. *****************************************************************************/
  1851. void
  1852. nv50_display_fini(struct drm_device *dev)
  1853. {
  1854. }
  1855. int
  1856. nv50_display_init(struct drm_device *dev)
  1857. {
  1858. struct nv50_disp *disp = nv50_disp(dev);
  1859. struct drm_crtc *crtc;
  1860. u32 *push;
  1861. push = evo_wait(nv50_mast(dev), 32);
  1862. if (!push)
  1863. return -EBUSY;
  1864. list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
  1865. struct nv50_sync *sync = nv50_sync(crtc);
  1866. nouveau_bo_wr32(disp->sync, sync->addr / 4, sync->data);
  1867. }
  1868. evo_mthd(push, 0x0088, 1);
  1869. evo_data(push, NvEvoSync);
  1870. evo_kick(push, nv50_mast(dev));
  1871. return 0;
  1872. }
  1873. void
  1874. nv50_display_destroy(struct drm_device *dev)
  1875. {
  1876. struct nv50_disp *disp = nv50_disp(dev);
  1877. nv50_dmac_destroy(disp->core, &disp->mast.base);
  1878. nouveau_bo_unmap(disp->sync);
  1879. if (disp->sync)
  1880. nouveau_bo_unpin(disp->sync);
  1881. nouveau_bo_ref(NULL, &disp->sync);
  1882. nouveau_display(dev)->priv = NULL;
  1883. kfree(disp);
  1884. }
  1885. int
  1886. nv50_display_create(struct drm_device *dev)
  1887. {
  1888. static const u16 oclass[] = {
  1889. NVE0_DISP_CLASS,
  1890. NVD0_DISP_CLASS,
  1891. NVA3_DISP_CLASS,
  1892. NV94_DISP_CLASS,
  1893. NVA0_DISP_CLASS,
  1894. NV84_DISP_CLASS,
  1895. NV50_DISP_CLASS,
  1896. };
  1897. struct nouveau_device *device = nouveau_dev(dev);
  1898. struct nouveau_drm *drm = nouveau_drm(dev);
  1899. struct dcb_table *dcb = &drm->vbios.dcb;
  1900. struct drm_connector *connector, *tmp;
  1901. struct nv50_disp *disp;
  1902. struct dcb_output *dcbe;
  1903. int crtcs, ret, i;
  1904. disp = kzalloc(sizeof(*disp), GFP_KERNEL);
  1905. if (!disp)
  1906. return -ENOMEM;
  1907. nouveau_display(dev)->priv = disp;
  1908. nouveau_display(dev)->dtor = nv50_display_destroy;
  1909. nouveau_display(dev)->init = nv50_display_init;
  1910. nouveau_display(dev)->fini = nv50_display_fini;
  1911. /* small shared memory area we use for notifiers and semaphores */
  1912. ret = nouveau_bo_new(dev, 4096, 0x1000, TTM_PL_FLAG_VRAM,
  1913. 0, 0x0000, NULL, &disp->sync);
  1914. if (!ret) {
  1915. ret = nouveau_bo_pin(disp->sync, TTM_PL_FLAG_VRAM);
  1916. if (!ret) {
  1917. ret = nouveau_bo_map(disp->sync);
  1918. if (ret)
  1919. nouveau_bo_unpin(disp->sync);
  1920. }
  1921. if (ret)
  1922. nouveau_bo_ref(NULL, &disp->sync);
  1923. }
  1924. if (ret)
  1925. goto out;
  1926. /* attempt to allocate a supported evo display class */
  1927. ret = -ENODEV;
  1928. for (i = 0; ret && i < ARRAY_SIZE(oclass); i++) {
  1929. ret = nouveau_object_new(nv_object(drm), NVDRM_DEVICE,
  1930. 0xd1500000, oclass[i], NULL, 0,
  1931. &disp->core);
  1932. }
  1933. if (ret)
  1934. goto out;
  1935. /* allocate master evo channel */
  1936. ret = nv50_dmac_create(disp->core, NV50_DISP_MAST_CLASS, 0,
  1937. &(struct nv50_display_mast_class) {
  1938. .pushbuf = EVO_PUSH_HANDLE(MAST, 0),
  1939. }, sizeof(struct nv50_display_mast_class),
  1940. disp->sync->bo.offset, &disp->mast.base);
  1941. if (ret)
  1942. goto out;
  1943. /* create crtc objects to represent the hw heads */
  1944. if (nv_mclass(disp->core) >= NVD0_DISP_CLASS)
  1945. crtcs = nv_rd32(device, 0x022448);
  1946. else
  1947. crtcs = 2;
  1948. for (i = 0; i < crtcs; i++) {
  1949. ret = nv50_crtc_create(dev, disp->core, i);
  1950. if (ret)
  1951. goto out;
  1952. }
  1953. /* create encoder/connector objects based on VBIOS DCB table */
  1954. for (i = 0, dcbe = &dcb->entry[0]; i < dcb->entries; i++, dcbe++) {
  1955. connector = nouveau_connector_create(dev, dcbe->connector);
  1956. if (IS_ERR(connector))
  1957. continue;
  1958. if (dcbe->location == DCB_LOC_ON_CHIP) {
  1959. switch (dcbe->type) {
  1960. case DCB_OUTPUT_TMDS:
  1961. case DCB_OUTPUT_LVDS:
  1962. case DCB_OUTPUT_DP:
  1963. ret = nv50_sor_create(connector, dcbe);
  1964. break;
  1965. case DCB_OUTPUT_ANALOG:
  1966. ret = nv50_dac_create(connector, dcbe);
  1967. break;
  1968. default:
  1969. ret = -ENODEV;
  1970. break;
  1971. }
  1972. } else {
  1973. ret = nv50_pior_create(connector, dcbe);
  1974. }
  1975. if (ret) {
  1976. NV_WARN(drm, "failed to create encoder %d/%d/%d: %d\n",
  1977. dcbe->location, dcbe->type,
  1978. ffs(dcbe->or) - 1, ret);
  1979. ret = 0;
  1980. }
  1981. }
  1982. /* cull any connectors we created that don't have an encoder */
  1983. list_for_each_entry_safe(connector, tmp, &dev->mode_config.connector_list, head) {
  1984. if (connector->encoder_ids[0])
  1985. continue;
  1986. NV_WARN(drm, "%s has no encoders, removing\n",
  1987. drm_get_connector_name(connector));
  1988. connector->funcs->destroy(connector);
  1989. }
  1990. out:
  1991. if (ret)
  1992. nv50_display_destroy(dev);
  1993. return ret;
  1994. }