disp.c 62 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351
  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 "disp.h"
  25. #include "atom.h"
  26. #include "core.h"
  27. #include "head.h"
  28. #include "wndw.h"
  29. #include <linux/dma-mapping.h>
  30. #include <linux/hdmi.h>
  31. #include <drm/drmP.h>
  32. #include <drm/drm_atomic_helper.h>
  33. #include <drm/drm_crtc_helper.h>
  34. #include <drm/drm_dp_helper.h>
  35. #include <drm/drm_fb_helper.h>
  36. #include <drm/drm_plane_helper.h>
  37. #include <drm/drm_scdc_helper.h>
  38. #include <drm/drm_edid.h>
  39. #include <nvif/class.h>
  40. #include <nvif/cl0002.h>
  41. #include <nvif/cl5070.h>
  42. #include <nvif/cl507d.h>
  43. #include <nvif/event.h>
  44. #include "nouveau_drv.h"
  45. #include "nouveau_dma.h"
  46. #include "nouveau_gem.h"
  47. #include "nouveau_connector.h"
  48. #include "nouveau_encoder.h"
  49. #include "nouveau_fence.h"
  50. #include "nouveau_fbcon.h"
  51. #include <subdev/bios/dp.h>
  52. /******************************************************************************
  53. * Atomic state
  54. *****************************************************************************/
  55. struct nv50_outp_atom {
  56. struct list_head head;
  57. struct drm_encoder *encoder;
  58. bool flush_disable;
  59. union nv50_outp_atom_mask {
  60. struct {
  61. bool ctrl:1;
  62. };
  63. u8 mask;
  64. } set, clr;
  65. };
  66. /******************************************************************************
  67. * EVO channel
  68. *****************************************************************************/
  69. static int
  70. nv50_chan_create(struct nvif_device *device, struct nvif_object *disp,
  71. const s32 *oclass, u8 head, void *data, u32 size,
  72. struct nv50_chan *chan)
  73. {
  74. struct nvif_sclass *sclass;
  75. int ret, i, n;
  76. chan->device = device;
  77. ret = n = nvif_object_sclass_get(disp, &sclass);
  78. if (ret < 0)
  79. return ret;
  80. while (oclass[0]) {
  81. for (i = 0; i < n; i++) {
  82. if (sclass[i].oclass == oclass[0]) {
  83. ret = nvif_object_init(disp, 0, oclass[0],
  84. data, size, &chan->user);
  85. if (ret == 0)
  86. nvif_object_map(&chan->user, NULL, 0);
  87. nvif_object_sclass_put(&sclass);
  88. return ret;
  89. }
  90. }
  91. oclass++;
  92. }
  93. nvif_object_sclass_put(&sclass);
  94. return -ENOSYS;
  95. }
  96. static void
  97. nv50_chan_destroy(struct nv50_chan *chan)
  98. {
  99. nvif_object_fini(&chan->user);
  100. }
  101. /******************************************************************************
  102. * DMA EVO channel
  103. *****************************************************************************/
  104. void
  105. nv50_dmac_destroy(struct nv50_dmac *dmac)
  106. {
  107. nvif_object_fini(&dmac->vram);
  108. nvif_object_fini(&dmac->sync);
  109. nv50_chan_destroy(&dmac->base);
  110. nvif_mem_fini(&dmac->push);
  111. }
  112. int
  113. nv50_dmac_create(struct nvif_device *device, struct nvif_object *disp,
  114. const s32 *oclass, u8 head, void *data, u32 size, u64 syncbuf,
  115. struct nv50_dmac *dmac)
  116. {
  117. struct nouveau_cli *cli = (void *)device->object.client;
  118. struct nv50_disp_core_channel_dma_v0 *args = data;
  119. u8 type = NVIF_MEM_COHERENT;
  120. int ret;
  121. mutex_init(&dmac->lock);
  122. /* Pascal added support for 47-bit physical addresses, but some
  123. * parts of EVO still only accept 40-bit PAs.
  124. *
  125. * To avoid issues on systems with large amounts of RAM, and on
  126. * systems where an IOMMU maps pages at a high address, we need
  127. * to allocate push buffers in VRAM instead.
  128. *
  129. * This appears to match NVIDIA's behaviour on Pascal.
  130. */
  131. if (device->info.family == NV_DEVICE_INFO_V0_PASCAL)
  132. type |= NVIF_MEM_VRAM;
  133. ret = nvif_mem_init_map(&cli->mmu, type, 0x1000, &dmac->push);
  134. if (ret)
  135. return ret;
  136. dmac->ptr = dmac->push.object.map.ptr;
  137. args->pushbuf = nvif_handle(&dmac->push.object);
  138. ret = nv50_chan_create(device, disp, oclass, head, data, size,
  139. &dmac->base);
  140. if (ret)
  141. return ret;
  142. if (!syncbuf)
  143. return 0;
  144. ret = nvif_object_init(&dmac->base.user, 0xf0000000, NV_DMA_IN_MEMORY,
  145. &(struct nv_dma_v0) {
  146. .target = NV_DMA_V0_TARGET_VRAM,
  147. .access = NV_DMA_V0_ACCESS_RDWR,
  148. .start = syncbuf + 0x0000,
  149. .limit = syncbuf + 0x0fff,
  150. }, sizeof(struct nv_dma_v0),
  151. &dmac->sync);
  152. if (ret)
  153. return ret;
  154. ret = nvif_object_init(&dmac->base.user, 0xf0000001, NV_DMA_IN_MEMORY,
  155. &(struct nv_dma_v0) {
  156. .target = NV_DMA_V0_TARGET_VRAM,
  157. .access = NV_DMA_V0_ACCESS_RDWR,
  158. .start = 0,
  159. .limit = device->info.ram_user - 1,
  160. }, sizeof(struct nv_dma_v0),
  161. &dmac->vram);
  162. if (ret)
  163. return ret;
  164. return ret;
  165. }
  166. /******************************************************************************
  167. * EVO channel helpers
  168. *****************************************************************************/
  169. static void
  170. evo_flush(struct nv50_dmac *dmac)
  171. {
  172. /* Push buffer fetches are not coherent with BAR1, we need to ensure
  173. * writes have been flushed right through to VRAM before writing PUT.
  174. */
  175. if (dmac->push.type & NVIF_MEM_VRAM) {
  176. struct nvif_device *device = dmac->base.device;
  177. nvif_wr32(&device->object, 0x070000, 0x00000001);
  178. nvif_msec(device, 2000,
  179. if (!(nvif_rd32(&device->object, 0x070000) & 0x00000002))
  180. break;
  181. );
  182. }
  183. }
  184. u32 *
  185. evo_wait(struct nv50_dmac *evoc, int nr)
  186. {
  187. struct nv50_dmac *dmac = evoc;
  188. struct nvif_device *device = dmac->base.device;
  189. u32 put = nvif_rd32(&dmac->base.user, 0x0000) / 4;
  190. mutex_lock(&dmac->lock);
  191. if (put + nr >= (PAGE_SIZE / 4) - 8) {
  192. dmac->ptr[put] = 0x20000000;
  193. evo_flush(dmac);
  194. nvif_wr32(&dmac->base.user, 0x0000, 0x00000000);
  195. if (nvif_msec(device, 2000,
  196. if (!nvif_rd32(&dmac->base.user, 0x0004))
  197. break;
  198. ) < 0) {
  199. mutex_unlock(&dmac->lock);
  200. pr_err("nouveau: evo channel stalled\n");
  201. return NULL;
  202. }
  203. put = 0;
  204. }
  205. return dmac->ptr + put;
  206. }
  207. void
  208. evo_kick(u32 *push, struct nv50_dmac *evoc)
  209. {
  210. struct nv50_dmac *dmac = evoc;
  211. evo_flush(dmac);
  212. nvif_wr32(&dmac->base.user, 0x0000, (push - dmac->ptr) << 2);
  213. mutex_unlock(&dmac->lock);
  214. }
  215. /******************************************************************************
  216. * Output path helpers
  217. *****************************************************************************/
  218. static void
  219. nv50_outp_release(struct nouveau_encoder *nv_encoder)
  220. {
  221. struct nv50_disp *disp = nv50_disp(nv_encoder->base.base.dev);
  222. struct {
  223. struct nv50_disp_mthd_v1 base;
  224. } args = {
  225. .base.version = 1,
  226. .base.method = NV50_DISP_MTHD_V1_RELEASE,
  227. .base.hasht = nv_encoder->dcb->hasht,
  228. .base.hashm = nv_encoder->dcb->hashm,
  229. };
  230. nvif_mthd(&disp->disp->object, 0, &args, sizeof(args));
  231. nv_encoder->or = -1;
  232. nv_encoder->link = 0;
  233. }
  234. static int
  235. nv50_outp_acquire(struct nouveau_encoder *nv_encoder)
  236. {
  237. struct nouveau_drm *drm = nouveau_drm(nv_encoder->base.base.dev);
  238. struct nv50_disp *disp = nv50_disp(drm->dev);
  239. struct {
  240. struct nv50_disp_mthd_v1 base;
  241. struct nv50_disp_acquire_v0 info;
  242. } args = {
  243. .base.version = 1,
  244. .base.method = NV50_DISP_MTHD_V1_ACQUIRE,
  245. .base.hasht = nv_encoder->dcb->hasht,
  246. .base.hashm = nv_encoder->dcb->hashm,
  247. };
  248. int ret;
  249. ret = nvif_mthd(&disp->disp->object, 0, &args, sizeof(args));
  250. if (ret) {
  251. NV_ERROR(drm, "error acquiring output path: %d\n", ret);
  252. return ret;
  253. }
  254. nv_encoder->or = args.info.or;
  255. nv_encoder->link = args.info.link;
  256. return 0;
  257. }
  258. static int
  259. nv50_outp_atomic_check_view(struct drm_encoder *encoder,
  260. struct drm_crtc_state *crtc_state,
  261. struct drm_connector_state *conn_state,
  262. struct drm_display_mode *native_mode)
  263. {
  264. struct drm_display_mode *adjusted_mode = &crtc_state->adjusted_mode;
  265. struct drm_display_mode *mode = &crtc_state->mode;
  266. struct drm_connector *connector = conn_state->connector;
  267. struct nouveau_conn_atom *asyc = nouveau_conn_atom(conn_state);
  268. struct nouveau_drm *drm = nouveau_drm(encoder->dev);
  269. NV_ATOMIC(drm, "%s atomic_check\n", encoder->name);
  270. asyc->scaler.full = false;
  271. if (!native_mode)
  272. return 0;
  273. if (asyc->scaler.mode == DRM_MODE_SCALE_NONE) {
  274. switch (connector->connector_type) {
  275. case DRM_MODE_CONNECTOR_LVDS:
  276. case DRM_MODE_CONNECTOR_eDP:
  277. /* Force use of scaler for non-EDID modes. */
  278. if (adjusted_mode->type & DRM_MODE_TYPE_DRIVER)
  279. break;
  280. mode = native_mode;
  281. asyc->scaler.full = true;
  282. break;
  283. default:
  284. break;
  285. }
  286. } else {
  287. mode = native_mode;
  288. }
  289. if (!drm_mode_equal(adjusted_mode, mode)) {
  290. drm_mode_copy(adjusted_mode, mode);
  291. crtc_state->mode_changed = true;
  292. }
  293. return 0;
  294. }
  295. static int
  296. nv50_outp_atomic_check(struct drm_encoder *encoder,
  297. struct drm_crtc_state *crtc_state,
  298. struct drm_connector_state *conn_state)
  299. {
  300. struct nouveau_connector *nv_connector =
  301. nouveau_connector(conn_state->connector);
  302. return nv50_outp_atomic_check_view(encoder, crtc_state, conn_state,
  303. nv_connector->native_mode);
  304. }
  305. /******************************************************************************
  306. * DAC
  307. *****************************************************************************/
  308. static void
  309. nv50_dac_disable(struct drm_encoder *encoder)
  310. {
  311. struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
  312. struct nv50_core *core = nv50_disp(encoder->dev)->core;
  313. if (nv_encoder->crtc)
  314. core->func->dac->ctrl(core, nv_encoder->or, 0x00000000, NULL);
  315. nv_encoder->crtc = NULL;
  316. nv50_outp_release(nv_encoder);
  317. }
  318. static void
  319. nv50_dac_enable(struct drm_encoder *encoder)
  320. {
  321. struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
  322. struct nouveau_crtc *nv_crtc = nouveau_crtc(encoder->crtc);
  323. struct nv50_head_atom *asyh = nv50_head_atom(nv_crtc->base.state);
  324. struct nv50_core *core = nv50_disp(encoder->dev)->core;
  325. nv50_outp_acquire(nv_encoder);
  326. core->func->dac->ctrl(core, nv_encoder->or, 1 << nv_crtc->index, asyh);
  327. asyh->or.depth = 0;
  328. nv_encoder->crtc = encoder->crtc;
  329. }
  330. static enum drm_connector_status
  331. nv50_dac_detect(struct drm_encoder *encoder, struct drm_connector *connector)
  332. {
  333. struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
  334. struct nv50_disp *disp = nv50_disp(encoder->dev);
  335. struct {
  336. struct nv50_disp_mthd_v1 base;
  337. struct nv50_disp_dac_load_v0 load;
  338. } args = {
  339. .base.version = 1,
  340. .base.method = NV50_DISP_MTHD_V1_DAC_LOAD,
  341. .base.hasht = nv_encoder->dcb->hasht,
  342. .base.hashm = nv_encoder->dcb->hashm,
  343. };
  344. int ret;
  345. args.load.data = nouveau_drm(encoder->dev)->vbios.dactestval;
  346. if (args.load.data == 0)
  347. args.load.data = 340;
  348. ret = nvif_mthd(&disp->disp->object, 0, &args, sizeof(args));
  349. if (ret || !args.load.load)
  350. return connector_status_disconnected;
  351. return connector_status_connected;
  352. }
  353. static const struct drm_encoder_helper_funcs
  354. nv50_dac_help = {
  355. .atomic_check = nv50_outp_atomic_check,
  356. .enable = nv50_dac_enable,
  357. .disable = nv50_dac_disable,
  358. .detect = nv50_dac_detect
  359. };
  360. static void
  361. nv50_dac_destroy(struct drm_encoder *encoder)
  362. {
  363. drm_encoder_cleanup(encoder);
  364. kfree(encoder);
  365. }
  366. static const struct drm_encoder_funcs
  367. nv50_dac_func = {
  368. .destroy = nv50_dac_destroy,
  369. };
  370. static int
  371. nv50_dac_create(struct drm_connector *connector, struct dcb_output *dcbe)
  372. {
  373. struct nouveau_drm *drm = nouveau_drm(connector->dev);
  374. struct nvkm_i2c *i2c = nvxx_i2c(&drm->client.device);
  375. struct nvkm_i2c_bus *bus;
  376. struct nouveau_encoder *nv_encoder;
  377. struct drm_encoder *encoder;
  378. int type = DRM_MODE_ENCODER_DAC;
  379. nv_encoder = kzalloc(sizeof(*nv_encoder), GFP_KERNEL);
  380. if (!nv_encoder)
  381. return -ENOMEM;
  382. nv_encoder->dcb = dcbe;
  383. bus = nvkm_i2c_bus_find(i2c, dcbe->i2c_index);
  384. if (bus)
  385. nv_encoder->i2c = &bus->i2c;
  386. encoder = to_drm_encoder(nv_encoder);
  387. encoder->possible_crtcs = dcbe->heads;
  388. encoder->possible_clones = 0;
  389. drm_encoder_init(connector->dev, encoder, &nv50_dac_func, type,
  390. "dac-%04x-%04x", dcbe->hasht, dcbe->hashm);
  391. drm_encoder_helper_add(encoder, &nv50_dac_help);
  392. drm_connector_attach_encoder(connector, encoder);
  393. return 0;
  394. }
  395. /******************************************************************************
  396. * Audio
  397. *****************************************************************************/
  398. static void
  399. nv50_audio_disable(struct drm_encoder *encoder, struct nouveau_crtc *nv_crtc)
  400. {
  401. struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
  402. struct nv50_disp *disp = nv50_disp(encoder->dev);
  403. struct {
  404. struct nv50_disp_mthd_v1 base;
  405. struct nv50_disp_sor_hda_eld_v0 eld;
  406. } args = {
  407. .base.version = 1,
  408. .base.method = NV50_DISP_MTHD_V1_SOR_HDA_ELD,
  409. .base.hasht = nv_encoder->dcb->hasht,
  410. .base.hashm = (0xf0ff & nv_encoder->dcb->hashm) |
  411. (0x0100 << nv_crtc->index),
  412. };
  413. nvif_mthd(&disp->disp->object, 0, &args, sizeof(args));
  414. }
  415. static void
  416. nv50_audio_enable(struct drm_encoder *encoder, struct drm_display_mode *mode)
  417. {
  418. struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
  419. struct nouveau_crtc *nv_crtc = nouveau_crtc(encoder->crtc);
  420. struct nouveau_connector *nv_connector;
  421. struct nv50_disp *disp = nv50_disp(encoder->dev);
  422. struct __packed {
  423. struct {
  424. struct nv50_disp_mthd_v1 mthd;
  425. struct nv50_disp_sor_hda_eld_v0 eld;
  426. } base;
  427. u8 data[sizeof(nv_connector->base.eld)];
  428. } args = {
  429. .base.mthd.version = 1,
  430. .base.mthd.method = NV50_DISP_MTHD_V1_SOR_HDA_ELD,
  431. .base.mthd.hasht = nv_encoder->dcb->hasht,
  432. .base.mthd.hashm = (0xf0ff & nv_encoder->dcb->hashm) |
  433. (0x0100 << nv_crtc->index),
  434. };
  435. nv_connector = nouveau_encoder_connector_get(nv_encoder);
  436. if (!drm_detect_monitor_audio(nv_connector->edid))
  437. return;
  438. memcpy(args.data, nv_connector->base.eld, sizeof(args.data));
  439. nvif_mthd(&disp->disp->object, 0, &args,
  440. sizeof(args.base) + drm_eld_size(args.data));
  441. }
  442. /******************************************************************************
  443. * HDMI
  444. *****************************************************************************/
  445. static void
  446. nv50_hdmi_disable(struct drm_encoder *encoder, struct nouveau_crtc *nv_crtc)
  447. {
  448. struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
  449. struct nv50_disp *disp = nv50_disp(encoder->dev);
  450. struct {
  451. struct nv50_disp_mthd_v1 base;
  452. struct nv50_disp_sor_hdmi_pwr_v0 pwr;
  453. } args = {
  454. .base.version = 1,
  455. .base.method = NV50_DISP_MTHD_V1_SOR_HDMI_PWR,
  456. .base.hasht = nv_encoder->dcb->hasht,
  457. .base.hashm = (0xf0ff & nv_encoder->dcb->hashm) |
  458. (0x0100 << nv_crtc->index),
  459. };
  460. nvif_mthd(&disp->disp->object, 0, &args, sizeof(args));
  461. }
  462. static void
  463. nv50_hdmi_enable(struct drm_encoder *encoder, struct drm_display_mode *mode)
  464. {
  465. struct nouveau_drm *drm = nouveau_drm(encoder->dev);
  466. struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
  467. struct nouveau_crtc *nv_crtc = nouveau_crtc(encoder->crtc);
  468. struct nv50_disp *disp = nv50_disp(encoder->dev);
  469. struct {
  470. struct nv50_disp_mthd_v1 base;
  471. struct nv50_disp_sor_hdmi_pwr_v0 pwr;
  472. u8 infoframes[2 * 17]; /* two frames, up to 17 bytes each */
  473. } args = {
  474. .base.version = 1,
  475. .base.method = NV50_DISP_MTHD_V1_SOR_HDMI_PWR,
  476. .base.hasht = nv_encoder->dcb->hasht,
  477. .base.hashm = (0xf0ff & nv_encoder->dcb->hashm) |
  478. (0x0100 << nv_crtc->index),
  479. .pwr.state = 1,
  480. .pwr.rekey = 56, /* binary driver, and tegra, constant */
  481. };
  482. struct nouveau_connector *nv_connector;
  483. struct drm_hdmi_info *hdmi;
  484. u32 max_ac_packet;
  485. union hdmi_infoframe avi_frame;
  486. union hdmi_infoframe vendor_frame;
  487. bool scdc_supported, high_tmds_clock_ratio = false, scrambling = false;
  488. u8 config;
  489. int ret;
  490. int size;
  491. nv_connector = nouveau_encoder_connector_get(nv_encoder);
  492. if (!drm_detect_hdmi_monitor(nv_connector->edid))
  493. return;
  494. hdmi = &nv_connector->base.display_info.hdmi;
  495. scdc_supported = hdmi->scdc.supported;
  496. ret = drm_hdmi_avi_infoframe_from_display_mode(&avi_frame.avi, mode,
  497. scdc_supported);
  498. if (!ret) {
  499. /* We have an AVI InfoFrame, populate it to the display */
  500. args.pwr.avi_infoframe_length
  501. = hdmi_infoframe_pack(&avi_frame, args.infoframes, 17);
  502. }
  503. ret = drm_hdmi_vendor_infoframe_from_display_mode(&vendor_frame.vendor.hdmi,
  504. &nv_connector->base, mode);
  505. if (!ret) {
  506. /* We have a Vendor InfoFrame, populate it to the display */
  507. args.pwr.vendor_infoframe_length
  508. = hdmi_infoframe_pack(&vendor_frame,
  509. args.infoframes
  510. + args.pwr.avi_infoframe_length,
  511. 17);
  512. }
  513. max_ac_packet = mode->htotal - mode->hdisplay;
  514. max_ac_packet -= args.pwr.rekey;
  515. max_ac_packet -= 18; /* constant from tegra */
  516. args.pwr.max_ac_packet = max_ac_packet / 32;
  517. if (hdmi->scdc.scrambling.supported) {
  518. high_tmds_clock_ratio = mode->clock > 340000;
  519. scrambling = high_tmds_clock_ratio ||
  520. hdmi->scdc.scrambling.low_rates;
  521. }
  522. args.pwr.scdc =
  523. NV50_DISP_SOR_HDMI_PWR_V0_SCDC_SCRAMBLE * scrambling |
  524. NV50_DISP_SOR_HDMI_PWR_V0_SCDC_DIV_BY_4 * high_tmds_clock_ratio;
  525. size = sizeof(args.base)
  526. + sizeof(args.pwr)
  527. + args.pwr.avi_infoframe_length
  528. + args.pwr.vendor_infoframe_length;
  529. nvif_mthd(&disp->disp->object, 0, &args, size);
  530. nv50_audio_enable(encoder, mode);
  531. /* If SCDC is supported by the downstream monitor, update
  532. * divider / scrambling settings to what we programmed above.
  533. */
  534. if (!hdmi->scdc.scrambling.supported)
  535. return;
  536. ret = drm_scdc_readb(nv_encoder->i2c, SCDC_TMDS_CONFIG, &config);
  537. if (ret < 0) {
  538. NV_ERROR(drm, "Failure to read SCDC_TMDS_CONFIG: %d\n", ret);
  539. return;
  540. }
  541. config &= ~(SCDC_TMDS_BIT_CLOCK_RATIO_BY_40 | SCDC_SCRAMBLING_ENABLE);
  542. config |= SCDC_TMDS_BIT_CLOCK_RATIO_BY_40 * high_tmds_clock_ratio;
  543. config |= SCDC_SCRAMBLING_ENABLE * scrambling;
  544. ret = drm_scdc_writeb(nv_encoder->i2c, SCDC_TMDS_CONFIG, config);
  545. if (ret < 0)
  546. NV_ERROR(drm, "Failure to write SCDC_TMDS_CONFIG = 0x%02x: %d\n",
  547. config, ret);
  548. }
  549. /******************************************************************************
  550. * MST
  551. *****************************************************************************/
  552. #define nv50_mstm(p) container_of((p), struct nv50_mstm, mgr)
  553. #define nv50_mstc(p) container_of((p), struct nv50_mstc, connector)
  554. #define nv50_msto(p) container_of((p), struct nv50_msto, encoder)
  555. struct nv50_mstm {
  556. struct nouveau_encoder *outp;
  557. struct drm_dp_mst_topology_mgr mgr;
  558. struct nv50_msto *msto[4];
  559. bool modified;
  560. bool disabled;
  561. int links;
  562. };
  563. struct nv50_mstc {
  564. struct nv50_mstm *mstm;
  565. struct drm_dp_mst_port *port;
  566. struct drm_connector connector;
  567. struct drm_display_mode *native;
  568. struct edid *edid;
  569. int pbn;
  570. };
  571. struct nv50_msto {
  572. struct drm_encoder encoder;
  573. struct nv50_head *head;
  574. struct nv50_mstc *mstc;
  575. bool disabled;
  576. };
  577. static struct drm_dp_payload *
  578. nv50_msto_payload(struct nv50_msto *msto)
  579. {
  580. struct nouveau_drm *drm = nouveau_drm(msto->encoder.dev);
  581. struct nv50_mstc *mstc = msto->mstc;
  582. struct nv50_mstm *mstm = mstc->mstm;
  583. int vcpi = mstc->port->vcpi.vcpi, i;
  584. NV_ATOMIC(drm, "%s: vcpi %d\n", msto->encoder.name, vcpi);
  585. for (i = 0; i < mstm->mgr.max_payloads; i++) {
  586. struct drm_dp_payload *payload = &mstm->mgr.payloads[i];
  587. NV_ATOMIC(drm, "%s: %d: vcpi %d start 0x%02x slots 0x%02x\n",
  588. mstm->outp->base.base.name, i, payload->vcpi,
  589. payload->start_slot, payload->num_slots);
  590. }
  591. for (i = 0; i < mstm->mgr.max_payloads; i++) {
  592. struct drm_dp_payload *payload = &mstm->mgr.payloads[i];
  593. if (payload->vcpi == vcpi)
  594. return payload;
  595. }
  596. return NULL;
  597. }
  598. static void
  599. nv50_msto_cleanup(struct nv50_msto *msto)
  600. {
  601. struct nouveau_drm *drm = nouveau_drm(msto->encoder.dev);
  602. struct nv50_mstc *mstc = msto->mstc;
  603. struct nv50_mstm *mstm = mstc->mstm;
  604. NV_ATOMIC(drm, "%s: msto cleanup\n", msto->encoder.name);
  605. if (mstc->port && mstc->port->vcpi.vcpi > 0 && !nv50_msto_payload(msto))
  606. drm_dp_mst_deallocate_vcpi(&mstm->mgr, mstc->port);
  607. if (msto->disabled) {
  608. msto->mstc = NULL;
  609. msto->head = NULL;
  610. msto->disabled = false;
  611. }
  612. }
  613. static void
  614. nv50_msto_prepare(struct nv50_msto *msto)
  615. {
  616. struct nouveau_drm *drm = nouveau_drm(msto->encoder.dev);
  617. struct nv50_mstc *mstc = msto->mstc;
  618. struct nv50_mstm *mstm = mstc->mstm;
  619. struct {
  620. struct nv50_disp_mthd_v1 base;
  621. struct nv50_disp_sor_dp_mst_vcpi_v0 vcpi;
  622. } args = {
  623. .base.version = 1,
  624. .base.method = NV50_DISP_MTHD_V1_SOR_DP_MST_VCPI,
  625. .base.hasht = mstm->outp->dcb->hasht,
  626. .base.hashm = (0xf0ff & mstm->outp->dcb->hashm) |
  627. (0x0100 << msto->head->base.index),
  628. };
  629. NV_ATOMIC(drm, "%s: msto prepare\n", msto->encoder.name);
  630. if (mstc->port && mstc->port->vcpi.vcpi > 0) {
  631. struct drm_dp_payload *payload = nv50_msto_payload(msto);
  632. if (payload) {
  633. args.vcpi.start_slot = payload->start_slot;
  634. args.vcpi.num_slots = payload->num_slots;
  635. args.vcpi.pbn = mstc->port->vcpi.pbn;
  636. args.vcpi.aligned_pbn = mstc->port->vcpi.aligned_pbn;
  637. }
  638. }
  639. NV_ATOMIC(drm, "%s: %s: %02x %02x %04x %04x\n",
  640. msto->encoder.name, msto->head->base.base.name,
  641. args.vcpi.start_slot, args.vcpi.num_slots,
  642. args.vcpi.pbn, args.vcpi.aligned_pbn);
  643. nvif_mthd(&drm->display->disp.object, 0, &args, sizeof(args));
  644. }
  645. static int
  646. nv50_msto_atomic_check(struct drm_encoder *encoder,
  647. struct drm_crtc_state *crtc_state,
  648. struct drm_connector_state *conn_state)
  649. {
  650. struct nv50_mstc *mstc = nv50_mstc(conn_state->connector);
  651. struct nv50_mstm *mstm = mstc->mstm;
  652. int bpp = conn_state->connector->display_info.bpc * 3;
  653. int slots;
  654. mstc->pbn = drm_dp_calc_pbn_mode(crtc_state->adjusted_mode.clock, bpp);
  655. slots = drm_dp_find_vcpi_slots(&mstm->mgr, mstc->pbn);
  656. if (slots < 0)
  657. return slots;
  658. return nv50_outp_atomic_check_view(encoder, crtc_state, conn_state,
  659. mstc->native);
  660. }
  661. static void
  662. nv50_msto_enable(struct drm_encoder *encoder)
  663. {
  664. struct nv50_head *head = nv50_head(encoder->crtc);
  665. struct nv50_msto *msto = nv50_msto(encoder);
  666. struct nv50_mstc *mstc = NULL;
  667. struct nv50_mstm *mstm = NULL;
  668. struct drm_connector *connector;
  669. struct drm_connector_list_iter conn_iter;
  670. u8 proto, depth;
  671. int slots;
  672. bool r;
  673. drm_connector_list_iter_begin(encoder->dev, &conn_iter);
  674. drm_for_each_connector_iter(connector, &conn_iter) {
  675. if (connector->state->best_encoder == &msto->encoder) {
  676. mstc = nv50_mstc(connector);
  677. mstm = mstc->mstm;
  678. break;
  679. }
  680. }
  681. drm_connector_list_iter_end(&conn_iter);
  682. if (WARN_ON(!mstc))
  683. return;
  684. slots = drm_dp_find_vcpi_slots(&mstm->mgr, mstc->pbn);
  685. r = drm_dp_mst_allocate_vcpi(&mstm->mgr, mstc->port, mstc->pbn, slots);
  686. WARN_ON(!r);
  687. if (!mstm->links++)
  688. nv50_outp_acquire(mstm->outp);
  689. if (mstm->outp->link & 1)
  690. proto = 0x8;
  691. else
  692. proto = 0x9;
  693. switch (mstc->connector.display_info.bpc) {
  694. case 6: depth = 0x2; break;
  695. case 8: depth = 0x5; break;
  696. case 10:
  697. default: depth = 0x6; break;
  698. }
  699. mstm->outp->update(mstm->outp, head->base.index,
  700. nv50_head_atom(head->base.base.state), proto, depth);
  701. msto->head = head;
  702. msto->mstc = mstc;
  703. mstm->modified = true;
  704. }
  705. static void
  706. nv50_msto_disable(struct drm_encoder *encoder)
  707. {
  708. struct nv50_msto *msto = nv50_msto(encoder);
  709. struct nv50_mstc *mstc = msto->mstc;
  710. struct nv50_mstm *mstm = mstc->mstm;
  711. if (mstc->port)
  712. drm_dp_mst_reset_vcpi_slots(&mstm->mgr, mstc->port);
  713. mstm->outp->update(mstm->outp, msto->head->base.index, NULL, 0, 0);
  714. mstm->modified = true;
  715. if (!--mstm->links)
  716. mstm->disabled = true;
  717. msto->disabled = true;
  718. }
  719. static const struct drm_encoder_helper_funcs
  720. nv50_msto_help = {
  721. .disable = nv50_msto_disable,
  722. .enable = nv50_msto_enable,
  723. .atomic_check = nv50_msto_atomic_check,
  724. };
  725. static void
  726. nv50_msto_destroy(struct drm_encoder *encoder)
  727. {
  728. struct nv50_msto *msto = nv50_msto(encoder);
  729. drm_encoder_cleanup(&msto->encoder);
  730. kfree(msto);
  731. }
  732. static const struct drm_encoder_funcs
  733. nv50_msto = {
  734. .destroy = nv50_msto_destroy,
  735. };
  736. static int
  737. nv50_msto_new(struct drm_device *dev, u32 heads, const char *name, int id,
  738. struct nv50_msto **pmsto)
  739. {
  740. struct nv50_msto *msto;
  741. int ret;
  742. if (!(msto = *pmsto = kzalloc(sizeof(*msto), GFP_KERNEL)))
  743. return -ENOMEM;
  744. ret = drm_encoder_init(dev, &msto->encoder, &nv50_msto,
  745. DRM_MODE_ENCODER_DPMST, "%s-mst-%d", name, id);
  746. if (ret) {
  747. kfree(*pmsto);
  748. *pmsto = NULL;
  749. return ret;
  750. }
  751. drm_encoder_helper_add(&msto->encoder, &nv50_msto_help);
  752. msto->encoder.possible_crtcs = heads;
  753. return 0;
  754. }
  755. static struct drm_encoder *
  756. nv50_mstc_atomic_best_encoder(struct drm_connector *connector,
  757. struct drm_connector_state *connector_state)
  758. {
  759. struct nv50_head *head = nv50_head(connector_state->crtc);
  760. struct nv50_mstc *mstc = nv50_mstc(connector);
  761. return &mstc->mstm->msto[head->base.index]->encoder;
  762. }
  763. static struct drm_encoder *
  764. nv50_mstc_best_encoder(struct drm_connector *connector)
  765. {
  766. struct nv50_mstc *mstc = nv50_mstc(connector);
  767. return &mstc->mstm->msto[0]->encoder;
  768. }
  769. static enum drm_mode_status
  770. nv50_mstc_mode_valid(struct drm_connector *connector,
  771. struct drm_display_mode *mode)
  772. {
  773. return MODE_OK;
  774. }
  775. static int
  776. nv50_mstc_get_modes(struct drm_connector *connector)
  777. {
  778. struct nv50_mstc *mstc = nv50_mstc(connector);
  779. int ret = 0;
  780. mstc->edid = drm_dp_mst_get_edid(&mstc->connector, mstc->port->mgr, mstc->port);
  781. drm_connector_update_edid_property(&mstc->connector, mstc->edid);
  782. if (mstc->edid)
  783. ret = drm_add_edid_modes(&mstc->connector, mstc->edid);
  784. if (!mstc->connector.display_info.bpc)
  785. mstc->connector.display_info.bpc = 8;
  786. if (mstc->native)
  787. drm_mode_destroy(mstc->connector.dev, mstc->native);
  788. mstc->native = nouveau_conn_native_mode(&mstc->connector);
  789. return ret;
  790. }
  791. static const struct drm_connector_helper_funcs
  792. nv50_mstc_help = {
  793. .get_modes = nv50_mstc_get_modes,
  794. .mode_valid = nv50_mstc_mode_valid,
  795. .best_encoder = nv50_mstc_best_encoder,
  796. .atomic_best_encoder = nv50_mstc_atomic_best_encoder,
  797. };
  798. static enum drm_connector_status
  799. nv50_mstc_detect(struct drm_connector *connector, bool force)
  800. {
  801. struct nv50_mstc *mstc = nv50_mstc(connector);
  802. enum drm_connector_status conn_status;
  803. int ret;
  804. if (!mstc->port)
  805. return connector_status_disconnected;
  806. ret = pm_runtime_get_sync(connector->dev->dev);
  807. if (ret < 0 && ret != -EACCES)
  808. return connector_status_disconnected;
  809. conn_status = drm_dp_mst_detect_port(connector, mstc->port->mgr,
  810. mstc->port);
  811. pm_runtime_mark_last_busy(connector->dev->dev);
  812. pm_runtime_put_autosuspend(connector->dev->dev);
  813. return conn_status;
  814. }
  815. static void
  816. nv50_mstc_destroy(struct drm_connector *connector)
  817. {
  818. struct nv50_mstc *mstc = nv50_mstc(connector);
  819. drm_connector_cleanup(&mstc->connector);
  820. kfree(mstc);
  821. }
  822. static const struct drm_connector_funcs
  823. nv50_mstc = {
  824. .reset = nouveau_conn_reset,
  825. .detect = nv50_mstc_detect,
  826. .fill_modes = drm_helper_probe_single_connector_modes,
  827. .destroy = nv50_mstc_destroy,
  828. .atomic_duplicate_state = nouveau_conn_atomic_duplicate_state,
  829. .atomic_destroy_state = nouveau_conn_atomic_destroy_state,
  830. .atomic_set_property = nouveau_conn_atomic_set_property,
  831. .atomic_get_property = nouveau_conn_atomic_get_property,
  832. };
  833. static int
  834. nv50_mstc_new(struct nv50_mstm *mstm, struct drm_dp_mst_port *port,
  835. const char *path, struct nv50_mstc **pmstc)
  836. {
  837. struct drm_device *dev = mstm->outp->base.base.dev;
  838. struct nv50_mstc *mstc;
  839. int ret, i;
  840. if (!(mstc = *pmstc = kzalloc(sizeof(*mstc), GFP_KERNEL)))
  841. return -ENOMEM;
  842. mstc->mstm = mstm;
  843. mstc->port = port;
  844. ret = drm_connector_init(dev, &mstc->connector, &nv50_mstc,
  845. DRM_MODE_CONNECTOR_DisplayPort);
  846. if (ret) {
  847. kfree(*pmstc);
  848. *pmstc = NULL;
  849. return ret;
  850. }
  851. drm_connector_helper_add(&mstc->connector, &nv50_mstc_help);
  852. mstc->connector.funcs->reset(&mstc->connector);
  853. nouveau_conn_attach_properties(&mstc->connector);
  854. for (i = 0; i < ARRAY_SIZE(mstm->msto) && mstm->msto[i]; i++)
  855. drm_connector_attach_encoder(&mstc->connector, &mstm->msto[i]->encoder);
  856. drm_object_attach_property(&mstc->connector.base, dev->mode_config.path_property, 0);
  857. drm_object_attach_property(&mstc->connector.base, dev->mode_config.tile_property, 0);
  858. drm_connector_set_path_property(&mstc->connector, path);
  859. return 0;
  860. }
  861. static void
  862. nv50_mstm_cleanup(struct nv50_mstm *mstm)
  863. {
  864. struct nouveau_drm *drm = nouveau_drm(mstm->outp->base.base.dev);
  865. struct drm_encoder *encoder;
  866. int ret;
  867. NV_ATOMIC(drm, "%s: mstm cleanup\n", mstm->outp->base.base.name);
  868. ret = drm_dp_check_act_status(&mstm->mgr);
  869. ret = drm_dp_update_payload_part2(&mstm->mgr);
  870. drm_for_each_encoder(encoder, mstm->outp->base.base.dev) {
  871. if (encoder->encoder_type == DRM_MODE_ENCODER_DPMST) {
  872. struct nv50_msto *msto = nv50_msto(encoder);
  873. struct nv50_mstc *mstc = msto->mstc;
  874. if (mstc && mstc->mstm == mstm)
  875. nv50_msto_cleanup(msto);
  876. }
  877. }
  878. mstm->modified = false;
  879. }
  880. static void
  881. nv50_mstm_prepare(struct nv50_mstm *mstm)
  882. {
  883. struct nouveau_drm *drm = nouveau_drm(mstm->outp->base.base.dev);
  884. struct drm_encoder *encoder;
  885. int ret;
  886. NV_ATOMIC(drm, "%s: mstm prepare\n", mstm->outp->base.base.name);
  887. ret = drm_dp_update_payload_part1(&mstm->mgr);
  888. drm_for_each_encoder(encoder, mstm->outp->base.base.dev) {
  889. if (encoder->encoder_type == DRM_MODE_ENCODER_DPMST) {
  890. struct nv50_msto *msto = nv50_msto(encoder);
  891. struct nv50_mstc *mstc = msto->mstc;
  892. if (mstc && mstc->mstm == mstm)
  893. nv50_msto_prepare(msto);
  894. }
  895. }
  896. if (mstm->disabled) {
  897. if (!mstm->links)
  898. nv50_outp_release(mstm->outp);
  899. mstm->disabled = false;
  900. }
  901. }
  902. static void
  903. nv50_mstm_hotplug(struct drm_dp_mst_topology_mgr *mgr)
  904. {
  905. struct nv50_mstm *mstm = nv50_mstm(mgr);
  906. drm_kms_helper_hotplug_event(mstm->outp->base.base.dev);
  907. }
  908. static void
  909. nv50_mstm_destroy_connector(struct drm_dp_mst_topology_mgr *mgr,
  910. struct drm_connector *connector)
  911. {
  912. struct nouveau_drm *drm = nouveau_drm(connector->dev);
  913. struct nv50_mstc *mstc = nv50_mstc(connector);
  914. drm_connector_unregister(&mstc->connector);
  915. drm_fb_helper_remove_one_connector(&drm->fbcon->helper, &mstc->connector);
  916. drm_modeset_lock(&drm->dev->mode_config.connection_mutex, NULL);
  917. mstc->port = NULL;
  918. drm_modeset_unlock(&drm->dev->mode_config.connection_mutex);
  919. drm_connector_put(&mstc->connector);
  920. }
  921. static void
  922. nv50_mstm_register_connector(struct drm_connector *connector)
  923. {
  924. struct nouveau_drm *drm = nouveau_drm(connector->dev);
  925. drm_fb_helper_add_one_connector(&drm->fbcon->helper, connector);
  926. drm_connector_register(connector);
  927. }
  928. static struct drm_connector *
  929. nv50_mstm_add_connector(struct drm_dp_mst_topology_mgr *mgr,
  930. struct drm_dp_mst_port *port, const char *path)
  931. {
  932. struct nv50_mstm *mstm = nv50_mstm(mgr);
  933. struct nv50_mstc *mstc;
  934. int ret;
  935. ret = nv50_mstc_new(mstm, port, path, &mstc);
  936. if (ret) {
  937. if (mstc)
  938. mstc->connector.funcs->destroy(&mstc->connector);
  939. return NULL;
  940. }
  941. return &mstc->connector;
  942. }
  943. static const struct drm_dp_mst_topology_cbs
  944. nv50_mstm = {
  945. .add_connector = nv50_mstm_add_connector,
  946. .register_connector = nv50_mstm_register_connector,
  947. .destroy_connector = nv50_mstm_destroy_connector,
  948. .hotplug = nv50_mstm_hotplug,
  949. };
  950. void
  951. nv50_mstm_service(struct nv50_mstm *mstm)
  952. {
  953. struct drm_dp_aux *aux = mstm ? mstm->mgr.aux : NULL;
  954. bool handled = true;
  955. int ret;
  956. u8 esi[8] = {};
  957. if (!aux)
  958. return;
  959. while (handled) {
  960. ret = drm_dp_dpcd_read(aux, DP_SINK_COUNT_ESI, esi, 8);
  961. if (ret != 8) {
  962. drm_dp_mst_topology_mgr_set_mst(&mstm->mgr, false);
  963. return;
  964. }
  965. drm_dp_mst_hpd_irq(&mstm->mgr, esi, &handled);
  966. if (!handled)
  967. break;
  968. drm_dp_dpcd_write(aux, DP_SINK_COUNT_ESI + 1, &esi[1], 3);
  969. }
  970. }
  971. void
  972. nv50_mstm_remove(struct nv50_mstm *mstm)
  973. {
  974. if (mstm)
  975. drm_dp_mst_topology_mgr_set_mst(&mstm->mgr, false);
  976. }
  977. static int
  978. nv50_mstm_enable(struct nv50_mstm *mstm, u8 dpcd, int state)
  979. {
  980. struct nouveau_encoder *outp = mstm->outp;
  981. struct {
  982. struct nv50_disp_mthd_v1 base;
  983. struct nv50_disp_sor_dp_mst_link_v0 mst;
  984. } args = {
  985. .base.version = 1,
  986. .base.method = NV50_DISP_MTHD_V1_SOR_DP_MST_LINK,
  987. .base.hasht = outp->dcb->hasht,
  988. .base.hashm = outp->dcb->hashm,
  989. .mst.state = state,
  990. };
  991. struct nouveau_drm *drm = nouveau_drm(outp->base.base.dev);
  992. struct nvif_object *disp = &drm->display->disp.object;
  993. int ret;
  994. if (dpcd >= 0x12) {
  995. /* Even if we're enabling MST, start with disabling the
  996. * branching unit to clear any sink-side MST topology state
  997. * that wasn't set by us
  998. */
  999. ret = drm_dp_dpcd_writeb(mstm->mgr.aux, DP_MSTM_CTRL, 0);
  1000. if (ret < 0)
  1001. return ret;
  1002. if (state) {
  1003. /* Now, start initializing */
  1004. ret = drm_dp_dpcd_writeb(mstm->mgr.aux, DP_MSTM_CTRL,
  1005. DP_MST_EN);
  1006. if (ret < 0)
  1007. return ret;
  1008. }
  1009. }
  1010. return nvif_mthd(disp, 0, &args, sizeof(args));
  1011. }
  1012. int
  1013. nv50_mstm_detect(struct nv50_mstm *mstm, u8 dpcd[8], int allow)
  1014. {
  1015. struct drm_dp_aux *aux;
  1016. int ret;
  1017. bool old_state, new_state;
  1018. u8 mstm_ctrl;
  1019. if (!mstm)
  1020. return 0;
  1021. mutex_lock(&mstm->mgr.lock);
  1022. old_state = mstm->mgr.mst_state;
  1023. new_state = old_state;
  1024. aux = mstm->mgr.aux;
  1025. if (old_state) {
  1026. /* Just check that the MST hub is still as we expect it */
  1027. ret = drm_dp_dpcd_readb(aux, DP_MSTM_CTRL, &mstm_ctrl);
  1028. if (ret < 0 || !(mstm_ctrl & DP_MST_EN)) {
  1029. DRM_DEBUG_KMS("Hub gone, disabling MST topology\n");
  1030. new_state = false;
  1031. }
  1032. } else if (dpcd[0] >= 0x12) {
  1033. ret = drm_dp_dpcd_readb(aux, DP_MSTM_CAP, &dpcd[1]);
  1034. if (ret < 0)
  1035. goto probe_error;
  1036. if (!(dpcd[1] & DP_MST_CAP))
  1037. dpcd[0] = 0x11;
  1038. else
  1039. new_state = allow;
  1040. }
  1041. if (new_state == old_state) {
  1042. mutex_unlock(&mstm->mgr.lock);
  1043. return new_state;
  1044. }
  1045. ret = nv50_mstm_enable(mstm, dpcd[0], new_state);
  1046. if (ret)
  1047. goto probe_error;
  1048. mutex_unlock(&mstm->mgr.lock);
  1049. ret = drm_dp_mst_topology_mgr_set_mst(&mstm->mgr, new_state);
  1050. if (ret)
  1051. return nv50_mstm_enable(mstm, dpcd[0], 0);
  1052. return new_state;
  1053. probe_error:
  1054. mutex_unlock(&mstm->mgr.lock);
  1055. return ret;
  1056. }
  1057. static void
  1058. nv50_mstm_fini(struct nv50_mstm *mstm)
  1059. {
  1060. if (mstm && mstm->mgr.mst_state)
  1061. drm_dp_mst_topology_mgr_suspend(&mstm->mgr);
  1062. }
  1063. static void
  1064. nv50_mstm_init(struct nv50_mstm *mstm)
  1065. {
  1066. if (mstm && mstm->mgr.mst_state)
  1067. drm_dp_mst_topology_mgr_resume(&mstm->mgr);
  1068. }
  1069. static void
  1070. nv50_mstm_del(struct nv50_mstm **pmstm)
  1071. {
  1072. struct nv50_mstm *mstm = *pmstm;
  1073. if (mstm) {
  1074. drm_dp_mst_topology_mgr_destroy(&mstm->mgr);
  1075. kfree(*pmstm);
  1076. *pmstm = NULL;
  1077. }
  1078. }
  1079. static int
  1080. nv50_mstm_new(struct nouveau_encoder *outp, struct drm_dp_aux *aux, int aux_max,
  1081. int conn_base_id, struct nv50_mstm **pmstm)
  1082. {
  1083. const int max_payloads = hweight8(outp->dcb->heads);
  1084. struct drm_device *dev = outp->base.base.dev;
  1085. struct nv50_mstm *mstm;
  1086. int ret, i;
  1087. u8 dpcd;
  1088. /* This is a workaround for some monitors not functioning
  1089. * correctly in MST mode on initial module load. I think
  1090. * some bad interaction with the VBIOS may be responsible.
  1091. *
  1092. * A good ol' off and on again seems to work here ;)
  1093. */
  1094. ret = drm_dp_dpcd_readb(aux, DP_DPCD_REV, &dpcd);
  1095. if (ret >= 0 && dpcd >= 0x12)
  1096. drm_dp_dpcd_writeb(aux, DP_MSTM_CTRL, 0);
  1097. if (!(mstm = *pmstm = kzalloc(sizeof(*mstm), GFP_KERNEL)))
  1098. return -ENOMEM;
  1099. mstm->outp = outp;
  1100. mstm->mgr.cbs = &nv50_mstm;
  1101. ret = drm_dp_mst_topology_mgr_init(&mstm->mgr, dev, aux, aux_max,
  1102. max_payloads, conn_base_id);
  1103. if (ret)
  1104. return ret;
  1105. for (i = 0; i < max_payloads; i++) {
  1106. ret = nv50_msto_new(dev, outp->dcb->heads, outp->base.base.name,
  1107. i, &mstm->msto[i]);
  1108. if (ret)
  1109. return ret;
  1110. }
  1111. return 0;
  1112. }
  1113. /******************************************************************************
  1114. * SOR
  1115. *****************************************************************************/
  1116. static void
  1117. nv50_sor_update(struct nouveau_encoder *nv_encoder, u8 head,
  1118. struct nv50_head_atom *asyh, u8 proto, u8 depth)
  1119. {
  1120. struct nv50_disp *disp = nv50_disp(nv_encoder->base.base.dev);
  1121. struct nv50_core *core = disp->core;
  1122. if (!asyh) {
  1123. nv_encoder->ctrl &= ~BIT(head);
  1124. if (!(nv_encoder->ctrl & 0x0000000f))
  1125. nv_encoder->ctrl = 0;
  1126. } else {
  1127. nv_encoder->ctrl |= proto << 8;
  1128. nv_encoder->ctrl |= BIT(head);
  1129. asyh->or.depth = depth;
  1130. }
  1131. core->func->sor->ctrl(core, nv_encoder->or, nv_encoder->ctrl, asyh);
  1132. }
  1133. static void
  1134. nv50_sor_disable(struct drm_encoder *encoder)
  1135. {
  1136. struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
  1137. struct nouveau_crtc *nv_crtc = nouveau_crtc(nv_encoder->crtc);
  1138. nv_encoder->crtc = NULL;
  1139. if (nv_crtc) {
  1140. struct nvkm_i2c_aux *aux = nv_encoder->aux;
  1141. u8 pwr;
  1142. if (aux) {
  1143. int ret = nvkm_rdaux(aux, DP_SET_POWER, &pwr, 1);
  1144. if (ret == 0) {
  1145. pwr &= ~DP_SET_POWER_MASK;
  1146. pwr |= DP_SET_POWER_D3;
  1147. nvkm_wraux(aux, DP_SET_POWER, &pwr, 1);
  1148. }
  1149. }
  1150. nv_encoder->update(nv_encoder, nv_crtc->index, NULL, 0, 0);
  1151. nv50_audio_disable(encoder, nv_crtc);
  1152. nv50_hdmi_disable(&nv_encoder->base.base, nv_crtc);
  1153. nv50_outp_release(nv_encoder);
  1154. }
  1155. }
  1156. static void
  1157. nv50_sor_enable(struct drm_encoder *encoder)
  1158. {
  1159. struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
  1160. struct nouveau_crtc *nv_crtc = nouveau_crtc(encoder->crtc);
  1161. struct nv50_head_atom *asyh = nv50_head_atom(nv_crtc->base.state);
  1162. struct drm_display_mode *mode = &asyh->state.adjusted_mode;
  1163. struct {
  1164. struct nv50_disp_mthd_v1 base;
  1165. struct nv50_disp_sor_lvds_script_v0 lvds;
  1166. } lvds = {
  1167. .base.version = 1,
  1168. .base.method = NV50_DISP_MTHD_V1_SOR_LVDS_SCRIPT,
  1169. .base.hasht = nv_encoder->dcb->hasht,
  1170. .base.hashm = nv_encoder->dcb->hashm,
  1171. };
  1172. struct nv50_disp *disp = nv50_disp(encoder->dev);
  1173. struct drm_device *dev = encoder->dev;
  1174. struct nouveau_drm *drm = nouveau_drm(dev);
  1175. struct nouveau_connector *nv_connector;
  1176. struct nvbios *bios = &drm->vbios;
  1177. u8 proto = 0xf;
  1178. u8 depth = 0x0;
  1179. nv_connector = nouveau_encoder_connector_get(nv_encoder);
  1180. nv_encoder->crtc = encoder->crtc;
  1181. nv50_outp_acquire(nv_encoder);
  1182. switch (nv_encoder->dcb->type) {
  1183. case DCB_OUTPUT_TMDS:
  1184. if (nv_encoder->link & 1) {
  1185. proto = 0x1;
  1186. /* Only enable dual-link if:
  1187. * - Need to (i.e. rate > 165MHz)
  1188. * - DCB says we can
  1189. * - Not an HDMI monitor, since there's no dual-link
  1190. * on HDMI.
  1191. */
  1192. if (mode->clock >= 165000 &&
  1193. nv_encoder->dcb->duallink_possible &&
  1194. !drm_detect_hdmi_monitor(nv_connector->edid))
  1195. proto |= 0x4;
  1196. } else {
  1197. proto = 0x2;
  1198. }
  1199. nv50_hdmi_enable(&nv_encoder->base.base, mode);
  1200. break;
  1201. case DCB_OUTPUT_LVDS:
  1202. proto = 0x0;
  1203. if (bios->fp_no_ddc) {
  1204. if (bios->fp.dual_link)
  1205. lvds.lvds.script |= 0x0100;
  1206. if (bios->fp.if_is_24bit)
  1207. lvds.lvds.script |= 0x0200;
  1208. } else {
  1209. if (nv_connector->type == DCB_CONNECTOR_LVDS_SPWG) {
  1210. if (((u8 *)nv_connector->edid)[121] == 2)
  1211. lvds.lvds.script |= 0x0100;
  1212. } else
  1213. if (mode->clock >= bios->fp.duallink_transition_clk) {
  1214. lvds.lvds.script |= 0x0100;
  1215. }
  1216. if (lvds.lvds.script & 0x0100) {
  1217. if (bios->fp.strapless_is_24bit & 2)
  1218. lvds.lvds.script |= 0x0200;
  1219. } else {
  1220. if (bios->fp.strapless_is_24bit & 1)
  1221. lvds.lvds.script |= 0x0200;
  1222. }
  1223. if (nv_connector->base.display_info.bpc == 8)
  1224. lvds.lvds.script |= 0x0200;
  1225. }
  1226. nvif_mthd(&disp->disp->object, 0, &lvds, sizeof(lvds));
  1227. break;
  1228. case DCB_OUTPUT_DP:
  1229. if (nv_connector->base.display_info.bpc == 6)
  1230. depth = 0x2;
  1231. else
  1232. if (nv_connector->base.display_info.bpc == 8)
  1233. depth = 0x5;
  1234. else
  1235. depth = 0x6;
  1236. if (nv_encoder->link & 1)
  1237. proto = 0x8;
  1238. else
  1239. proto = 0x9;
  1240. nv50_audio_enable(encoder, mode);
  1241. break;
  1242. default:
  1243. BUG();
  1244. break;
  1245. }
  1246. nv_encoder->update(nv_encoder, nv_crtc->index, asyh, proto, depth);
  1247. }
  1248. static const struct drm_encoder_helper_funcs
  1249. nv50_sor_help = {
  1250. .atomic_check = nv50_outp_atomic_check,
  1251. .enable = nv50_sor_enable,
  1252. .disable = nv50_sor_disable,
  1253. };
  1254. static void
  1255. nv50_sor_destroy(struct drm_encoder *encoder)
  1256. {
  1257. struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
  1258. nv50_mstm_del(&nv_encoder->dp.mstm);
  1259. drm_encoder_cleanup(encoder);
  1260. kfree(encoder);
  1261. }
  1262. static const struct drm_encoder_funcs
  1263. nv50_sor_func = {
  1264. .destroy = nv50_sor_destroy,
  1265. };
  1266. static int
  1267. nv50_sor_create(struct drm_connector *connector, struct dcb_output *dcbe)
  1268. {
  1269. struct nouveau_connector *nv_connector = nouveau_connector(connector);
  1270. struct nouveau_drm *drm = nouveau_drm(connector->dev);
  1271. struct nvkm_bios *bios = nvxx_bios(&drm->client.device);
  1272. struct nvkm_i2c *i2c = nvxx_i2c(&drm->client.device);
  1273. struct nouveau_encoder *nv_encoder;
  1274. struct drm_encoder *encoder;
  1275. u8 ver, hdr, cnt, len;
  1276. u32 data;
  1277. int type, ret;
  1278. switch (dcbe->type) {
  1279. case DCB_OUTPUT_LVDS: type = DRM_MODE_ENCODER_LVDS; break;
  1280. case DCB_OUTPUT_TMDS:
  1281. case DCB_OUTPUT_DP:
  1282. default:
  1283. type = DRM_MODE_ENCODER_TMDS;
  1284. break;
  1285. }
  1286. nv_encoder = kzalloc(sizeof(*nv_encoder), GFP_KERNEL);
  1287. if (!nv_encoder)
  1288. return -ENOMEM;
  1289. nv_encoder->dcb = dcbe;
  1290. nv_encoder->update = nv50_sor_update;
  1291. encoder = to_drm_encoder(nv_encoder);
  1292. encoder->possible_crtcs = dcbe->heads;
  1293. encoder->possible_clones = 0;
  1294. drm_encoder_init(connector->dev, encoder, &nv50_sor_func, type,
  1295. "sor-%04x-%04x", dcbe->hasht, dcbe->hashm);
  1296. drm_encoder_helper_add(encoder, &nv50_sor_help);
  1297. drm_connector_attach_encoder(connector, encoder);
  1298. if (dcbe->type == DCB_OUTPUT_DP) {
  1299. struct nv50_disp *disp = nv50_disp(encoder->dev);
  1300. struct nvkm_i2c_aux *aux =
  1301. nvkm_i2c_aux_find(i2c, dcbe->i2c_index);
  1302. if (aux) {
  1303. if (disp->disp->object.oclass < GF110_DISP) {
  1304. /* HW has no support for address-only
  1305. * transactions, so we're required to
  1306. * use custom I2C-over-AUX code.
  1307. */
  1308. nv_encoder->i2c = &aux->i2c;
  1309. } else {
  1310. nv_encoder->i2c = &nv_connector->aux.ddc;
  1311. }
  1312. nv_encoder->aux = aux;
  1313. }
  1314. if ((data = nvbios_dp_table(bios, &ver, &hdr, &cnt, &len)) &&
  1315. ver >= 0x40 && (nvbios_rd08(bios, data + 0x08) & 0x04)) {
  1316. ret = nv50_mstm_new(nv_encoder, &nv_connector->aux, 16,
  1317. nv_connector->base.base.id,
  1318. &nv_encoder->dp.mstm);
  1319. if (ret)
  1320. return ret;
  1321. }
  1322. } else {
  1323. struct nvkm_i2c_bus *bus =
  1324. nvkm_i2c_bus_find(i2c, dcbe->i2c_index);
  1325. if (bus)
  1326. nv_encoder->i2c = &bus->i2c;
  1327. }
  1328. return 0;
  1329. }
  1330. /******************************************************************************
  1331. * PIOR
  1332. *****************************************************************************/
  1333. static int
  1334. nv50_pior_atomic_check(struct drm_encoder *encoder,
  1335. struct drm_crtc_state *crtc_state,
  1336. struct drm_connector_state *conn_state)
  1337. {
  1338. int ret = nv50_outp_atomic_check(encoder, crtc_state, conn_state);
  1339. if (ret)
  1340. return ret;
  1341. crtc_state->adjusted_mode.clock *= 2;
  1342. return 0;
  1343. }
  1344. static void
  1345. nv50_pior_disable(struct drm_encoder *encoder)
  1346. {
  1347. struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
  1348. struct nv50_core *core = nv50_disp(encoder->dev)->core;
  1349. if (nv_encoder->crtc)
  1350. core->func->pior->ctrl(core, nv_encoder->or, 0x00000000, NULL);
  1351. nv_encoder->crtc = NULL;
  1352. nv50_outp_release(nv_encoder);
  1353. }
  1354. static void
  1355. nv50_pior_enable(struct drm_encoder *encoder)
  1356. {
  1357. struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
  1358. struct nouveau_crtc *nv_crtc = nouveau_crtc(encoder->crtc);
  1359. struct nouveau_connector *nv_connector;
  1360. struct nv50_head_atom *asyh = nv50_head_atom(nv_crtc->base.state);
  1361. struct nv50_core *core = nv50_disp(encoder->dev)->core;
  1362. u8 owner = 1 << nv_crtc->index;
  1363. u8 proto;
  1364. nv50_outp_acquire(nv_encoder);
  1365. nv_connector = nouveau_encoder_connector_get(nv_encoder);
  1366. switch (nv_connector->base.display_info.bpc) {
  1367. case 10: asyh->or.depth = 0x6; break;
  1368. case 8: asyh->or.depth = 0x5; break;
  1369. case 6: asyh->or.depth = 0x2; break;
  1370. default: asyh->or.depth = 0x0; break;
  1371. }
  1372. switch (nv_encoder->dcb->type) {
  1373. case DCB_OUTPUT_TMDS:
  1374. case DCB_OUTPUT_DP:
  1375. proto = 0x0;
  1376. break;
  1377. default:
  1378. BUG();
  1379. break;
  1380. }
  1381. core->func->pior->ctrl(core, nv_encoder->or, (proto << 8) | owner, asyh);
  1382. nv_encoder->crtc = encoder->crtc;
  1383. }
  1384. static const struct drm_encoder_helper_funcs
  1385. nv50_pior_help = {
  1386. .atomic_check = nv50_pior_atomic_check,
  1387. .enable = nv50_pior_enable,
  1388. .disable = nv50_pior_disable,
  1389. };
  1390. static void
  1391. nv50_pior_destroy(struct drm_encoder *encoder)
  1392. {
  1393. drm_encoder_cleanup(encoder);
  1394. kfree(encoder);
  1395. }
  1396. static const struct drm_encoder_funcs
  1397. nv50_pior_func = {
  1398. .destroy = nv50_pior_destroy,
  1399. };
  1400. static int
  1401. nv50_pior_create(struct drm_connector *connector, struct dcb_output *dcbe)
  1402. {
  1403. struct nouveau_drm *drm = nouveau_drm(connector->dev);
  1404. struct nvkm_i2c *i2c = nvxx_i2c(&drm->client.device);
  1405. struct nvkm_i2c_bus *bus = NULL;
  1406. struct nvkm_i2c_aux *aux = NULL;
  1407. struct i2c_adapter *ddc;
  1408. struct nouveau_encoder *nv_encoder;
  1409. struct drm_encoder *encoder;
  1410. int type;
  1411. switch (dcbe->type) {
  1412. case DCB_OUTPUT_TMDS:
  1413. bus = nvkm_i2c_bus_find(i2c, NVKM_I2C_BUS_EXT(dcbe->extdev));
  1414. ddc = bus ? &bus->i2c : NULL;
  1415. type = DRM_MODE_ENCODER_TMDS;
  1416. break;
  1417. case DCB_OUTPUT_DP:
  1418. aux = nvkm_i2c_aux_find(i2c, NVKM_I2C_AUX_EXT(dcbe->extdev));
  1419. ddc = aux ? &aux->i2c : NULL;
  1420. type = DRM_MODE_ENCODER_TMDS;
  1421. break;
  1422. default:
  1423. return -ENODEV;
  1424. }
  1425. nv_encoder = kzalloc(sizeof(*nv_encoder), GFP_KERNEL);
  1426. if (!nv_encoder)
  1427. return -ENOMEM;
  1428. nv_encoder->dcb = dcbe;
  1429. nv_encoder->i2c = ddc;
  1430. nv_encoder->aux = aux;
  1431. encoder = to_drm_encoder(nv_encoder);
  1432. encoder->possible_crtcs = dcbe->heads;
  1433. encoder->possible_clones = 0;
  1434. drm_encoder_init(connector->dev, encoder, &nv50_pior_func, type,
  1435. "pior-%04x-%04x", dcbe->hasht, dcbe->hashm);
  1436. drm_encoder_helper_add(encoder, &nv50_pior_help);
  1437. drm_connector_attach_encoder(connector, encoder);
  1438. return 0;
  1439. }
  1440. /******************************************************************************
  1441. * Atomic
  1442. *****************************************************************************/
  1443. static void
  1444. nv50_disp_atomic_commit_core(struct drm_atomic_state *state, u32 *interlock)
  1445. {
  1446. struct nouveau_drm *drm = nouveau_drm(state->dev);
  1447. struct nv50_disp *disp = nv50_disp(drm->dev);
  1448. struct nv50_core *core = disp->core;
  1449. struct nv50_mstm *mstm;
  1450. struct drm_encoder *encoder;
  1451. NV_ATOMIC(drm, "commit core %08x\n", interlock[NV50_DISP_INTERLOCK_BASE]);
  1452. drm_for_each_encoder(encoder, drm->dev) {
  1453. if (encoder->encoder_type != DRM_MODE_ENCODER_DPMST) {
  1454. mstm = nouveau_encoder(encoder)->dp.mstm;
  1455. if (mstm && mstm->modified)
  1456. nv50_mstm_prepare(mstm);
  1457. }
  1458. }
  1459. core->func->ntfy_init(disp->sync, NV50_DISP_CORE_NTFY);
  1460. core->func->update(core, interlock, true);
  1461. if (core->func->ntfy_wait_done(disp->sync, NV50_DISP_CORE_NTFY,
  1462. disp->core->chan.base.device))
  1463. NV_ERROR(drm, "core notifier timeout\n");
  1464. drm_for_each_encoder(encoder, drm->dev) {
  1465. if (encoder->encoder_type != DRM_MODE_ENCODER_DPMST) {
  1466. mstm = nouveau_encoder(encoder)->dp.mstm;
  1467. if (mstm && mstm->modified)
  1468. nv50_mstm_cleanup(mstm);
  1469. }
  1470. }
  1471. }
  1472. static void
  1473. nv50_disp_atomic_commit_wndw(struct drm_atomic_state *state, u32 *interlock)
  1474. {
  1475. struct drm_plane_state *new_plane_state;
  1476. struct drm_plane *plane;
  1477. int i;
  1478. for_each_new_plane_in_state(state, plane, new_plane_state, i) {
  1479. struct nv50_wndw *wndw = nv50_wndw(plane);
  1480. if (interlock[wndw->interlock.type] & wndw->interlock.data) {
  1481. if (wndw->func->update)
  1482. wndw->func->update(wndw, interlock);
  1483. }
  1484. }
  1485. }
  1486. static void
  1487. nv50_disp_atomic_commit_tail(struct drm_atomic_state *state)
  1488. {
  1489. struct drm_device *dev = state->dev;
  1490. struct drm_crtc_state *new_crtc_state, *old_crtc_state;
  1491. struct drm_crtc *crtc;
  1492. struct drm_plane_state *new_plane_state;
  1493. struct drm_plane *plane;
  1494. struct nouveau_drm *drm = nouveau_drm(dev);
  1495. struct nv50_disp *disp = nv50_disp(dev);
  1496. struct nv50_atom *atom = nv50_atom(state);
  1497. struct nv50_outp_atom *outp, *outt;
  1498. u32 interlock[NV50_DISP_INTERLOCK__SIZE] = {};
  1499. int i;
  1500. NV_ATOMIC(drm, "commit %d %d\n", atom->lock_core, atom->flush_disable);
  1501. drm_atomic_helper_wait_for_fences(dev, state, false);
  1502. drm_atomic_helper_wait_for_dependencies(state);
  1503. drm_atomic_helper_update_legacy_modeset_state(dev, state);
  1504. if (atom->lock_core)
  1505. mutex_lock(&disp->mutex);
  1506. /* Disable head(s). */
  1507. for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i) {
  1508. struct nv50_head_atom *asyh = nv50_head_atom(new_crtc_state);
  1509. struct nv50_head *head = nv50_head(crtc);
  1510. NV_ATOMIC(drm, "%s: clr %04x (set %04x)\n", crtc->name,
  1511. asyh->clr.mask, asyh->set.mask);
  1512. if (old_crtc_state->active && !new_crtc_state->active)
  1513. drm_crtc_vblank_off(crtc);
  1514. if (asyh->clr.mask) {
  1515. nv50_head_flush_clr(head, asyh, atom->flush_disable);
  1516. interlock[NV50_DISP_INTERLOCK_CORE] |= 1;
  1517. }
  1518. }
  1519. /* Disable plane(s). */
  1520. for_each_new_plane_in_state(state, plane, new_plane_state, i) {
  1521. struct nv50_wndw_atom *asyw = nv50_wndw_atom(new_plane_state);
  1522. struct nv50_wndw *wndw = nv50_wndw(plane);
  1523. NV_ATOMIC(drm, "%s: clr %02x (set %02x)\n", plane->name,
  1524. asyw->clr.mask, asyw->set.mask);
  1525. if (!asyw->clr.mask)
  1526. continue;
  1527. nv50_wndw_flush_clr(wndw, interlock, atom->flush_disable, asyw);
  1528. }
  1529. /* Disable output path(s). */
  1530. list_for_each_entry(outp, &atom->outp, head) {
  1531. const struct drm_encoder_helper_funcs *help;
  1532. struct drm_encoder *encoder;
  1533. encoder = outp->encoder;
  1534. help = encoder->helper_private;
  1535. NV_ATOMIC(drm, "%s: clr %02x (set %02x)\n", encoder->name,
  1536. outp->clr.mask, outp->set.mask);
  1537. if (outp->clr.mask) {
  1538. help->disable(encoder);
  1539. interlock[NV50_DISP_INTERLOCK_CORE] |= 1;
  1540. if (outp->flush_disable) {
  1541. nv50_disp_atomic_commit_wndw(state, interlock);
  1542. nv50_disp_atomic_commit_core(state, interlock);
  1543. memset(interlock, 0x00, sizeof(interlock));
  1544. }
  1545. }
  1546. }
  1547. /* Flush disable. */
  1548. if (interlock[NV50_DISP_INTERLOCK_CORE]) {
  1549. if (atom->flush_disable) {
  1550. nv50_disp_atomic_commit_wndw(state, interlock);
  1551. nv50_disp_atomic_commit_core(state, interlock);
  1552. memset(interlock, 0x00, sizeof(interlock));
  1553. }
  1554. }
  1555. /* Update output path(s). */
  1556. list_for_each_entry_safe(outp, outt, &atom->outp, head) {
  1557. const struct drm_encoder_helper_funcs *help;
  1558. struct drm_encoder *encoder;
  1559. encoder = outp->encoder;
  1560. help = encoder->helper_private;
  1561. NV_ATOMIC(drm, "%s: set %02x (clr %02x)\n", encoder->name,
  1562. outp->set.mask, outp->clr.mask);
  1563. if (outp->set.mask) {
  1564. help->enable(encoder);
  1565. interlock[NV50_DISP_INTERLOCK_CORE] = 1;
  1566. }
  1567. list_del(&outp->head);
  1568. kfree(outp);
  1569. }
  1570. /* Update head(s). */
  1571. for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i) {
  1572. struct nv50_head_atom *asyh = nv50_head_atom(new_crtc_state);
  1573. struct nv50_head *head = nv50_head(crtc);
  1574. NV_ATOMIC(drm, "%s: set %04x (clr %04x)\n", crtc->name,
  1575. asyh->set.mask, asyh->clr.mask);
  1576. if (asyh->set.mask) {
  1577. nv50_head_flush_set(head, asyh);
  1578. interlock[NV50_DISP_INTERLOCK_CORE] = 1;
  1579. }
  1580. if (new_crtc_state->active) {
  1581. if (!old_crtc_state->active)
  1582. drm_crtc_vblank_on(crtc);
  1583. if (new_crtc_state->event)
  1584. drm_crtc_vblank_get(crtc);
  1585. }
  1586. }
  1587. /* Update plane(s). */
  1588. for_each_new_plane_in_state(state, plane, new_plane_state, i) {
  1589. struct nv50_wndw_atom *asyw = nv50_wndw_atom(new_plane_state);
  1590. struct nv50_wndw *wndw = nv50_wndw(plane);
  1591. NV_ATOMIC(drm, "%s: set %02x (clr %02x)\n", plane->name,
  1592. asyw->set.mask, asyw->clr.mask);
  1593. if ( !asyw->set.mask &&
  1594. (!asyw->clr.mask || atom->flush_disable))
  1595. continue;
  1596. nv50_wndw_flush_set(wndw, interlock, asyw);
  1597. }
  1598. /* Flush update. */
  1599. nv50_disp_atomic_commit_wndw(state, interlock);
  1600. if (interlock[NV50_DISP_INTERLOCK_CORE]) {
  1601. if (interlock[NV50_DISP_INTERLOCK_BASE] ||
  1602. interlock[NV50_DISP_INTERLOCK_OVLY] ||
  1603. interlock[NV50_DISP_INTERLOCK_WNDW] ||
  1604. !atom->state.legacy_cursor_update)
  1605. nv50_disp_atomic_commit_core(state, interlock);
  1606. else
  1607. disp->core->func->update(disp->core, interlock, false);
  1608. }
  1609. if (atom->lock_core)
  1610. mutex_unlock(&disp->mutex);
  1611. /* Wait for HW to signal completion. */
  1612. for_each_new_plane_in_state(state, plane, new_plane_state, i) {
  1613. struct nv50_wndw_atom *asyw = nv50_wndw_atom(new_plane_state);
  1614. struct nv50_wndw *wndw = nv50_wndw(plane);
  1615. int ret = nv50_wndw_wait_armed(wndw, asyw);
  1616. if (ret)
  1617. NV_ERROR(drm, "%s: timeout\n", plane->name);
  1618. }
  1619. for_each_new_crtc_in_state(state, crtc, new_crtc_state, i) {
  1620. if (new_crtc_state->event) {
  1621. unsigned long flags;
  1622. /* Get correct count/ts if racing with vblank irq */
  1623. if (new_crtc_state->active)
  1624. drm_crtc_accurate_vblank_count(crtc);
  1625. spin_lock_irqsave(&crtc->dev->event_lock, flags);
  1626. drm_crtc_send_vblank_event(crtc, new_crtc_state->event);
  1627. spin_unlock_irqrestore(&crtc->dev->event_lock, flags);
  1628. new_crtc_state->event = NULL;
  1629. if (new_crtc_state->active)
  1630. drm_crtc_vblank_put(crtc);
  1631. }
  1632. }
  1633. drm_atomic_helper_commit_hw_done(state);
  1634. drm_atomic_helper_cleanup_planes(dev, state);
  1635. drm_atomic_helper_commit_cleanup_done(state);
  1636. drm_atomic_state_put(state);
  1637. }
  1638. static void
  1639. nv50_disp_atomic_commit_work(struct work_struct *work)
  1640. {
  1641. struct drm_atomic_state *state =
  1642. container_of(work, typeof(*state), commit_work);
  1643. nv50_disp_atomic_commit_tail(state);
  1644. }
  1645. static int
  1646. nv50_disp_atomic_commit(struct drm_device *dev,
  1647. struct drm_atomic_state *state, bool nonblock)
  1648. {
  1649. struct nouveau_drm *drm = nouveau_drm(dev);
  1650. struct drm_plane_state *new_plane_state;
  1651. struct drm_plane *plane;
  1652. struct drm_crtc *crtc;
  1653. bool active = false;
  1654. int ret, i;
  1655. ret = pm_runtime_get_sync(dev->dev);
  1656. if (ret < 0 && ret != -EACCES)
  1657. return ret;
  1658. ret = drm_atomic_helper_setup_commit(state, nonblock);
  1659. if (ret)
  1660. goto done;
  1661. INIT_WORK(&state->commit_work, nv50_disp_atomic_commit_work);
  1662. ret = drm_atomic_helper_prepare_planes(dev, state);
  1663. if (ret)
  1664. goto done;
  1665. if (!nonblock) {
  1666. ret = drm_atomic_helper_wait_for_fences(dev, state, true);
  1667. if (ret)
  1668. goto err_cleanup;
  1669. }
  1670. ret = drm_atomic_helper_swap_state(state, true);
  1671. if (ret)
  1672. goto err_cleanup;
  1673. for_each_new_plane_in_state(state, plane, new_plane_state, i) {
  1674. struct nv50_wndw_atom *asyw = nv50_wndw_atom(new_plane_state);
  1675. struct nv50_wndw *wndw = nv50_wndw(plane);
  1676. if (asyw->set.image)
  1677. nv50_wndw_ntfy_enable(wndw, asyw);
  1678. }
  1679. drm_atomic_state_get(state);
  1680. if (nonblock)
  1681. queue_work(system_unbound_wq, &state->commit_work);
  1682. else
  1683. nv50_disp_atomic_commit_tail(state);
  1684. drm_for_each_crtc(crtc, dev) {
  1685. if (crtc->state->active) {
  1686. if (!drm->have_disp_power_ref) {
  1687. drm->have_disp_power_ref = true;
  1688. return 0;
  1689. }
  1690. active = true;
  1691. break;
  1692. }
  1693. }
  1694. if (!active && drm->have_disp_power_ref) {
  1695. pm_runtime_put_autosuspend(dev->dev);
  1696. drm->have_disp_power_ref = false;
  1697. }
  1698. err_cleanup:
  1699. if (ret)
  1700. drm_atomic_helper_cleanup_planes(dev, state);
  1701. done:
  1702. pm_runtime_put_autosuspend(dev->dev);
  1703. return ret;
  1704. }
  1705. static struct nv50_outp_atom *
  1706. nv50_disp_outp_atomic_add(struct nv50_atom *atom, struct drm_encoder *encoder)
  1707. {
  1708. struct nv50_outp_atom *outp;
  1709. list_for_each_entry(outp, &atom->outp, head) {
  1710. if (outp->encoder == encoder)
  1711. return outp;
  1712. }
  1713. outp = kzalloc(sizeof(*outp), GFP_KERNEL);
  1714. if (!outp)
  1715. return ERR_PTR(-ENOMEM);
  1716. list_add(&outp->head, &atom->outp);
  1717. outp->encoder = encoder;
  1718. return outp;
  1719. }
  1720. static int
  1721. nv50_disp_outp_atomic_check_clr(struct nv50_atom *atom,
  1722. struct drm_connector_state *old_connector_state)
  1723. {
  1724. struct drm_encoder *encoder = old_connector_state->best_encoder;
  1725. struct drm_crtc_state *old_crtc_state, *new_crtc_state;
  1726. struct drm_crtc *crtc;
  1727. struct nv50_outp_atom *outp;
  1728. if (!(crtc = old_connector_state->crtc))
  1729. return 0;
  1730. old_crtc_state = drm_atomic_get_old_crtc_state(&atom->state, crtc);
  1731. new_crtc_state = drm_atomic_get_new_crtc_state(&atom->state, crtc);
  1732. if (old_crtc_state->active && drm_atomic_crtc_needs_modeset(new_crtc_state)) {
  1733. outp = nv50_disp_outp_atomic_add(atom, encoder);
  1734. if (IS_ERR(outp))
  1735. return PTR_ERR(outp);
  1736. if (outp->encoder->encoder_type == DRM_MODE_ENCODER_DPMST) {
  1737. outp->flush_disable = true;
  1738. atom->flush_disable = true;
  1739. }
  1740. outp->clr.ctrl = true;
  1741. atom->lock_core = true;
  1742. }
  1743. return 0;
  1744. }
  1745. static int
  1746. nv50_disp_outp_atomic_check_set(struct nv50_atom *atom,
  1747. struct drm_connector_state *connector_state)
  1748. {
  1749. struct drm_encoder *encoder = connector_state->best_encoder;
  1750. struct drm_crtc_state *new_crtc_state;
  1751. struct drm_crtc *crtc;
  1752. struct nv50_outp_atom *outp;
  1753. if (!(crtc = connector_state->crtc))
  1754. return 0;
  1755. new_crtc_state = drm_atomic_get_new_crtc_state(&atom->state, crtc);
  1756. if (new_crtc_state->active && drm_atomic_crtc_needs_modeset(new_crtc_state)) {
  1757. outp = nv50_disp_outp_atomic_add(atom, encoder);
  1758. if (IS_ERR(outp))
  1759. return PTR_ERR(outp);
  1760. outp->set.ctrl = true;
  1761. atom->lock_core = true;
  1762. }
  1763. return 0;
  1764. }
  1765. static int
  1766. nv50_disp_atomic_check(struct drm_device *dev, struct drm_atomic_state *state)
  1767. {
  1768. struct nv50_atom *atom = nv50_atom(state);
  1769. struct drm_connector_state *old_connector_state, *new_connector_state;
  1770. struct drm_connector *connector;
  1771. struct drm_crtc_state *new_crtc_state;
  1772. struct drm_crtc *crtc;
  1773. int ret, i;
  1774. /* We need to handle colour management on a per-plane basis. */
  1775. for_each_new_crtc_in_state(state, crtc, new_crtc_state, i) {
  1776. if (new_crtc_state->color_mgmt_changed) {
  1777. ret = drm_atomic_add_affected_planes(state, crtc);
  1778. if (ret)
  1779. return ret;
  1780. }
  1781. }
  1782. ret = drm_atomic_helper_check(dev, state);
  1783. if (ret)
  1784. return ret;
  1785. for_each_oldnew_connector_in_state(state, connector, old_connector_state, new_connector_state, i) {
  1786. ret = nv50_disp_outp_atomic_check_clr(atom, old_connector_state);
  1787. if (ret)
  1788. return ret;
  1789. ret = nv50_disp_outp_atomic_check_set(atom, new_connector_state);
  1790. if (ret)
  1791. return ret;
  1792. }
  1793. return 0;
  1794. }
  1795. static void
  1796. nv50_disp_atomic_state_clear(struct drm_atomic_state *state)
  1797. {
  1798. struct nv50_atom *atom = nv50_atom(state);
  1799. struct nv50_outp_atom *outp, *outt;
  1800. list_for_each_entry_safe(outp, outt, &atom->outp, head) {
  1801. list_del(&outp->head);
  1802. kfree(outp);
  1803. }
  1804. drm_atomic_state_default_clear(state);
  1805. }
  1806. static void
  1807. nv50_disp_atomic_state_free(struct drm_atomic_state *state)
  1808. {
  1809. struct nv50_atom *atom = nv50_atom(state);
  1810. drm_atomic_state_default_release(&atom->state);
  1811. kfree(atom);
  1812. }
  1813. static struct drm_atomic_state *
  1814. nv50_disp_atomic_state_alloc(struct drm_device *dev)
  1815. {
  1816. struct nv50_atom *atom;
  1817. if (!(atom = kzalloc(sizeof(*atom), GFP_KERNEL)) ||
  1818. drm_atomic_state_init(dev, &atom->state) < 0) {
  1819. kfree(atom);
  1820. return NULL;
  1821. }
  1822. INIT_LIST_HEAD(&atom->outp);
  1823. return &atom->state;
  1824. }
  1825. static const struct drm_mode_config_funcs
  1826. nv50_disp_func = {
  1827. .fb_create = nouveau_user_framebuffer_create,
  1828. .output_poll_changed = nouveau_fbcon_output_poll_changed,
  1829. .atomic_check = nv50_disp_atomic_check,
  1830. .atomic_commit = nv50_disp_atomic_commit,
  1831. .atomic_state_alloc = nv50_disp_atomic_state_alloc,
  1832. .atomic_state_clear = nv50_disp_atomic_state_clear,
  1833. .atomic_state_free = nv50_disp_atomic_state_free,
  1834. };
  1835. /******************************************************************************
  1836. * Init
  1837. *****************************************************************************/
  1838. void
  1839. nv50_display_fini(struct drm_device *dev)
  1840. {
  1841. struct nouveau_encoder *nv_encoder;
  1842. struct drm_encoder *encoder;
  1843. struct drm_plane *plane;
  1844. drm_for_each_plane(plane, dev) {
  1845. struct nv50_wndw *wndw = nv50_wndw(plane);
  1846. if (plane->funcs != &nv50_wndw)
  1847. continue;
  1848. nv50_wndw_fini(wndw);
  1849. }
  1850. list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
  1851. if (encoder->encoder_type != DRM_MODE_ENCODER_DPMST) {
  1852. nv_encoder = nouveau_encoder(encoder);
  1853. nv50_mstm_fini(nv_encoder->dp.mstm);
  1854. }
  1855. }
  1856. }
  1857. int
  1858. nv50_display_init(struct drm_device *dev)
  1859. {
  1860. struct nv50_core *core = nv50_disp(dev)->core;
  1861. struct drm_encoder *encoder;
  1862. struct drm_plane *plane;
  1863. core->func->init(core);
  1864. list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
  1865. if (encoder->encoder_type != DRM_MODE_ENCODER_DPMST) {
  1866. struct nouveau_encoder *nv_encoder =
  1867. nouveau_encoder(encoder);
  1868. nv50_mstm_init(nv_encoder->dp.mstm);
  1869. }
  1870. }
  1871. drm_for_each_plane(plane, dev) {
  1872. struct nv50_wndw *wndw = nv50_wndw(plane);
  1873. if (plane->funcs != &nv50_wndw)
  1874. continue;
  1875. nv50_wndw_init(wndw);
  1876. }
  1877. return 0;
  1878. }
  1879. void
  1880. nv50_display_destroy(struct drm_device *dev)
  1881. {
  1882. struct nv50_disp *disp = nv50_disp(dev);
  1883. nv50_core_del(&disp->core);
  1884. nouveau_bo_unmap(disp->sync);
  1885. if (disp->sync)
  1886. nouveau_bo_unpin(disp->sync);
  1887. nouveau_bo_ref(NULL, &disp->sync);
  1888. nouveau_display(dev)->priv = NULL;
  1889. kfree(disp);
  1890. }
  1891. int
  1892. nv50_display_create(struct drm_device *dev)
  1893. {
  1894. struct nvif_device *device = &nouveau_drm(dev)->client.device;
  1895. struct nouveau_drm *drm = nouveau_drm(dev);
  1896. struct dcb_table *dcb = &drm->vbios.dcb;
  1897. struct drm_connector *connector, *tmp;
  1898. struct nv50_disp *disp;
  1899. struct dcb_output *dcbe;
  1900. int crtcs, ret, i;
  1901. disp = kzalloc(sizeof(*disp), GFP_KERNEL);
  1902. if (!disp)
  1903. return -ENOMEM;
  1904. mutex_init(&disp->mutex);
  1905. nouveau_display(dev)->priv = disp;
  1906. nouveau_display(dev)->dtor = nv50_display_destroy;
  1907. nouveau_display(dev)->init = nv50_display_init;
  1908. nouveau_display(dev)->fini = nv50_display_fini;
  1909. disp->disp = &nouveau_display(dev)->disp;
  1910. dev->mode_config.funcs = &nv50_disp_func;
  1911. dev->mode_config.quirk_addfb_prefer_xbgr_30bpp = true;
  1912. /* small shared memory area we use for notifiers and semaphores */
  1913. ret = nouveau_bo_new(&drm->client, 4096, 0x1000, TTM_PL_FLAG_VRAM,
  1914. 0, 0x0000, NULL, NULL, &disp->sync);
  1915. if (!ret) {
  1916. ret = nouveau_bo_pin(disp->sync, TTM_PL_FLAG_VRAM, true);
  1917. if (!ret) {
  1918. ret = nouveau_bo_map(disp->sync);
  1919. if (ret)
  1920. nouveau_bo_unpin(disp->sync);
  1921. }
  1922. if (ret)
  1923. nouveau_bo_ref(NULL, &disp->sync);
  1924. }
  1925. if (ret)
  1926. goto out;
  1927. /* allocate master evo channel */
  1928. ret = nv50_core_new(drm, &disp->core);
  1929. if (ret)
  1930. goto out;
  1931. /* create crtc objects to represent the hw heads */
  1932. if (disp->disp->object.oclass >= GV100_DISP)
  1933. crtcs = nvif_rd32(&device->object, 0x610060) & 0xff;
  1934. else
  1935. if (disp->disp->object.oclass >= GF110_DISP)
  1936. crtcs = nvif_rd32(&device->object, 0x612004) & 0xf;
  1937. else
  1938. crtcs = 0x3;
  1939. for (i = 0; i < fls(crtcs); i++) {
  1940. if (!(crtcs & (1 << i)))
  1941. continue;
  1942. ret = nv50_head_create(dev, i);
  1943. if (ret)
  1944. goto out;
  1945. }
  1946. /* create encoder/connector objects based on VBIOS DCB table */
  1947. for (i = 0, dcbe = &dcb->entry[0]; i < dcb->entries; i++, dcbe++) {
  1948. connector = nouveau_connector_create(dev, dcbe->connector);
  1949. if (IS_ERR(connector))
  1950. continue;
  1951. if (dcbe->location == DCB_LOC_ON_CHIP) {
  1952. switch (dcbe->type) {
  1953. case DCB_OUTPUT_TMDS:
  1954. case DCB_OUTPUT_LVDS:
  1955. case DCB_OUTPUT_DP:
  1956. ret = nv50_sor_create(connector, dcbe);
  1957. break;
  1958. case DCB_OUTPUT_ANALOG:
  1959. ret = nv50_dac_create(connector, dcbe);
  1960. break;
  1961. default:
  1962. ret = -ENODEV;
  1963. break;
  1964. }
  1965. } else {
  1966. ret = nv50_pior_create(connector, dcbe);
  1967. }
  1968. if (ret) {
  1969. NV_WARN(drm, "failed to create encoder %d/%d/%d: %d\n",
  1970. dcbe->location, dcbe->type,
  1971. ffs(dcbe->or) - 1, ret);
  1972. ret = 0;
  1973. }
  1974. }
  1975. /* cull any connectors we created that don't have an encoder */
  1976. list_for_each_entry_safe(connector, tmp, &dev->mode_config.connector_list, head) {
  1977. if (connector->encoder_ids[0])
  1978. continue;
  1979. NV_WARN(drm, "%s has no encoders, removing\n",
  1980. connector->name);
  1981. connector->funcs->destroy(connector);
  1982. }
  1983. /* Disable vblank irqs aggressively for power-saving, safe on nv50+ */
  1984. dev->vblank_disable_immediate = true;
  1985. out:
  1986. if (ret)
  1987. nv50_display_destroy(dev);
  1988. return ret;
  1989. }