nv50_display.c 61 KB

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