nvd0_display.c 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473
  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 "drmP.h"
  26. #include "drm_crtc_helper.h"
  27. #include "nouveau_drv.h"
  28. #include "nouveau_connector.h"
  29. #include "nouveau_encoder.h"
  30. #include "nouveau_crtc.h"
  31. #include "nouveau_dma.h"
  32. #include "nouveau_fb.h"
  33. #include "nv50_display.h"
  34. struct nvd0_display {
  35. struct nouveau_gpuobj *mem;
  36. struct {
  37. dma_addr_t handle;
  38. u32 *ptr;
  39. } evo[1];
  40. struct tasklet_struct tasklet;
  41. u32 modeset;
  42. };
  43. static struct nvd0_display *
  44. nvd0_display(struct drm_device *dev)
  45. {
  46. struct drm_nouveau_private *dev_priv = dev->dev_private;
  47. return dev_priv->engine.display.priv;
  48. }
  49. static inline int
  50. evo_icmd(struct drm_device *dev, int id, u32 mthd, u32 data)
  51. {
  52. int ret = 0;
  53. nv_mask(dev, 0x610700 + (id * 0x10), 0x00000001, 0x00000001);
  54. nv_wr32(dev, 0x610704 + (id * 0x10), data);
  55. nv_mask(dev, 0x610704 + (id * 0x10), 0x80000ffc, 0x80000000 | mthd);
  56. if (!nv_wait(dev, 0x610704 + (id * 0x10), 0x80000000, 0x00000000))
  57. ret = -EBUSY;
  58. nv_mask(dev, 0x610700 + (id * 0x10), 0x00000001, 0x00000000);
  59. return ret;
  60. }
  61. static u32 *
  62. evo_wait(struct drm_device *dev, int id, int nr)
  63. {
  64. struct nvd0_display *disp = nvd0_display(dev);
  65. u32 put = nv_rd32(dev, 0x640000 + (id * 0x1000)) / 4;
  66. if (put + nr >= (PAGE_SIZE / 4)) {
  67. disp->evo[id].ptr[put] = 0x20000000;
  68. nv_wr32(dev, 0x640000 + (id * 0x1000), 0x00000000);
  69. if (!nv_wait(dev, 0x640004 + (id * 0x1000), ~0, 0x00000000)) {
  70. NV_ERROR(dev, "evo %d dma stalled\n", id);
  71. return NULL;
  72. }
  73. put = 0;
  74. }
  75. return disp->evo[id].ptr + put;
  76. }
  77. static void
  78. evo_kick(u32 *push, struct drm_device *dev, int id)
  79. {
  80. struct nvd0_display *disp = nvd0_display(dev);
  81. nv_wr32(dev, 0x640000 + (id * 0x1000), (push - disp->evo[id].ptr) << 2);
  82. }
  83. #define evo_mthd(p,m,s) *((p)++) = (((s) << 18) | (m))
  84. #define evo_data(p,d) *((p)++) = (d)
  85. static struct drm_crtc *
  86. nvd0_display_crtc_get(struct drm_encoder *encoder)
  87. {
  88. return nouveau_encoder(encoder)->crtc;
  89. }
  90. /******************************************************************************
  91. * CRTC
  92. *****************************************************************************/
  93. static int
  94. nvd0_crtc_set_dither(struct nouveau_crtc *nv_crtc, bool on, bool update)
  95. {
  96. struct drm_device *dev = nv_crtc->base.dev;
  97. u32 *push, mode;
  98. mode = 0x00000000;
  99. if (on) {
  100. /* 0x11: 6bpc dynamic 2x2
  101. * 0x13: 8bpc dynamic 2x2
  102. * 0x19: 6bpc static 2x2
  103. * 0x1b: 8bpc static 2x2
  104. * 0x21: 6bpc temporal
  105. * 0x23: 8bpc temporal
  106. */
  107. mode = 0x00000011;
  108. }
  109. push = evo_wait(dev, 0, 4);
  110. if (push) {
  111. evo_mthd(push, 0x0490 + (nv_crtc->index * 0x300), 1);
  112. evo_data(push, mode);
  113. if (update) {
  114. evo_mthd(push, 0x0080, 1);
  115. evo_data(push, 0x00000000);
  116. }
  117. evo_kick(push, dev, 0);
  118. }
  119. return 0;
  120. }
  121. static int
  122. nvd0_crtc_set_scale(struct nouveau_crtc *nv_crtc, int type, bool update)
  123. {
  124. struct drm_display_mode *mode = &nv_crtc->base.mode;
  125. struct drm_device *dev = nv_crtc->base.dev;
  126. struct nouveau_connector *nv_connector;
  127. u32 *push, outX, outY;
  128. outX = mode->hdisplay;
  129. outY = mode->vdisplay;
  130. nv_connector = nouveau_crtc_connector_get(nv_crtc);
  131. if (nv_connector && nv_connector->native_mode) {
  132. struct drm_display_mode *native = nv_connector->native_mode;
  133. u32 xratio = (native->hdisplay << 19) / mode->hdisplay;
  134. u32 yratio = (native->vdisplay << 19) / mode->vdisplay;
  135. switch (type) {
  136. case DRM_MODE_SCALE_ASPECT:
  137. if (xratio > yratio) {
  138. outX = (mode->hdisplay * yratio) >> 19;
  139. outY = (mode->vdisplay * yratio) >> 19;
  140. } else {
  141. outX = (mode->hdisplay * xratio) >> 19;
  142. outY = (mode->vdisplay * xratio) >> 19;
  143. }
  144. break;
  145. case DRM_MODE_SCALE_FULLSCREEN:
  146. outX = native->hdisplay;
  147. outY = native->vdisplay;
  148. break;
  149. default:
  150. break;
  151. }
  152. }
  153. push = evo_wait(dev, 0, 16);
  154. if (push) {
  155. evo_mthd(push, 0x04c0 + (nv_crtc->index * 0x300), 3);
  156. evo_data(push, (outY << 16) | outX);
  157. evo_data(push, (outY << 16) | outX);
  158. evo_data(push, (outY << 16) | outX);
  159. evo_mthd(push, 0x0494 + (nv_crtc->index * 0x300), 1);
  160. evo_data(push, 0x00000000);
  161. evo_mthd(push, 0x04b8 + (nv_crtc->index * 0x300), 1);
  162. evo_data(push, (mode->vdisplay << 16) | mode->hdisplay);
  163. if (update) {
  164. evo_mthd(push, 0x0080, 1);
  165. evo_data(push, 0x00000000);
  166. }
  167. evo_kick(push, dev, 0);
  168. }
  169. return 0;
  170. }
  171. static int
  172. nvd0_crtc_set_image(struct nouveau_crtc *nv_crtc, struct drm_framebuffer *fb,
  173. int x, int y, bool update)
  174. {
  175. struct nouveau_framebuffer *nvfb = nouveau_framebuffer(fb);
  176. u32 *push;
  177. push = evo_wait(fb->dev, 0, 16);
  178. if (push) {
  179. evo_mthd(push, 0x0460 + (nv_crtc->index * 0x300), 1);
  180. evo_data(push, nvfb->nvbo->bo.offset >> 8);
  181. evo_mthd(push, 0x0468 + (nv_crtc->index * 0x300), 4);
  182. evo_data(push, (fb->height << 16) | fb->width);
  183. evo_data(push, nvfb->r_pitch);
  184. evo_data(push, nvfb->r_format);
  185. evo_data(push, nvfb->r_dma);
  186. evo_mthd(push, 0x04b0 + (nv_crtc->index * 0x300), 1);
  187. evo_data(push, (y << 16) | x);
  188. if (update) {
  189. evo_mthd(push, 0x0080, 1);
  190. evo_data(push, 0x00000000);
  191. }
  192. evo_kick(push, fb->dev, 0);
  193. }
  194. nv_crtc->fb.tile_flags = nvfb->r_dma;
  195. return 0;
  196. }
  197. static void
  198. nvd0_crtc_cursor_show(struct nouveau_crtc *nv_crtc, bool show, bool update)
  199. {
  200. struct drm_device *dev = nv_crtc->base.dev;
  201. u32 *push = evo_wait(dev, 0, 16);
  202. if (push) {
  203. if (show) {
  204. evo_mthd(push, 0x0480 + (nv_crtc->index * 0x300), 2);
  205. evo_data(push, 0x85000000);
  206. evo_data(push, nv_crtc->cursor.nvbo->bo.offset >> 8);
  207. evo_mthd(push, 0x048c + (nv_crtc->index * 0x300), 1);
  208. evo_data(push, NvEvoVRAM);
  209. } else {
  210. evo_mthd(push, 0x0480 + (nv_crtc->index * 0x300), 1);
  211. evo_data(push, 0x05000000);
  212. evo_mthd(push, 0x048c + (nv_crtc->index * 0x300), 1);
  213. evo_data(push, 0x00000000);
  214. }
  215. if (update) {
  216. evo_mthd(push, 0x0080, 1);
  217. evo_data(push, 0x00000000);
  218. }
  219. evo_kick(push, dev, 0);
  220. }
  221. }
  222. static void
  223. nvd0_crtc_dpms(struct drm_crtc *crtc, int mode)
  224. {
  225. }
  226. static void
  227. nvd0_crtc_prepare(struct drm_crtc *crtc)
  228. {
  229. struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc);
  230. u32 *push;
  231. push = evo_wait(crtc->dev, 0, 2);
  232. if (push) {
  233. evo_mthd(push, 0x0474 + (nv_crtc->index * 0x300), 1);
  234. evo_data(push, 0x00000000);
  235. evo_mthd(push, 0x0440 + (nv_crtc->index * 0x300), 1);
  236. evo_data(push, 0x03000000);
  237. evo_mthd(push, 0x045c + (nv_crtc->index * 0x300), 1);
  238. evo_data(push, 0x00000000);
  239. evo_kick(push, crtc->dev, 0);
  240. }
  241. nvd0_crtc_cursor_show(nv_crtc, false, false);
  242. }
  243. static void
  244. nvd0_crtc_commit(struct drm_crtc *crtc)
  245. {
  246. struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc);
  247. u32 *push;
  248. push = evo_wait(crtc->dev, 0, 32);
  249. if (push) {
  250. evo_mthd(push, 0x0474 + (nv_crtc->index * 0x300), 1);
  251. evo_data(push, nv_crtc->fb.tile_flags);
  252. evo_mthd(push, 0x0440 + (nv_crtc->index * 0x300), 4);
  253. evo_data(push, 0x83000000);
  254. evo_data(push, nv_crtc->lut.nvbo->bo.offset >> 8);
  255. evo_data(push, 0x00000000);
  256. evo_data(push, 0x00000000);
  257. evo_mthd(push, 0x045c + (nv_crtc->index * 0x300), 1);
  258. evo_data(push, NvEvoVRAM);
  259. evo_mthd(push, 0x0430 + (nv_crtc->index * 0x300), 1);
  260. evo_data(push, 0xffffff00);
  261. evo_kick(push, crtc->dev, 0);
  262. }
  263. nvd0_crtc_cursor_show(nv_crtc, nv_crtc->cursor.visible, true);
  264. }
  265. static bool
  266. nvd0_crtc_mode_fixup(struct drm_crtc *crtc, struct drm_display_mode *mode,
  267. struct drm_display_mode *adjusted_mode)
  268. {
  269. return true;
  270. }
  271. static int
  272. nvd0_crtc_swap_fbs(struct drm_crtc *crtc, struct drm_framebuffer *old_fb)
  273. {
  274. struct nouveau_framebuffer *nvfb = nouveau_framebuffer(crtc->fb);
  275. int ret;
  276. ret = nouveau_bo_pin(nvfb->nvbo, TTM_PL_FLAG_VRAM);
  277. if (ret)
  278. return ret;
  279. if (old_fb) {
  280. nvfb = nouveau_framebuffer(old_fb);
  281. nouveau_bo_unpin(nvfb->nvbo);
  282. }
  283. return 0;
  284. }
  285. static int
  286. nvd0_crtc_mode_set(struct drm_crtc *crtc, struct drm_display_mode *umode,
  287. struct drm_display_mode *mode, int x, int y,
  288. struct drm_framebuffer *old_fb)
  289. {
  290. struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc);
  291. struct nouveau_connector *nv_connector;
  292. u32 htotal = mode->htotal;
  293. u32 vtotal = mode->vtotal;
  294. u32 hsyncw = mode->hsync_end - mode->hsync_start - 1;
  295. u32 vsyncw = mode->vsync_end - mode->vsync_start - 1;
  296. u32 hfrntp = mode->hsync_start - mode->hdisplay;
  297. u32 vfrntp = mode->vsync_start - mode->vdisplay;
  298. u32 hbackp = mode->htotal - mode->hsync_end;
  299. u32 vbackp = mode->vtotal - mode->vsync_end;
  300. u32 hss2be = hsyncw + hbackp;
  301. u32 vss2be = vsyncw + vbackp;
  302. u32 hss2de = htotal - hfrntp;
  303. u32 vss2de = vtotal - vfrntp;
  304. u32 syncs, *push;
  305. int ret;
  306. syncs = 0x00000001;
  307. if (mode->flags & DRM_MODE_FLAG_NHSYNC)
  308. syncs |= 0x00000008;
  309. if (mode->flags & DRM_MODE_FLAG_NVSYNC)
  310. syncs |= 0x00000010;
  311. ret = nvd0_crtc_swap_fbs(crtc, old_fb);
  312. if (ret)
  313. return ret;
  314. push = evo_wait(crtc->dev, 0, 64);
  315. if (push) {
  316. evo_mthd(push, 0x0410 + (nv_crtc->index * 0x300), 5);
  317. evo_data(push, 0x00000000);
  318. evo_data(push, (vtotal << 16) | htotal);
  319. evo_data(push, (vsyncw << 16) | hsyncw);
  320. evo_data(push, (vss2be << 16) | hss2be);
  321. evo_data(push, (vss2de << 16) | hss2de);
  322. evo_mthd(push, 0x042c + (nv_crtc->index * 0x300), 1);
  323. evo_data(push, 0x00000000); /* ??? */
  324. evo_mthd(push, 0x0450 + (nv_crtc->index * 0x300), 3);
  325. evo_data(push, mode->clock * 1000);
  326. evo_data(push, 0x00200000); /* ??? */
  327. evo_data(push, mode->clock * 1000);
  328. evo_mthd(push, 0x0404 + (nv_crtc->index * 0x300), 1);
  329. evo_data(push, syncs);
  330. evo_kick(push, crtc->dev, 0);
  331. }
  332. nv_connector = nouveau_crtc_connector_get(nv_crtc);
  333. nvd0_crtc_set_dither(nv_crtc, nv_connector->use_dithering, false);
  334. nvd0_crtc_set_scale(nv_crtc, nv_connector->scaling_mode, false);
  335. nvd0_crtc_set_image(nv_crtc, crtc->fb, x, y, false);
  336. return 0;
  337. }
  338. static int
  339. nvd0_crtc_mode_set_base(struct drm_crtc *crtc, int x, int y,
  340. struct drm_framebuffer *old_fb)
  341. {
  342. struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc);
  343. int ret;
  344. if (!crtc->fb) {
  345. NV_DEBUG_KMS(crtc->dev, "No FB bound\n");
  346. return 0;
  347. }
  348. ret = nvd0_crtc_swap_fbs(crtc, old_fb);
  349. if (ret)
  350. return ret;
  351. nvd0_crtc_set_image(nv_crtc, crtc->fb, x, y, true);
  352. return 0;
  353. }
  354. static int
  355. nvd0_crtc_mode_set_base_atomic(struct drm_crtc *crtc,
  356. struct drm_framebuffer *fb, int x, int y,
  357. enum mode_set_atomic state)
  358. {
  359. struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc);
  360. nvd0_crtc_set_image(nv_crtc, fb, x, y, true);
  361. return 0;
  362. }
  363. static void
  364. nvd0_crtc_lut_load(struct drm_crtc *crtc)
  365. {
  366. struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc);
  367. void __iomem *lut = nvbo_kmap_obj_iovirtual(nv_crtc->lut.nvbo);
  368. int i;
  369. for (i = 0; i < 256; i++) {
  370. writew(0x6000 + (nv_crtc->lut.r[i] >> 2), lut + (i * 0x20) + 0);
  371. writew(0x6000 + (nv_crtc->lut.g[i] >> 2), lut + (i * 0x20) + 2);
  372. writew(0x6000 + (nv_crtc->lut.b[i] >> 2), lut + (i * 0x20) + 4);
  373. }
  374. }
  375. static int
  376. nvd0_crtc_cursor_set(struct drm_crtc *crtc, struct drm_file *file_priv,
  377. uint32_t handle, uint32_t width, uint32_t height)
  378. {
  379. struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc);
  380. struct drm_device *dev = crtc->dev;
  381. struct drm_gem_object *gem;
  382. struct nouveau_bo *nvbo;
  383. bool visible = (handle != 0);
  384. int i, ret = 0;
  385. if (visible) {
  386. if (width != 64 || height != 64)
  387. return -EINVAL;
  388. gem = drm_gem_object_lookup(dev, file_priv, handle);
  389. if (unlikely(!gem))
  390. return -ENOENT;
  391. nvbo = nouveau_gem_object(gem);
  392. ret = nouveau_bo_map(nvbo);
  393. if (ret == 0) {
  394. for (i = 0; i < 64 * 64; i++) {
  395. u32 v = nouveau_bo_rd32(nvbo, i);
  396. nouveau_bo_wr32(nv_crtc->cursor.nvbo, i, v);
  397. }
  398. nouveau_bo_unmap(nvbo);
  399. }
  400. drm_gem_object_unreference_unlocked(gem);
  401. }
  402. if (visible != nv_crtc->cursor.visible) {
  403. nvd0_crtc_cursor_show(nv_crtc, visible, true);
  404. nv_crtc->cursor.visible = visible;
  405. }
  406. return ret;
  407. }
  408. static int
  409. nvd0_crtc_cursor_move(struct drm_crtc *crtc, int x, int y)
  410. {
  411. struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc);
  412. const u32 data = (y << 16) | x;
  413. nv_wr32(crtc->dev, 0x64d084 + (nv_crtc->index * 0x1000), data);
  414. nv_wr32(crtc->dev, 0x64d080 + (nv_crtc->index * 0x1000), 0x00000000);
  415. return 0;
  416. }
  417. static void
  418. nvd0_crtc_gamma_set(struct drm_crtc *crtc, u16 *r, u16 *g, u16 *b,
  419. uint32_t start, uint32_t size)
  420. {
  421. struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc);
  422. u32 end = max(start + size, (u32)256);
  423. u32 i;
  424. for (i = start; i < end; i++) {
  425. nv_crtc->lut.r[i] = r[i];
  426. nv_crtc->lut.g[i] = g[i];
  427. nv_crtc->lut.b[i] = b[i];
  428. }
  429. nvd0_crtc_lut_load(crtc);
  430. }
  431. static void
  432. nvd0_crtc_destroy(struct drm_crtc *crtc)
  433. {
  434. struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc);
  435. nouveau_bo_unmap(nv_crtc->cursor.nvbo);
  436. nouveau_bo_ref(NULL, &nv_crtc->cursor.nvbo);
  437. nouveau_bo_unmap(nv_crtc->lut.nvbo);
  438. nouveau_bo_ref(NULL, &nv_crtc->lut.nvbo);
  439. drm_crtc_cleanup(crtc);
  440. kfree(crtc);
  441. }
  442. static const struct drm_crtc_helper_funcs nvd0_crtc_hfunc = {
  443. .dpms = nvd0_crtc_dpms,
  444. .prepare = nvd0_crtc_prepare,
  445. .commit = nvd0_crtc_commit,
  446. .mode_fixup = nvd0_crtc_mode_fixup,
  447. .mode_set = nvd0_crtc_mode_set,
  448. .mode_set_base = nvd0_crtc_mode_set_base,
  449. .mode_set_base_atomic = nvd0_crtc_mode_set_base_atomic,
  450. .load_lut = nvd0_crtc_lut_load,
  451. };
  452. static const struct drm_crtc_funcs nvd0_crtc_func = {
  453. .cursor_set = nvd0_crtc_cursor_set,
  454. .cursor_move = nvd0_crtc_cursor_move,
  455. .gamma_set = nvd0_crtc_gamma_set,
  456. .set_config = drm_crtc_helper_set_config,
  457. .destroy = nvd0_crtc_destroy,
  458. };
  459. static void
  460. nvd0_cursor_set_pos(struct nouveau_crtc *nv_crtc, int x, int y)
  461. {
  462. }
  463. static void
  464. nvd0_cursor_set_offset(struct nouveau_crtc *nv_crtc, uint32_t offset)
  465. {
  466. }
  467. static int
  468. nvd0_crtc_create(struct drm_device *dev, int index)
  469. {
  470. struct nouveau_crtc *nv_crtc;
  471. struct drm_crtc *crtc;
  472. int ret, i;
  473. nv_crtc = kzalloc(sizeof(*nv_crtc), GFP_KERNEL);
  474. if (!nv_crtc)
  475. return -ENOMEM;
  476. nv_crtc->index = index;
  477. nv_crtc->set_dither = nvd0_crtc_set_dither;
  478. nv_crtc->set_scale = nvd0_crtc_set_scale;
  479. nv_crtc->cursor.set_offset = nvd0_cursor_set_offset;
  480. nv_crtc->cursor.set_pos = nvd0_cursor_set_pos;
  481. for (i = 0; i < 256; i++) {
  482. nv_crtc->lut.r[i] = i << 8;
  483. nv_crtc->lut.g[i] = i << 8;
  484. nv_crtc->lut.b[i] = i << 8;
  485. }
  486. crtc = &nv_crtc->base;
  487. drm_crtc_init(dev, crtc, &nvd0_crtc_func);
  488. drm_crtc_helper_add(crtc, &nvd0_crtc_hfunc);
  489. drm_mode_crtc_set_gamma_size(crtc, 256);
  490. ret = nouveau_bo_new(dev, 64 * 64 * 4, 0x100, TTM_PL_FLAG_VRAM,
  491. 0, 0x0000, &nv_crtc->cursor.nvbo);
  492. if (!ret) {
  493. ret = nouveau_bo_pin(nv_crtc->cursor.nvbo, TTM_PL_FLAG_VRAM);
  494. if (!ret)
  495. ret = nouveau_bo_map(nv_crtc->cursor.nvbo);
  496. if (ret)
  497. nouveau_bo_ref(NULL, &nv_crtc->cursor.nvbo);
  498. }
  499. if (ret)
  500. goto out;
  501. ret = nouveau_bo_new(dev, 8192, 0x100, TTM_PL_FLAG_VRAM,
  502. 0, 0x0000, &nv_crtc->lut.nvbo);
  503. if (!ret) {
  504. ret = nouveau_bo_pin(nv_crtc->lut.nvbo, TTM_PL_FLAG_VRAM);
  505. if (!ret)
  506. ret = nouveau_bo_map(nv_crtc->lut.nvbo);
  507. if (ret)
  508. nouveau_bo_ref(NULL, &nv_crtc->lut.nvbo);
  509. }
  510. if (ret)
  511. goto out;
  512. nvd0_crtc_lut_load(crtc);
  513. out:
  514. if (ret)
  515. nvd0_crtc_destroy(crtc);
  516. return ret;
  517. }
  518. /******************************************************************************
  519. * DAC
  520. *****************************************************************************/
  521. static void
  522. nvd0_dac_dpms(struct drm_encoder *encoder, int mode)
  523. {
  524. struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
  525. struct drm_device *dev = encoder->dev;
  526. int or = nv_encoder->or;
  527. u32 dpms_ctrl;
  528. dpms_ctrl = 0x80000000;
  529. if (mode == DRM_MODE_DPMS_STANDBY || mode == DRM_MODE_DPMS_OFF)
  530. dpms_ctrl |= 0x00000001;
  531. if (mode == DRM_MODE_DPMS_SUSPEND || mode == DRM_MODE_DPMS_OFF)
  532. dpms_ctrl |= 0x00000004;
  533. nv_wait(dev, 0x61a004 + (or * 0x0800), 0x80000000, 0x00000000);
  534. nv_mask(dev, 0x61a004 + (or * 0x0800), 0xc000007f, dpms_ctrl);
  535. nv_wait(dev, 0x61a004 + (or * 0x0800), 0x80000000, 0x00000000);
  536. }
  537. static bool
  538. nvd0_dac_mode_fixup(struct drm_encoder *encoder, struct drm_display_mode *mode,
  539. struct drm_display_mode *adjusted_mode)
  540. {
  541. struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
  542. struct nouveau_connector *nv_connector;
  543. nv_connector = nouveau_encoder_connector_get(nv_encoder);
  544. if (nv_connector && nv_connector->native_mode) {
  545. if (nv_connector->scaling_mode != DRM_MODE_SCALE_NONE) {
  546. int id = adjusted_mode->base.id;
  547. *adjusted_mode = *nv_connector->native_mode;
  548. adjusted_mode->base.id = id;
  549. }
  550. }
  551. return true;
  552. }
  553. static void
  554. nvd0_dac_prepare(struct drm_encoder *encoder)
  555. {
  556. }
  557. static void
  558. nvd0_dac_commit(struct drm_encoder *encoder)
  559. {
  560. }
  561. static void
  562. nvd0_dac_mode_set(struct drm_encoder *encoder, struct drm_display_mode *mode,
  563. struct drm_display_mode *adjusted_mode)
  564. {
  565. struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
  566. struct nouveau_crtc *nv_crtc = nouveau_crtc(encoder->crtc);
  567. u32 *push;
  568. nvd0_dac_dpms(encoder, DRM_MODE_DPMS_ON);
  569. push = evo_wait(encoder->dev, 0, 4);
  570. if (push) {
  571. evo_mthd(push, 0x0180 + (nv_encoder->or * 0x20), 2);
  572. evo_data(push, 1 << nv_crtc->index);
  573. evo_data(push, 0x00ff);
  574. evo_kick(push, encoder->dev, 0);
  575. }
  576. nv_encoder->crtc = encoder->crtc;
  577. }
  578. static void
  579. nvd0_dac_disconnect(struct drm_encoder *encoder)
  580. {
  581. struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
  582. struct drm_device *dev = encoder->dev;
  583. u32 *push;
  584. if (nv_encoder->crtc) {
  585. nvd0_crtc_prepare(nv_encoder->crtc);
  586. push = evo_wait(dev, 0, 4);
  587. if (push) {
  588. evo_mthd(push, 0x0180 + (nv_encoder->or * 0x20), 1);
  589. evo_data(push, 0x00000000);
  590. evo_mthd(push, 0x0080, 1);
  591. evo_data(push, 0x00000000);
  592. evo_kick(push, dev, 0);
  593. }
  594. nv_encoder->crtc = NULL;
  595. }
  596. }
  597. static enum drm_connector_status
  598. nvd0_dac_detect(struct drm_encoder *encoder, struct drm_connector *connector)
  599. {
  600. enum drm_connector_status status = connector_status_disconnected;
  601. struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
  602. struct drm_device *dev = encoder->dev;
  603. int or = nv_encoder->or;
  604. u32 load;
  605. nv_wr32(dev, 0x61a00c + (or * 0x800), 0x00100000);
  606. udelay(9500);
  607. nv_wr32(dev, 0x61a00c + (or * 0x800), 0x80000000);
  608. load = nv_rd32(dev, 0x61a00c + (or * 0x800));
  609. if ((load & 0x38000000) == 0x38000000)
  610. status = connector_status_connected;
  611. nv_wr32(dev, 0x61a00c + (or * 0x800), 0x00000000);
  612. return status;
  613. }
  614. static void
  615. nvd0_dac_destroy(struct drm_encoder *encoder)
  616. {
  617. drm_encoder_cleanup(encoder);
  618. kfree(encoder);
  619. }
  620. static const struct drm_encoder_helper_funcs nvd0_dac_hfunc = {
  621. .dpms = nvd0_dac_dpms,
  622. .mode_fixup = nvd0_dac_mode_fixup,
  623. .prepare = nvd0_dac_prepare,
  624. .commit = nvd0_dac_commit,
  625. .mode_set = nvd0_dac_mode_set,
  626. .disable = nvd0_dac_disconnect,
  627. .get_crtc = nvd0_display_crtc_get,
  628. .detect = nvd0_dac_detect
  629. };
  630. static const struct drm_encoder_funcs nvd0_dac_func = {
  631. .destroy = nvd0_dac_destroy,
  632. };
  633. static int
  634. nvd0_dac_create(struct drm_connector *connector, struct dcb_entry *dcbe)
  635. {
  636. struct drm_device *dev = connector->dev;
  637. struct nouveau_encoder *nv_encoder;
  638. struct drm_encoder *encoder;
  639. nv_encoder = kzalloc(sizeof(*nv_encoder), GFP_KERNEL);
  640. if (!nv_encoder)
  641. return -ENOMEM;
  642. nv_encoder->dcb = dcbe;
  643. nv_encoder->or = ffs(dcbe->or) - 1;
  644. encoder = to_drm_encoder(nv_encoder);
  645. encoder->possible_crtcs = dcbe->heads;
  646. encoder->possible_clones = 0;
  647. drm_encoder_init(dev, encoder, &nvd0_dac_func, DRM_MODE_ENCODER_DAC);
  648. drm_encoder_helper_add(encoder, &nvd0_dac_hfunc);
  649. drm_mode_connector_attach_encoder(connector, encoder);
  650. return 0;
  651. }
  652. /******************************************************************************
  653. * SOR
  654. *****************************************************************************/
  655. static void
  656. nvd0_sor_dpms(struct drm_encoder *encoder, int mode)
  657. {
  658. struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
  659. struct drm_device *dev = encoder->dev;
  660. struct drm_encoder *partner;
  661. int or = nv_encoder->or;
  662. u32 dpms_ctrl;
  663. nv_encoder->last_dpms = mode;
  664. list_for_each_entry(partner, &dev->mode_config.encoder_list, head) {
  665. struct nouveau_encoder *nv_partner = nouveau_encoder(partner);
  666. if (partner->encoder_type != DRM_MODE_ENCODER_TMDS)
  667. continue;
  668. if (nv_partner != nv_encoder &&
  669. nv_partner->dcb->or == nv_encoder->or) {
  670. if (nv_partner->last_dpms == DRM_MODE_DPMS_ON)
  671. return;
  672. break;
  673. }
  674. }
  675. dpms_ctrl = (mode == DRM_MODE_DPMS_ON);
  676. dpms_ctrl |= 0x80000000;
  677. nv_wait(dev, 0x61c004 + (or * 0x0800), 0x80000000, 0x00000000);
  678. nv_mask(dev, 0x61c004 + (or * 0x0800), 0x80000001, dpms_ctrl);
  679. nv_wait(dev, 0x61c004 + (or * 0x0800), 0x80000000, 0x00000000);
  680. nv_wait(dev, 0x61c030 + (or * 0x0800), 0x10000000, 0x00000000);
  681. }
  682. static bool
  683. nvd0_sor_mode_fixup(struct drm_encoder *encoder, struct drm_display_mode *mode,
  684. struct drm_display_mode *adjusted_mode)
  685. {
  686. struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
  687. struct nouveau_connector *nv_connector;
  688. nv_connector = nouveau_encoder_connector_get(nv_encoder);
  689. if (nv_connector && nv_connector->native_mode) {
  690. if (nv_connector->scaling_mode != DRM_MODE_SCALE_NONE) {
  691. int id = adjusted_mode->base.id;
  692. *adjusted_mode = *nv_connector->native_mode;
  693. adjusted_mode->base.id = id;
  694. }
  695. }
  696. return true;
  697. }
  698. static void
  699. nvd0_sor_prepare(struct drm_encoder *encoder)
  700. {
  701. }
  702. static void
  703. nvd0_sor_commit(struct drm_encoder *encoder)
  704. {
  705. }
  706. static void
  707. nvd0_sor_mode_set(struct drm_encoder *encoder, struct drm_display_mode *umode,
  708. struct drm_display_mode *mode)
  709. {
  710. struct drm_nouveau_private *dev_priv = encoder->dev->dev_private;
  711. struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
  712. struct nouveau_crtc *nv_crtc = nouveau_crtc(encoder->crtc);
  713. struct nouveau_connector *nv_connector;
  714. struct nvbios *bios = &dev_priv->vbios;
  715. u32 mode_ctrl = (1 << nv_crtc->index);
  716. u32 *push, or_config;
  717. nv_connector = nouveau_encoder_connector_get(nv_encoder);
  718. switch (nv_encoder->dcb->type) {
  719. case OUTPUT_TMDS:
  720. if (nv_encoder->dcb->sorconf.link & 1) {
  721. if (mode->clock < 165000)
  722. mode_ctrl |= 0x00000100;
  723. else
  724. mode_ctrl |= 0x00000500;
  725. } else {
  726. mode_ctrl |= 0x00000200;
  727. }
  728. or_config = (mode_ctrl & 0x00000f00) >> 8;
  729. if (mode->clock >= 165000)
  730. or_config |= 0x0100;
  731. break;
  732. case OUTPUT_LVDS:
  733. or_config = (mode_ctrl & 0x00000f00) >> 8;
  734. if (bios->fp_no_ddc) {
  735. if (bios->fp.dual_link)
  736. or_config |= 0x0100;
  737. if (bios->fp.if_is_24bit)
  738. or_config |= 0x0200;
  739. } else {
  740. if (nv_connector->dcb->type == DCB_CONNECTOR_LVDS_SPWG) {
  741. if (((u8 *)nv_connector->edid)[121] == 2)
  742. or_config |= 0x0100;
  743. } else
  744. if (mode->clock >= bios->fp.duallink_transition_clk) {
  745. or_config |= 0x0100;
  746. }
  747. if (or_config & 0x0100) {
  748. if (bios->fp.strapless_is_24bit & 2)
  749. or_config |= 0x0200;
  750. } else {
  751. if (bios->fp.strapless_is_24bit & 1)
  752. or_config |= 0x0200;
  753. }
  754. if (nv_connector->base.display_info.bpc == 8)
  755. or_config |= 0x0200;
  756. }
  757. break;
  758. default:
  759. BUG_ON(1);
  760. break;
  761. }
  762. nvd0_sor_dpms(encoder, DRM_MODE_DPMS_ON);
  763. push = evo_wait(encoder->dev, 0, 4);
  764. if (push) {
  765. evo_mthd(push, 0x0200 + (nv_encoder->or * 0x20), 2);
  766. evo_data(push, mode_ctrl);
  767. evo_data(push, or_config);
  768. evo_kick(push, encoder->dev, 0);
  769. }
  770. nv_encoder->crtc = encoder->crtc;
  771. }
  772. static void
  773. nvd0_sor_disconnect(struct drm_encoder *encoder)
  774. {
  775. struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
  776. struct drm_device *dev = encoder->dev;
  777. u32 *push;
  778. if (nv_encoder->crtc) {
  779. nvd0_crtc_prepare(nv_encoder->crtc);
  780. push = evo_wait(dev, 0, 4);
  781. if (push) {
  782. evo_mthd(push, 0x0200 + (nv_encoder->or * 0x20), 1);
  783. evo_data(push, 0x00000000);
  784. evo_mthd(push, 0x0080, 1);
  785. evo_data(push, 0x00000000);
  786. evo_kick(push, dev, 0);
  787. }
  788. nv_encoder->crtc = NULL;
  789. nv_encoder->last_dpms = DRM_MODE_DPMS_OFF;
  790. }
  791. }
  792. static void
  793. nvd0_sor_destroy(struct drm_encoder *encoder)
  794. {
  795. drm_encoder_cleanup(encoder);
  796. kfree(encoder);
  797. }
  798. static const struct drm_encoder_helper_funcs nvd0_sor_hfunc = {
  799. .dpms = nvd0_sor_dpms,
  800. .mode_fixup = nvd0_sor_mode_fixup,
  801. .prepare = nvd0_sor_prepare,
  802. .commit = nvd0_sor_commit,
  803. .mode_set = nvd0_sor_mode_set,
  804. .disable = nvd0_sor_disconnect,
  805. .get_crtc = nvd0_display_crtc_get,
  806. };
  807. static const struct drm_encoder_funcs nvd0_sor_func = {
  808. .destroy = nvd0_sor_destroy,
  809. };
  810. static int
  811. nvd0_sor_create(struct drm_connector *connector, struct dcb_entry *dcbe)
  812. {
  813. struct drm_device *dev = connector->dev;
  814. struct nouveau_encoder *nv_encoder;
  815. struct drm_encoder *encoder;
  816. nv_encoder = kzalloc(sizeof(*nv_encoder), GFP_KERNEL);
  817. if (!nv_encoder)
  818. return -ENOMEM;
  819. nv_encoder->dcb = dcbe;
  820. nv_encoder->or = ffs(dcbe->or) - 1;
  821. nv_encoder->last_dpms = DRM_MODE_DPMS_OFF;
  822. encoder = to_drm_encoder(nv_encoder);
  823. encoder->possible_crtcs = dcbe->heads;
  824. encoder->possible_clones = 0;
  825. drm_encoder_init(dev, encoder, &nvd0_sor_func, DRM_MODE_ENCODER_TMDS);
  826. drm_encoder_helper_add(encoder, &nvd0_sor_hfunc);
  827. drm_mode_connector_attach_encoder(connector, encoder);
  828. return 0;
  829. }
  830. /******************************************************************************
  831. * IRQ
  832. *****************************************************************************/
  833. static struct dcb_entry *
  834. lookup_dcb(struct drm_device *dev, int id, u32 mc)
  835. {
  836. struct drm_nouveau_private *dev_priv = dev->dev_private;
  837. int type, or, i;
  838. if (id < 4) {
  839. type = OUTPUT_ANALOG;
  840. or = id;
  841. } else {
  842. switch (mc & 0x00000f00) {
  843. case 0x00000000: type = OUTPUT_LVDS; break;
  844. case 0x00000100: type = OUTPUT_TMDS; break;
  845. case 0x00000200: type = OUTPUT_TMDS; break;
  846. case 0x00000500: type = OUTPUT_TMDS; break;
  847. default:
  848. NV_ERROR(dev, "PDISP: unknown SOR mc 0x%08x\n", mc);
  849. return NULL;
  850. }
  851. or = id - 4;
  852. }
  853. for (i = 0; i < dev_priv->vbios.dcb.entries; i++) {
  854. struct dcb_entry *dcb = &dev_priv->vbios.dcb.entry[i];
  855. if (dcb->type == type && (dcb->or & (1 << or)))
  856. return dcb;
  857. }
  858. NV_ERROR(dev, "PDISP: DCB for %d/0x%08x not found\n", id, mc);
  859. return NULL;
  860. }
  861. static void
  862. nvd0_display_unk1_handler(struct drm_device *dev, u32 crtc, u32 mask)
  863. {
  864. struct dcb_entry *dcb;
  865. int i;
  866. for (i = 0; mask && i < 8; i++) {
  867. u32 mcc = nv_rd32(dev, 0x640180 + (i * 0x20));
  868. if (!(mcc & (1 << crtc)))
  869. continue;
  870. dcb = lookup_dcb(dev, i, mcc);
  871. if (!dcb)
  872. continue;
  873. nouveau_bios_run_display_table(dev, 0x0000, -1, dcb, crtc);
  874. }
  875. nv_wr32(dev, 0x6101d4, 0x00000000);
  876. nv_wr32(dev, 0x6109d4, 0x00000000);
  877. nv_wr32(dev, 0x6101d0, 0x80000000);
  878. }
  879. static void
  880. nvd0_display_unk2_handler(struct drm_device *dev, u32 crtc, u32 mask)
  881. {
  882. struct dcb_entry *dcb;
  883. u32 or, tmp, pclk;
  884. int i;
  885. for (i = 0; mask && i < 8; i++) {
  886. u32 mcc = nv_rd32(dev, 0x640180 + (i * 0x20));
  887. if (!(mcc & (1 << crtc)))
  888. continue;
  889. dcb = lookup_dcb(dev, i, mcc);
  890. if (!dcb)
  891. continue;
  892. nouveau_bios_run_display_table(dev, 0x0000, -2, dcb, crtc);
  893. }
  894. pclk = nv_rd32(dev, 0x660450 + (crtc * 0x300)) / 1000;
  895. if (mask & 0x00010000) {
  896. nv50_crtc_set_clock(dev, crtc, pclk);
  897. }
  898. for (i = 0; mask && i < 8; i++) {
  899. u32 mcp = nv_rd32(dev, 0x660180 + (i * 0x20));
  900. u32 cfg = nv_rd32(dev, 0x660184 + (i * 0x20));
  901. if (!(mcp & (1 << crtc)))
  902. continue;
  903. dcb = lookup_dcb(dev, i, mcp);
  904. if (!dcb)
  905. continue;
  906. or = ffs(dcb->or) - 1;
  907. nouveau_bios_run_display_table(dev, cfg, pclk, dcb, crtc);
  908. nv_wr32(dev, 0x612200 + (crtc * 0x800), 0x00000000);
  909. switch (dcb->type) {
  910. case OUTPUT_ANALOG:
  911. nv_wr32(dev, 0x612280 + (or * 0x800), 0x00000000);
  912. break;
  913. case OUTPUT_TMDS:
  914. case OUTPUT_LVDS:
  915. if (cfg & 0x00000100)
  916. tmp = 0x00000101;
  917. else
  918. tmp = 0x00000000;
  919. nv_mask(dev, 0x612300 + (or * 0x800), 0x00000707, tmp);
  920. break;
  921. default:
  922. break;
  923. }
  924. break;
  925. }
  926. nv_wr32(dev, 0x6101d4, 0x00000000);
  927. nv_wr32(dev, 0x6109d4, 0x00000000);
  928. nv_wr32(dev, 0x6101d0, 0x80000000);
  929. }
  930. static void
  931. nvd0_display_unk4_handler(struct drm_device *dev, u32 crtc, u32 mask)
  932. {
  933. struct dcb_entry *dcb;
  934. int pclk, i;
  935. pclk = nv_rd32(dev, 0x660450 + (crtc * 0x300)) / 1000;
  936. for (i = 0; mask && i < 8; i++) {
  937. u32 mcp = nv_rd32(dev, 0x660180 + (i * 0x20));
  938. u32 cfg = nv_rd32(dev, 0x660184 + (i * 0x20));
  939. if (!(mcp & (1 << crtc)))
  940. continue;
  941. dcb = lookup_dcb(dev, i, mcp);
  942. if (!dcb)
  943. continue;
  944. nouveau_bios_run_display_table(dev, cfg, -pclk, dcb, crtc);
  945. }
  946. nv_wr32(dev, 0x6101d4, 0x00000000);
  947. nv_wr32(dev, 0x6109d4, 0x00000000);
  948. nv_wr32(dev, 0x6101d0, 0x80000000);
  949. }
  950. static void
  951. nvd0_display_bh(unsigned long data)
  952. {
  953. struct drm_device *dev = (struct drm_device *)data;
  954. struct nvd0_display *disp = nvd0_display(dev);
  955. u32 mask, crtc;
  956. int i;
  957. if (drm_debug & (DRM_UT_DRIVER | DRM_UT_KMS)) {
  958. NV_INFO(dev, "PDISP: modeset req %d\n", disp->modeset);
  959. NV_INFO(dev, " STAT: 0x%08x 0x%08x 0x%08x\n",
  960. nv_rd32(dev, 0x6101d0),
  961. nv_rd32(dev, 0x6101d4), nv_rd32(dev, 0x6109d4));
  962. for (i = 0; i < 8; i++) {
  963. NV_INFO(dev, " %s%d: 0x%08x 0x%08x\n",
  964. i < 4 ? "DAC" : "SOR", i,
  965. nv_rd32(dev, 0x640180 + (i * 0x20)),
  966. nv_rd32(dev, 0x660180 + (i * 0x20)));
  967. }
  968. }
  969. mask = nv_rd32(dev, 0x6101d4);
  970. crtc = 0;
  971. if (!mask) {
  972. mask = nv_rd32(dev, 0x6109d4);
  973. crtc = 1;
  974. }
  975. if (disp->modeset & 0x00000001)
  976. nvd0_display_unk1_handler(dev, crtc, mask);
  977. if (disp->modeset & 0x00000002)
  978. nvd0_display_unk2_handler(dev, crtc, mask);
  979. if (disp->modeset & 0x00000004)
  980. nvd0_display_unk4_handler(dev, crtc, mask);
  981. }
  982. static void
  983. nvd0_display_intr(struct drm_device *dev)
  984. {
  985. struct nvd0_display *disp = nvd0_display(dev);
  986. u32 intr = nv_rd32(dev, 0x610088);
  987. if (intr & 0x00000002) {
  988. u32 stat = nv_rd32(dev, 0x61009c);
  989. int chid = ffs(stat) - 1;
  990. if (chid >= 0) {
  991. u32 mthd = nv_rd32(dev, 0x6101f0 + (chid * 12));
  992. u32 data = nv_rd32(dev, 0x6101f4 + (chid * 12));
  993. u32 unkn = nv_rd32(dev, 0x6101f8 + (chid * 12));
  994. NV_INFO(dev, "EvoCh: chid %d mthd 0x%04x data 0x%08x "
  995. "0x%08x 0x%08x\n",
  996. chid, (mthd & 0x0000ffc), data, mthd, unkn);
  997. nv_wr32(dev, 0x61009c, (1 << chid));
  998. nv_wr32(dev, 0x6101f0 + (chid * 12), 0x90000000);
  999. }
  1000. intr &= ~0x00000002;
  1001. }
  1002. if (intr & 0x00100000) {
  1003. u32 stat = nv_rd32(dev, 0x6100ac);
  1004. if (stat & 0x00000007) {
  1005. disp->modeset = stat;
  1006. tasklet_schedule(&disp->tasklet);
  1007. nv_wr32(dev, 0x6100ac, (stat & 0x00000007));
  1008. stat &= ~0x00000007;
  1009. }
  1010. if (stat) {
  1011. NV_INFO(dev, "PDISP: unknown intr24 0x%08x\n", stat);
  1012. nv_wr32(dev, 0x6100ac, stat);
  1013. }
  1014. intr &= ~0x00100000;
  1015. }
  1016. if (intr & 0x01000000) {
  1017. u32 stat = nv_rd32(dev, 0x6100bc);
  1018. nv_wr32(dev, 0x6100bc, stat);
  1019. intr &= ~0x01000000;
  1020. }
  1021. if (intr & 0x02000000) {
  1022. u32 stat = nv_rd32(dev, 0x6108bc);
  1023. nv_wr32(dev, 0x6108bc, stat);
  1024. intr &= ~0x02000000;
  1025. }
  1026. if (intr)
  1027. NV_INFO(dev, "PDISP: unknown intr 0x%08x\n", intr);
  1028. }
  1029. /******************************************************************************
  1030. * Init
  1031. *****************************************************************************/
  1032. static void
  1033. nvd0_display_fini(struct drm_device *dev)
  1034. {
  1035. int i;
  1036. /* fini cursors */
  1037. for (i = 14; i >= 13; i--) {
  1038. if (!(nv_rd32(dev, 0x610490 + (i * 0x10)) & 0x00000001))
  1039. continue;
  1040. nv_mask(dev, 0x610490 + (i * 0x10), 0x00000001, 0x00000000);
  1041. nv_wait(dev, 0x610490 + (i * 0x10), 0x00010000, 0x00000000);
  1042. nv_mask(dev, 0x610090, 1 << i, 0x00000000);
  1043. nv_mask(dev, 0x6100a0, 1 << i, 0x00000000);
  1044. }
  1045. /* fini master */
  1046. if (nv_rd32(dev, 0x610490) & 0x00000010) {
  1047. nv_mask(dev, 0x610490, 0x00000010, 0x00000000);
  1048. nv_mask(dev, 0x610490, 0x00000003, 0x00000000);
  1049. nv_wait(dev, 0x610490, 0x80000000, 0x00000000);
  1050. nv_mask(dev, 0x610090, 0x00000001, 0x00000000);
  1051. nv_mask(dev, 0x6100a0, 0x00000001, 0x00000000);
  1052. }
  1053. }
  1054. int
  1055. nvd0_display_init(struct drm_device *dev)
  1056. {
  1057. struct nvd0_display *disp = nvd0_display(dev);
  1058. u32 *push;
  1059. int i;
  1060. if (nv_rd32(dev, 0x6100ac) & 0x00000100) {
  1061. nv_wr32(dev, 0x6100ac, 0x00000100);
  1062. nv_mask(dev, 0x6194e8, 0x00000001, 0x00000000);
  1063. if (!nv_wait(dev, 0x6194e8, 0x00000002, 0x00000000)) {
  1064. NV_ERROR(dev, "PDISP: 0x6194e8 0x%08x\n",
  1065. nv_rd32(dev, 0x6194e8));
  1066. return -EBUSY;
  1067. }
  1068. }
  1069. /* nfi what these are exactly, i do know that SOR_MODE_CTRL won't
  1070. * work at all unless you do the SOR part below.
  1071. */
  1072. for (i = 0; i < 3; i++) {
  1073. u32 dac = nv_rd32(dev, 0x61a000 + (i * 0x800));
  1074. nv_wr32(dev, 0x6101c0 + (i * 0x800), dac);
  1075. }
  1076. for (i = 0; i < 4; i++) {
  1077. u32 sor = nv_rd32(dev, 0x61c000 + (i * 0x800));
  1078. nv_wr32(dev, 0x6301c4 + (i * 0x800), sor);
  1079. }
  1080. for (i = 0; i < 2; i++) {
  1081. u32 crtc0 = nv_rd32(dev, 0x616104 + (i * 0x800));
  1082. u32 crtc1 = nv_rd32(dev, 0x616108 + (i * 0x800));
  1083. u32 crtc2 = nv_rd32(dev, 0x61610c + (i * 0x800));
  1084. nv_wr32(dev, 0x6101b4 + (i * 0x800), crtc0);
  1085. nv_wr32(dev, 0x6101b8 + (i * 0x800), crtc1);
  1086. nv_wr32(dev, 0x6101bc + (i * 0x800), crtc2);
  1087. }
  1088. /* point at our hash table / objects, enable interrupts */
  1089. nv_wr32(dev, 0x610010, (disp->mem->vinst >> 8) | 9);
  1090. nv_mask(dev, 0x6100b0, 0x00000307, 0x00000307);
  1091. /* init master */
  1092. nv_wr32(dev, 0x610494, (disp->evo[0].handle >> 8) | 3);
  1093. nv_wr32(dev, 0x610498, 0x00010000);
  1094. nv_wr32(dev, 0x61049c, 0x00000001);
  1095. nv_mask(dev, 0x610490, 0x00000010, 0x00000010);
  1096. nv_wr32(dev, 0x640000, 0x00000000);
  1097. nv_wr32(dev, 0x610490, 0x01000013);
  1098. if (!nv_wait(dev, 0x610490, 0x80000000, 0x00000000)) {
  1099. NV_ERROR(dev, "PDISP: master 0x%08x\n",
  1100. nv_rd32(dev, 0x610490));
  1101. return -EBUSY;
  1102. }
  1103. nv_mask(dev, 0x610090, 0x00000001, 0x00000001);
  1104. nv_mask(dev, 0x6100a0, 0x00000001, 0x00000001);
  1105. /* init cursors */
  1106. for (i = 13; i <= 14; i++) {
  1107. nv_wr32(dev, 0x610490 + (i * 0x10), 0x00000001);
  1108. if (!nv_wait(dev, 0x610490 + (i * 0x10), 0x00010000, 0x00010000)) {
  1109. NV_ERROR(dev, "PDISP: curs%d 0x%08x\n", i,
  1110. nv_rd32(dev, 0x610490 + (i * 0x10)));
  1111. return -EBUSY;
  1112. }
  1113. nv_mask(dev, 0x610090, 1 << i, 1 << i);
  1114. nv_mask(dev, 0x6100a0, 1 << i, 1 << i);
  1115. }
  1116. push = evo_wait(dev, 0, 32);
  1117. if (!push)
  1118. return -EBUSY;
  1119. evo_mthd(push, 0x0088, 1);
  1120. evo_data(push, NvEvoSync);
  1121. evo_mthd(push, 0x0084, 1);
  1122. evo_data(push, 0x00000000);
  1123. evo_mthd(push, 0x0084, 1);
  1124. evo_data(push, 0x80000000);
  1125. evo_mthd(push, 0x008c, 1);
  1126. evo_data(push, 0x00000000);
  1127. evo_kick(push, dev, 0);
  1128. return 0;
  1129. }
  1130. void
  1131. nvd0_display_destroy(struct drm_device *dev)
  1132. {
  1133. struct drm_nouveau_private *dev_priv = dev->dev_private;
  1134. struct nvd0_display *disp = nvd0_display(dev);
  1135. struct pci_dev *pdev = dev->pdev;
  1136. nvd0_display_fini(dev);
  1137. pci_free_consistent(pdev, PAGE_SIZE, disp->evo[0].ptr, disp->evo[0].handle);
  1138. nouveau_gpuobj_ref(NULL, &disp->mem);
  1139. nouveau_irq_unregister(dev, 26);
  1140. dev_priv->engine.display.priv = NULL;
  1141. kfree(disp);
  1142. }
  1143. int
  1144. nvd0_display_create(struct drm_device *dev)
  1145. {
  1146. struct drm_nouveau_private *dev_priv = dev->dev_private;
  1147. struct nouveau_instmem_engine *pinstmem = &dev_priv->engine.instmem;
  1148. struct dcb_table *dcb = &dev_priv->vbios.dcb;
  1149. struct drm_connector *connector, *tmp;
  1150. struct pci_dev *pdev = dev->pdev;
  1151. struct nvd0_display *disp;
  1152. struct dcb_entry *dcbe;
  1153. int ret, i;
  1154. disp = kzalloc(sizeof(*disp), GFP_KERNEL);
  1155. if (!disp)
  1156. return -ENOMEM;
  1157. dev_priv->engine.display.priv = disp;
  1158. /* create crtc objects to represent the hw heads */
  1159. for (i = 0; i < 2; i++) {
  1160. ret = nvd0_crtc_create(dev, i);
  1161. if (ret)
  1162. goto out;
  1163. }
  1164. /* create encoder/connector objects based on VBIOS DCB table */
  1165. for (i = 0, dcbe = &dcb->entry[0]; i < dcb->entries; i++, dcbe++) {
  1166. connector = nouveau_connector_create(dev, dcbe->connector);
  1167. if (IS_ERR(connector))
  1168. continue;
  1169. if (dcbe->location != DCB_LOC_ON_CHIP) {
  1170. NV_WARN(dev, "skipping off-chip encoder %d/%d\n",
  1171. dcbe->type, ffs(dcbe->or) - 1);
  1172. continue;
  1173. }
  1174. switch (dcbe->type) {
  1175. case OUTPUT_TMDS:
  1176. case OUTPUT_LVDS:
  1177. nvd0_sor_create(connector, dcbe);
  1178. break;
  1179. case OUTPUT_ANALOG:
  1180. nvd0_dac_create(connector, dcbe);
  1181. break;
  1182. default:
  1183. NV_WARN(dev, "skipping unsupported encoder %d/%d\n",
  1184. dcbe->type, ffs(dcbe->or) - 1);
  1185. continue;
  1186. }
  1187. }
  1188. /* cull any connectors we created that don't have an encoder */
  1189. list_for_each_entry_safe(connector, tmp, &dev->mode_config.connector_list, head) {
  1190. if (connector->encoder_ids[0])
  1191. continue;
  1192. NV_WARN(dev, "%s has no encoders, removing\n",
  1193. drm_get_connector_name(connector));
  1194. connector->funcs->destroy(connector);
  1195. }
  1196. /* setup interrupt handling */
  1197. tasklet_init(&disp->tasklet, nvd0_display_bh, (unsigned long)dev);
  1198. nouveau_irq_register(dev, 26, nvd0_display_intr);
  1199. /* hash table and dma objects for the memory areas we care about */
  1200. ret = nouveau_gpuobj_new(dev, NULL, 0x4000, 0x10000,
  1201. NVOBJ_FLAG_ZERO_ALLOC, &disp->mem);
  1202. if (ret)
  1203. goto out;
  1204. nv_wo32(disp->mem, 0x1000, 0x00000049);
  1205. nv_wo32(disp->mem, 0x1004, (disp->mem->vinst + 0x2000) >> 8);
  1206. nv_wo32(disp->mem, 0x1008, (disp->mem->vinst + 0x2fff) >> 8);
  1207. nv_wo32(disp->mem, 0x100c, 0x00000000);
  1208. nv_wo32(disp->mem, 0x1010, 0x00000000);
  1209. nv_wo32(disp->mem, 0x1014, 0x00000000);
  1210. nv_wo32(disp->mem, 0x0000, NvEvoSync);
  1211. nv_wo32(disp->mem, 0x0004, (0x1000 << 9) | 0x00000001);
  1212. nv_wo32(disp->mem, 0x1020, 0x00000049);
  1213. nv_wo32(disp->mem, 0x1024, 0x00000000);
  1214. nv_wo32(disp->mem, 0x1028, (dev_priv->vram_size - 1) >> 8);
  1215. nv_wo32(disp->mem, 0x102c, 0x00000000);
  1216. nv_wo32(disp->mem, 0x1030, 0x00000000);
  1217. nv_wo32(disp->mem, 0x1034, 0x00000000);
  1218. nv_wo32(disp->mem, 0x0008, NvEvoVRAM);
  1219. nv_wo32(disp->mem, 0x000c, (0x1020 << 9) | 0x00000001);
  1220. nv_wo32(disp->mem, 0x1040, 0x00000009);
  1221. nv_wo32(disp->mem, 0x1044, 0x00000000);
  1222. nv_wo32(disp->mem, 0x1048, (dev_priv->vram_size - 1) >> 8);
  1223. nv_wo32(disp->mem, 0x104c, 0x00000000);
  1224. nv_wo32(disp->mem, 0x1050, 0x00000000);
  1225. nv_wo32(disp->mem, 0x1054, 0x00000000);
  1226. nv_wo32(disp->mem, 0x0010, NvEvoVRAM_LP);
  1227. nv_wo32(disp->mem, 0x0014, (0x1040 << 9) | 0x00000001);
  1228. nv_wo32(disp->mem, 0x1060, 0x0fe00009);
  1229. nv_wo32(disp->mem, 0x1064, 0x00000000);
  1230. nv_wo32(disp->mem, 0x1068, (dev_priv->vram_size - 1) >> 8);
  1231. nv_wo32(disp->mem, 0x106c, 0x00000000);
  1232. nv_wo32(disp->mem, 0x1070, 0x00000000);
  1233. nv_wo32(disp->mem, 0x1074, 0x00000000);
  1234. nv_wo32(disp->mem, 0x0018, NvEvoFB32);
  1235. nv_wo32(disp->mem, 0x001c, (0x1060 << 9) | 0x00000001);
  1236. pinstmem->flush(dev);
  1237. /* push buffers for evo channels */
  1238. disp->evo[0].ptr =
  1239. pci_alloc_consistent(pdev, PAGE_SIZE, &disp->evo[0].handle);
  1240. if (!disp->evo[0].ptr) {
  1241. ret = -ENOMEM;
  1242. goto out;
  1243. }
  1244. ret = nvd0_display_init(dev);
  1245. if (ret)
  1246. goto out;
  1247. out:
  1248. if (ret)
  1249. nvd0_display_destroy(dev);
  1250. return ret;
  1251. }