nv50_display.c 61 KB

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