nv50_display.c 27 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015
  1. /*
  2. * Copyright (C) 2008 Maarten Maathuis.
  3. * All Rights Reserved.
  4. *
  5. * Permission is hereby granted, free of charge, to any person obtaining
  6. * a copy of this software and associated documentation files (the
  7. * "Software"), to deal in the Software without restriction, including
  8. * without limitation the rights to use, copy, modify, merge, publish,
  9. * distribute, sublicense, and/or sell copies of the Software, and to
  10. * permit persons to whom the Software is furnished to do so, subject to
  11. * the following conditions:
  12. *
  13. * The above copyright notice and this permission notice (including the
  14. * next paragraph) shall be included in all copies or substantial
  15. * portions of the Software.
  16. *
  17. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  18. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  19. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  20. * IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
  21. * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  22. * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  23. * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  24. *
  25. */
  26. #define NOUVEAU_DMA_DEBUG (nouveau_reg_debug & NOUVEAU_REG_DEBUG_EVO)
  27. #include "nv50_display.h"
  28. #include "nouveau_crtc.h"
  29. #include "nouveau_encoder.h"
  30. #include "nouveau_connector.h"
  31. #include "nouveau_fb.h"
  32. #include "nouveau_fbcon.h"
  33. #include "nouveau_ramht.h"
  34. #include "drm_crtc_helper.h"
  35. static void nv50_display_isr(struct drm_device *);
  36. static void nv50_display_bh(unsigned long);
  37. static inline int
  38. nv50_sor_nr(struct drm_device *dev)
  39. {
  40. struct drm_nouveau_private *dev_priv = dev->dev_private;
  41. if (dev_priv->chipset < 0x90 ||
  42. dev_priv->chipset == 0x92 ||
  43. dev_priv->chipset == 0xa0)
  44. return 2;
  45. return 4;
  46. }
  47. static int
  48. evo_icmd(struct drm_device *dev, int ch, u32 mthd, u32 data)
  49. {
  50. int ret = 0;
  51. nv_mask(dev, 0x610300 + (ch * 0x08), 0x00000001, 0x00000001);
  52. nv_wr32(dev, 0x610304 + (ch * 0x08), data);
  53. nv_wr32(dev, 0x610300 + (ch * 0x08), 0x80000001 | mthd);
  54. if (!nv_wait(dev, 0x610300 + (ch * 0x08), 0x80000000, 0x00000000))
  55. ret = -EBUSY;
  56. if (ret || (nouveau_reg_debug & NOUVEAU_REG_DEBUG_EVO))
  57. NV_INFO(dev, "EvoPIO: %d 0x%04x 0x%08x\n", ch, mthd, data);
  58. nv_mask(dev, 0x610300 + (ch * 0x08), 0x00000001, 0x00000000);
  59. return ret;
  60. }
  61. int
  62. nv50_display_early_init(struct drm_device *dev)
  63. {
  64. u32 ctrl = nv_rd32(dev, 0x610200);
  65. int i;
  66. /* check if master evo channel is already active, a good a sign as any
  67. * that the display engine is in a weird state (hibernate/kexec), if
  68. * it is, do our best to reset the display engine...
  69. */
  70. if ((ctrl & 0x00000003) == 0x00000003) {
  71. NV_INFO(dev, "PDISP: EVO(0) 0x%08x, resetting...\n", ctrl);
  72. /* deactivate both heads first, PDISP will disappear forever
  73. * (well, until you power cycle) on some boards as soon as
  74. * PMC_ENABLE is hit unless they are..
  75. */
  76. for (i = 0; i < 2; i++) {
  77. evo_icmd(dev, 0, 0x0880 + (i * 0x400), 0x05000000);
  78. evo_icmd(dev, 0, 0x089c + (i * 0x400), 0);
  79. evo_icmd(dev, 0, 0x0840 + (i * 0x400), 0);
  80. evo_icmd(dev, 0, 0x0844 + (i * 0x400), 0);
  81. evo_icmd(dev, 0, 0x085c + (i * 0x400), 0);
  82. evo_icmd(dev, 0, 0x0874 + (i * 0x400), 0);
  83. }
  84. evo_icmd(dev, 0, 0x0080, 0);
  85. /* reset PDISP */
  86. nv_mask(dev, 0x000200, 0x40000000, 0x00000000);
  87. nv_mask(dev, 0x000200, 0x40000000, 0x40000000);
  88. }
  89. return 0;
  90. }
  91. void
  92. nv50_display_late_takedown(struct drm_device *dev)
  93. {
  94. }
  95. int
  96. nv50_display_sync(struct drm_device *dev)
  97. {
  98. struct drm_nouveau_private *dev_priv = dev->dev_private;
  99. struct nouveau_timer_engine *ptimer = &dev_priv->engine.timer;
  100. struct nv50_display *disp = nv50_display(dev);
  101. struct nouveau_channel *evo = disp->master;
  102. u64 start;
  103. int ret;
  104. ret = RING_SPACE(evo, 6);
  105. if (ret == 0) {
  106. BEGIN_RING(evo, 0, 0x0084, 1);
  107. OUT_RING (evo, 0x80000000);
  108. BEGIN_RING(evo, 0, 0x0080, 1);
  109. OUT_RING (evo, 0);
  110. BEGIN_RING(evo, 0, 0x0084, 1);
  111. OUT_RING (evo, 0x00000000);
  112. nv_wo32(disp->ntfy, 0x000, 0x00000000);
  113. FIRE_RING (evo);
  114. start = ptimer->read(dev);
  115. do {
  116. if (nv_ro32(disp->ntfy, 0x000))
  117. return 0;
  118. } while (ptimer->read(dev) - start < 2000000000ULL);
  119. }
  120. return -EBUSY;
  121. }
  122. int
  123. nv50_display_init(struct drm_device *dev)
  124. {
  125. struct nouveau_channel *evo;
  126. int ret, i;
  127. u32 val;
  128. NV_DEBUG_KMS(dev, "\n");
  129. nv_wr32(dev, 0x00610184, nv_rd32(dev, 0x00614004));
  130. /*
  131. * I think the 0x006101XX range is some kind of main control area
  132. * that enables things.
  133. */
  134. /* CRTC? */
  135. for (i = 0; i < 2; i++) {
  136. val = nv_rd32(dev, 0x00616100 + (i * 0x800));
  137. nv_wr32(dev, 0x00610190 + (i * 0x10), val);
  138. val = nv_rd32(dev, 0x00616104 + (i * 0x800));
  139. nv_wr32(dev, 0x00610194 + (i * 0x10), val);
  140. val = nv_rd32(dev, 0x00616108 + (i * 0x800));
  141. nv_wr32(dev, 0x00610198 + (i * 0x10), val);
  142. val = nv_rd32(dev, 0x0061610c + (i * 0x800));
  143. nv_wr32(dev, 0x0061019c + (i * 0x10), val);
  144. }
  145. /* DAC */
  146. for (i = 0; i < 3; i++) {
  147. val = nv_rd32(dev, 0x0061a000 + (i * 0x800));
  148. nv_wr32(dev, 0x006101d0 + (i * 0x04), val);
  149. }
  150. /* SOR */
  151. for (i = 0; i < nv50_sor_nr(dev); i++) {
  152. val = nv_rd32(dev, 0x0061c000 + (i * 0x800));
  153. nv_wr32(dev, 0x006101e0 + (i * 0x04), val);
  154. }
  155. /* EXT */
  156. for (i = 0; i < 3; i++) {
  157. val = nv_rd32(dev, 0x0061e000 + (i * 0x800));
  158. nv_wr32(dev, 0x006101f0 + (i * 0x04), val);
  159. }
  160. for (i = 0; i < 3; i++) {
  161. nv_wr32(dev, NV50_PDISPLAY_DAC_DPMS_CTRL(i), 0x00550000 |
  162. NV50_PDISPLAY_DAC_DPMS_CTRL_PENDING);
  163. nv_wr32(dev, NV50_PDISPLAY_DAC_CLK_CTRL1(i), 0x00000001);
  164. }
  165. /* The precise purpose is unknown, i suspect it has something to do
  166. * with text mode.
  167. */
  168. if (nv_rd32(dev, NV50_PDISPLAY_INTR_1) & 0x100) {
  169. nv_wr32(dev, NV50_PDISPLAY_INTR_1, 0x100);
  170. nv_wr32(dev, 0x006194e8, nv_rd32(dev, 0x006194e8) & ~1);
  171. if (!nv_wait(dev, 0x006194e8, 2, 0)) {
  172. NV_ERROR(dev, "timeout: (0x6194e8 & 2) != 0\n");
  173. NV_ERROR(dev, "0x6194e8 = 0x%08x\n",
  174. nv_rd32(dev, 0x6194e8));
  175. return -EBUSY;
  176. }
  177. }
  178. for (i = 0; i < 2; i++) {
  179. nv_wr32(dev, NV50_PDISPLAY_CURSOR_CURSOR_CTRL2(i), 0x2000);
  180. if (!nv_wait(dev, NV50_PDISPLAY_CURSOR_CURSOR_CTRL2(i),
  181. NV50_PDISPLAY_CURSOR_CURSOR_CTRL2_STATUS, 0)) {
  182. NV_ERROR(dev, "timeout: CURSOR_CTRL2_STATUS == 0\n");
  183. NV_ERROR(dev, "CURSOR_CTRL2 = 0x%08x\n",
  184. nv_rd32(dev, NV50_PDISPLAY_CURSOR_CURSOR_CTRL2(i)));
  185. return -EBUSY;
  186. }
  187. nv_wr32(dev, NV50_PDISPLAY_CURSOR_CURSOR_CTRL2(i),
  188. NV50_PDISPLAY_CURSOR_CURSOR_CTRL2_ON);
  189. if (!nv_wait(dev, NV50_PDISPLAY_CURSOR_CURSOR_CTRL2(i),
  190. NV50_PDISPLAY_CURSOR_CURSOR_CTRL2_STATUS,
  191. NV50_PDISPLAY_CURSOR_CURSOR_CTRL2_STATUS_ACTIVE)) {
  192. NV_ERROR(dev, "timeout: "
  193. "CURSOR_CTRL2_STATUS_ACTIVE(%d)\n", i);
  194. NV_ERROR(dev, "CURSOR_CTRL2(%d) = 0x%08x\n", i,
  195. nv_rd32(dev, NV50_PDISPLAY_CURSOR_CURSOR_CTRL2(i)));
  196. return -EBUSY;
  197. }
  198. }
  199. nv_wr32(dev, NV50_PDISPLAY_PIO_CTRL, 0x00000000);
  200. nv_mask(dev, NV50_PDISPLAY_INTR_0, 0x00000000, 0x00000000);
  201. nv_wr32(dev, NV50_PDISPLAY_INTR_EN_0, 0x00000000);
  202. nv_mask(dev, NV50_PDISPLAY_INTR_1, 0x00000000, 0x00000000);
  203. nv_wr32(dev, NV50_PDISPLAY_INTR_EN_1,
  204. NV50_PDISPLAY_INTR_EN_1_CLK_UNK10 |
  205. NV50_PDISPLAY_INTR_EN_1_CLK_UNK20 |
  206. NV50_PDISPLAY_INTR_EN_1_CLK_UNK40);
  207. ret = nv50_evo_init(dev);
  208. if (ret)
  209. return ret;
  210. evo = nv50_display(dev)->master;
  211. nv_wr32(dev, NV50_PDISPLAY_OBJECTS, (evo->ramin->vinst >> 8) | 9);
  212. ret = RING_SPACE(evo, 3);
  213. if (ret)
  214. return ret;
  215. BEGIN_RING(evo, 0, NV50_EVO_UNK84, 2);
  216. OUT_RING (evo, NV50_EVO_UNK84_NOTIFY_DISABLED);
  217. OUT_RING (evo, NvEvoSync);
  218. return nv50_display_sync(dev);
  219. }
  220. void
  221. nv50_display_fini(struct drm_device *dev)
  222. {
  223. struct nv50_display *disp = nv50_display(dev);
  224. struct nouveau_channel *evo = disp->master;
  225. struct drm_crtc *drm_crtc;
  226. int ret, i;
  227. NV_DEBUG_KMS(dev, "\n");
  228. list_for_each_entry(drm_crtc, &dev->mode_config.crtc_list, head) {
  229. struct nouveau_crtc *crtc = nouveau_crtc(drm_crtc);
  230. nv50_crtc_blank(crtc, true);
  231. }
  232. ret = RING_SPACE(evo, 2);
  233. if (ret == 0) {
  234. BEGIN_RING(evo, 0, NV50_EVO_UPDATE, 1);
  235. OUT_RING(evo, 0);
  236. }
  237. FIRE_RING(evo);
  238. /* Almost like ack'ing a vblank interrupt, maybe in the spirit of
  239. * cleaning up?
  240. */
  241. list_for_each_entry(drm_crtc, &dev->mode_config.crtc_list, head) {
  242. struct nouveau_crtc *crtc = nouveau_crtc(drm_crtc);
  243. uint32_t mask = NV50_PDISPLAY_INTR_1_VBLANK_CRTC_(crtc->index);
  244. if (!crtc->base.enabled)
  245. continue;
  246. nv_wr32(dev, NV50_PDISPLAY_INTR_1, mask);
  247. if (!nv_wait(dev, NV50_PDISPLAY_INTR_1, mask, mask)) {
  248. NV_ERROR(dev, "timeout: (0x610024 & 0x%08x) == "
  249. "0x%08x\n", mask, mask);
  250. NV_ERROR(dev, "0x610024 = 0x%08x\n",
  251. nv_rd32(dev, NV50_PDISPLAY_INTR_1));
  252. }
  253. }
  254. for (i = 0; i < 2; i++) {
  255. nv_wr32(dev, NV50_PDISPLAY_CURSOR_CURSOR_CTRL2(i), 0);
  256. if (!nv_wait(dev, NV50_PDISPLAY_CURSOR_CURSOR_CTRL2(i),
  257. NV50_PDISPLAY_CURSOR_CURSOR_CTRL2_STATUS, 0)) {
  258. NV_ERROR(dev, "timeout: CURSOR_CTRL2_STATUS == 0\n");
  259. NV_ERROR(dev, "CURSOR_CTRL2 = 0x%08x\n",
  260. nv_rd32(dev, NV50_PDISPLAY_CURSOR_CURSOR_CTRL2(i)));
  261. }
  262. }
  263. nv50_evo_fini(dev);
  264. for (i = 0; i < 3; i++) {
  265. if (!nv_wait(dev, NV50_PDISPLAY_SOR_DPMS_STATE(i),
  266. NV50_PDISPLAY_SOR_DPMS_STATE_WAIT, 0)) {
  267. NV_ERROR(dev, "timeout: SOR_DPMS_STATE_WAIT(%d) == 0\n", i);
  268. NV_ERROR(dev, "SOR_DPMS_STATE(%d) = 0x%08x\n", i,
  269. nv_rd32(dev, NV50_PDISPLAY_SOR_DPMS_STATE(i)));
  270. }
  271. }
  272. /* disable interrupts. */
  273. nv_wr32(dev, NV50_PDISPLAY_INTR_EN_1, 0x00000000);
  274. }
  275. int
  276. nv50_display_create(struct drm_device *dev)
  277. {
  278. struct drm_nouveau_private *dev_priv = dev->dev_private;
  279. struct dcb_table *dcb = &dev_priv->vbios.dcb;
  280. struct drm_connector *connector, *ct;
  281. struct nv50_display *priv;
  282. int ret, i;
  283. NV_DEBUG_KMS(dev, "\n");
  284. priv = kzalloc(sizeof(*priv), GFP_KERNEL);
  285. if (!priv)
  286. return -ENOMEM;
  287. dev_priv->engine.display.priv = priv;
  288. /* Create CRTC objects */
  289. for (i = 0; i < 2; i++)
  290. nv50_crtc_create(dev, i);
  291. /* We setup the encoders from the BIOS table */
  292. for (i = 0 ; i < dcb->entries; i++) {
  293. struct dcb_entry *entry = &dcb->entry[i];
  294. if (entry->location != DCB_LOC_ON_CHIP) {
  295. NV_WARN(dev, "Off-chip encoder %d/%d unsupported\n",
  296. entry->type, ffs(entry->or) - 1);
  297. continue;
  298. }
  299. connector = nouveau_connector_create(dev, entry->connector);
  300. if (IS_ERR(connector))
  301. continue;
  302. switch (entry->type) {
  303. case OUTPUT_TMDS:
  304. case OUTPUT_LVDS:
  305. case OUTPUT_DP:
  306. nv50_sor_create(connector, entry);
  307. break;
  308. case OUTPUT_ANALOG:
  309. nv50_dac_create(connector, entry);
  310. break;
  311. default:
  312. NV_WARN(dev, "DCB encoder %d unknown\n", entry->type);
  313. continue;
  314. }
  315. }
  316. list_for_each_entry_safe(connector, ct,
  317. &dev->mode_config.connector_list, head) {
  318. if (!connector->encoder_ids[0]) {
  319. NV_WARN(dev, "%s has no encoders, removing\n",
  320. drm_get_connector_name(connector));
  321. connector->funcs->destroy(connector);
  322. }
  323. }
  324. tasklet_init(&priv->tasklet, nv50_display_bh, (unsigned long)dev);
  325. nouveau_irq_register(dev, 26, nv50_display_isr);
  326. ret = nv50_evo_create(dev);
  327. if (ret) {
  328. nv50_display_destroy(dev);
  329. return ret;
  330. }
  331. return 0;
  332. }
  333. void
  334. nv50_display_destroy(struct drm_device *dev)
  335. {
  336. struct nv50_display *disp = nv50_display(dev);
  337. NV_DEBUG_KMS(dev, "\n");
  338. nv50_evo_destroy(dev);
  339. nouveau_irq_unregister(dev, 26);
  340. kfree(disp);
  341. }
  342. void
  343. nv50_display_flip_stop(struct drm_crtc *crtc)
  344. {
  345. struct nv50_display *disp = nv50_display(crtc->dev);
  346. struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc);
  347. struct nv50_display_crtc *dispc = &disp->crtc[nv_crtc->index];
  348. struct nouveau_channel *evo = dispc->sync;
  349. int ret;
  350. ret = RING_SPACE(evo, 8);
  351. if (ret) {
  352. WARN_ON(1);
  353. return;
  354. }
  355. BEGIN_RING(evo, 0, 0x0084, 1);
  356. OUT_RING (evo, 0x00000000);
  357. BEGIN_RING(evo, 0, 0x0094, 1);
  358. OUT_RING (evo, 0x00000000);
  359. BEGIN_RING(evo, 0, 0x00c0, 1);
  360. OUT_RING (evo, 0x00000000);
  361. BEGIN_RING(evo, 0, 0x0080, 1);
  362. OUT_RING (evo, 0x00000000);
  363. FIRE_RING (evo);
  364. }
  365. int
  366. nv50_display_flip_next(struct drm_crtc *crtc, struct drm_framebuffer *fb,
  367. struct nouveau_channel *chan)
  368. {
  369. struct drm_nouveau_private *dev_priv = crtc->dev->dev_private;
  370. struct nouveau_framebuffer *nv_fb = nouveau_framebuffer(fb);
  371. struct nv50_display *disp = nv50_display(crtc->dev);
  372. struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc);
  373. struct nv50_display_crtc *dispc = &disp->crtc[nv_crtc->index];
  374. struct nouveau_channel *evo = dispc->sync;
  375. int ret;
  376. ret = RING_SPACE(evo, chan ? 25 : 27);
  377. if (unlikely(ret))
  378. return ret;
  379. /* synchronise with the rendering channel, if necessary */
  380. if (likely(chan)) {
  381. ret = RING_SPACE(chan, 10);
  382. if (ret) {
  383. WIND_RING(evo);
  384. return ret;
  385. }
  386. if (dev_priv->chipset < 0xc0) {
  387. BEGIN_RING(chan, NvSubSw, 0x0060, 2);
  388. OUT_RING (chan, NvEvoSema0 + nv_crtc->index);
  389. OUT_RING (chan, dispc->sem.offset);
  390. BEGIN_RING(chan, NvSubSw, 0x006c, 1);
  391. OUT_RING (chan, 0xf00d0000 | dispc->sem.value);
  392. BEGIN_RING(chan, NvSubSw, 0x0064, 2);
  393. OUT_RING (chan, dispc->sem.offset ^ 0x10);
  394. OUT_RING (chan, 0x74b1e000);
  395. BEGIN_RING(chan, NvSubSw, 0x0060, 1);
  396. if (dev_priv->chipset < 0x84)
  397. OUT_RING (chan, NvSema);
  398. else
  399. OUT_RING (chan, chan->vram_handle);
  400. } else {
  401. u64 offset = chan->dispc_vma[nv_crtc->index].offset;
  402. offset += dispc->sem.offset;
  403. BEGIN_NVC0(chan, 2, NvSubM2MF, 0x0010, 4);
  404. OUT_RING (chan, upper_32_bits(offset));
  405. OUT_RING (chan, lower_32_bits(offset));
  406. OUT_RING (chan, 0xf00d0000 | dispc->sem.value);
  407. OUT_RING (chan, 0x1002);
  408. BEGIN_NVC0(chan, 2, NvSubM2MF, 0x0010, 4);
  409. OUT_RING (chan, upper_32_bits(offset));
  410. OUT_RING (chan, lower_32_bits(offset ^ 0x10));
  411. OUT_RING (chan, 0x74b1e000);
  412. OUT_RING (chan, 0x1001);
  413. }
  414. FIRE_RING (chan);
  415. } else {
  416. nouveau_bo_wr32(dispc->sem.bo, dispc->sem.offset / 4,
  417. 0xf00d0000 | dispc->sem.value);
  418. }
  419. /* queue the flip on the crtc's "display sync" channel */
  420. BEGIN_RING(evo, 0, 0x0100, 1);
  421. OUT_RING (evo, 0xfffe0000);
  422. if (chan) {
  423. BEGIN_RING(evo, 0, 0x0084, 1);
  424. OUT_RING (evo, 0x00000100);
  425. } else {
  426. BEGIN_RING(evo, 0, 0x0084, 1);
  427. OUT_RING (evo, 0x00000010);
  428. /* allows gamma somehow, PDISP will bitch at you if
  429. * you don't wait for vblank before changing this..
  430. */
  431. BEGIN_RING(evo, 0, 0x00e0, 1);
  432. OUT_RING (evo, 0x40000000);
  433. }
  434. BEGIN_RING(evo, 0, 0x0088, 4);
  435. OUT_RING (evo, dispc->sem.offset);
  436. OUT_RING (evo, 0xf00d0000 | dispc->sem.value);
  437. OUT_RING (evo, 0x74b1e000);
  438. OUT_RING (evo, NvEvoSync);
  439. BEGIN_RING(evo, 0, 0x00a0, 2);
  440. OUT_RING (evo, 0x00000000);
  441. OUT_RING (evo, 0x00000000);
  442. BEGIN_RING(evo, 0, 0x00c0, 1);
  443. OUT_RING (evo, nv_fb->r_dma);
  444. BEGIN_RING(evo, 0, 0x0110, 2);
  445. OUT_RING (evo, 0x00000000);
  446. OUT_RING (evo, 0x00000000);
  447. BEGIN_RING(evo, 0, 0x0800, 5);
  448. OUT_RING (evo, nv_fb->nvbo->bo.offset >> 8);
  449. OUT_RING (evo, 0);
  450. OUT_RING (evo, (fb->height << 16) | fb->width);
  451. OUT_RING (evo, nv_fb->r_pitch);
  452. OUT_RING (evo, nv_fb->r_format);
  453. BEGIN_RING(evo, 0, 0x0080, 1);
  454. OUT_RING (evo, 0x00000000);
  455. FIRE_RING (evo);
  456. dispc->sem.offset ^= 0x10;
  457. dispc->sem.value++;
  458. return 0;
  459. }
  460. static u16
  461. nv50_display_script_select(struct drm_device *dev, struct dcb_entry *dcb,
  462. u32 mc, int pxclk)
  463. {
  464. struct drm_nouveau_private *dev_priv = dev->dev_private;
  465. struct nouveau_connector *nv_connector = NULL;
  466. struct drm_encoder *encoder;
  467. struct nvbios *bios = &dev_priv->vbios;
  468. u32 script = 0, or;
  469. list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
  470. struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
  471. if (nv_encoder->dcb != dcb)
  472. continue;
  473. nv_connector = nouveau_encoder_connector_get(nv_encoder);
  474. break;
  475. }
  476. or = ffs(dcb->or) - 1;
  477. switch (dcb->type) {
  478. case OUTPUT_LVDS:
  479. script = (mc >> 8) & 0xf;
  480. if (bios->fp_no_ddc) {
  481. if (bios->fp.dual_link)
  482. script |= 0x0100;
  483. if (bios->fp.if_is_24bit)
  484. script |= 0x0200;
  485. } else {
  486. /* determine number of lvds links */
  487. if (nv_connector && nv_connector->edid &&
  488. nv_connector->type == DCB_CONNECTOR_LVDS_SPWG) {
  489. /* http://www.spwg.org */
  490. if (((u8 *)nv_connector->edid)[121] == 2)
  491. script |= 0x0100;
  492. } else
  493. if (pxclk >= bios->fp.duallink_transition_clk) {
  494. script |= 0x0100;
  495. }
  496. /* determine panel depth */
  497. if (script & 0x0100) {
  498. if (bios->fp.strapless_is_24bit & 2)
  499. script |= 0x0200;
  500. } else {
  501. if (bios->fp.strapless_is_24bit & 1)
  502. script |= 0x0200;
  503. }
  504. if (nv_connector && nv_connector->edid &&
  505. (nv_connector->edid->revision >= 4) &&
  506. (nv_connector->edid->input & 0x70) >= 0x20)
  507. script |= 0x0200;
  508. }
  509. if (nouveau_uscript_lvds >= 0) {
  510. NV_INFO(dev, "override script 0x%04x with 0x%04x "
  511. "for output LVDS-%d\n", script,
  512. nouveau_uscript_lvds, or);
  513. script = nouveau_uscript_lvds;
  514. }
  515. break;
  516. case OUTPUT_TMDS:
  517. script = (mc >> 8) & 0xf;
  518. if (pxclk >= 165000)
  519. script |= 0x0100;
  520. if (nouveau_uscript_tmds >= 0) {
  521. NV_INFO(dev, "override script 0x%04x with 0x%04x "
  522. "for output TMDS-%d\n", script,
  523. nouveau_uscript_tmds, or);
  524. script = nouveau_uscript_tmds;
  525. }
  526. break;
  527. case OUTPUT_DP:
  528. script = (mc >> 8) & 0xf;
  529. break;
  530. case OUTPUT_ANALOG:
  531. script = 0xff;
  532. break;
  533. default:
  534. NV_ERROR(dev, "modeset on unsupported output type!\n");
  535. break;
  536. }
  537. return script;
  538. }
  539. static void
  540. nv50_display_vblank_crtc_handler(struct drm_device *dev, int crtc)
  541. {
  542. struct drm_nouveau_private *dev_priv = dev->dev_private;
  543. struct nouveau_channel *chan, *tmp;
  544. list_for_each_entry_safe(chan, tmp, &dev_priv->vbl_waiting,
  545. nvsw.vbl_wait) {
  546. if (chan->nvsw.vblsem_head != crtc)
  547. continue;
  548. nouveau_bo_wr32(chan->notifier_bo, chan->nvsw.vblsem_offset,
  549. chan->nvsw.vblsem_rval);
  550. list_del(&chan->nvsw.vbl_wait);
  551. drm_vblank_put(dev, crtc);
  552. }
  553. drm_handle_vblank(dev, crtc);
  554. }
  555. static void
  556. nv50_display_vblank_handler(struct drm_device *dev, uint32_t intr)
  557. {
  558. if (intr & NV50_PDISPLAY_INTR_1_VBLANK_CRTC_0)
  559. nv50_display_vblank_crtc_handler(dev, 0);
  560. if (intr & NV50_PDISPLAY_INTR_1_VBLANK_CRTC_1)
  561. nv50_display_vblank_crtc_handler(dev, 1);
  562. nv_wr32(dev, NV50_PDISPLAY_INTR_1, NV50_PDISPLAY_INTR_1_VBLANK_CRTC);
  563. }
  564. static void
  565. nv50_display_unk10_handler(struct drm_device *dev)
  566. {
  567. struct drm_nouveau_private *dev_priv = dev->dev_private;
  568. struct nv50_display *disp = nv50_display(dev);
  569. u32 unk30 = nv_rd32(dev, 0x610030), mc;
  570. int i, crtc, or = 0, type = OUTPUT_ANY;
  571. NV_DEBUG_KMS(dev, "0x610030: 0x%08x\n", unk30);
  572. disp->irq.dcb = NULL;
  573. nv_wr32(dev, 0x619494, nv_rd32(dev, 0x619494) & ~8);
  574. /* Determine which CRTC we're dealing with, only 1 ever will be
  575. * signalled at the same time with the current nouveau code.
  576. */
  577. crtc = ffs((unk30 & 0x00000060) >> 5) - 1;
  578. if (crtc < 0)
  579. goto ack;
  580. /* Nothing needs to be done for the encoder */
  581. crtc = ffs((unk30 & 0x00000180) >> 7) - 1;
  582. if (crtc < 0)
  583. goto ack;
  584. /* Find which encoder was connected to the CRTC */
  585. for (i = 0; type == OUTPUT_ANY && i < 3; i++) {
  586. mc = nv_rd32(dev, NV50_PDISPLAY_DAC_MODE_CTRL_C(i));
  587. NV_DEBUG_KMS(dev, "DAC-%d mc: 0x%08x\n", i, mc);
  588. if (!(mc & (1 << crtc)))
  589. continue;
  590. switch ((mc & 0x00000f00) >> 8) {
  591. case 0: type = OUTPUT_ANALOG; break;
  592. case 1: type = OUTPUT_TV; break;
  593. default:
  594. NV_ERROR(dev, "invalid mc, DAC-%d: 0x%08x\n", i, mc);
  595. goto ack;
  596. }
  597. or = i;
  598. }
  599. for (i = 0; type == OUTPUT_ANY && i < nv50_sor_nr(dev); i++) {
  600. if (dev_priv->chipset < 0x90 ||
  601. dev_priv->chipset == 0x92 ||
  602. dev_priv->chipset == 0xa0)
  603. mc = nv_rd32(dev, NV50_PDISPLAY_SOR_MODE_CTRL_C(i));
  604. else
  605. mc = nv_rd32(dev, NV90_PDISPLAY_SOR_MODE_CTRL_C(i));
  606. NV_DEBUG_KMS(dev, "SOR-%d mc: 0x%08x\n", i, mc);
  607. if (!(mc & (1 << crtc)))
  608. continue;
  609. switch ((mc & 0x00000f00) >> 8) {
  610. case 0: type = OUTPUT_LVDS; break;
  611. case 1: type = OUTPUT_TMDS; break;
  612. case 2: type = OUTPUT_TMDS; break;
  613. case 5: type = OUTPUT_TMDS; break;
  614. case 8: type = OUTPUT_DP; break;
  615. case 9: type = OUTPUT_DP; break;
  616. default:
  617. NV_ERROR(dev, "invalid mc, SOR-%d: 0x%08x\n", i, mc);
  618. goto ack;
  619. }
  620. or = i;
  621. }
  622. /* There was no encoder to disable */
  623. if (type == OUTPUT_ANY)
  624. goto ack;
  625. /* Disable the encoder */
  626. for (i = 0; i < dev_priv->vbios.dcb.entries; i++) {
  627. struct dcb_entry *dcb = &dev_priv->vbios.dcb.entry[i];
  628. if (dcb->type == type && (dcb->or & (1 << or))) {
  629. nouveau_bios_run_display_table(dev, 0, -1, dcb, -1);
  630. disp->irq.dcb = dcb;
  631. goto ack;
  632. }
  633. }
  634. NV_ERROR(dev, "no dcb for %d %d 0x%08x\n", or, type, mc);
  635. ack:
  636. nv_wr32(dev, NV50_PDISPLAY_INTR_1, NV50_PDISPLAY_INTR_1_CLK_UNK10);
  637. nv_wr32(dev, 0x610030, 0x80000000);
  638. }
  639. static void
  640. nv50_display_unk20_handler(struct drm_device *dev)
  641. {
  642. struct drm_nouveau_private *dev_priv = dev->dev_private;
  643. struct nv50_display *disp = nv50_display(dev);
  644. u32 unk30 = nv_rd32(dev, 0x610030), tmp, pclk, script, mc = 0;
  645. struct dcb_entry *dcb;
  646. int i, crtc, or = 0, type = OUTPUT_ANY;
  647. NV_DEBUG_KMS(dev, "0x610030: 0x%08x\n", unk30);
  648. dcb = disp->irq.dcb;
  649. if (dcb) {
  650. nouveau_bios_run_display_table(dev, 0, -2, dcb, -1);
  651. disp->irq.dcb = NULL;
  652. }
  653. /* CRTC clock change requested? */
  654. crtc = ffs((unk30 & 0x00000600) >> 9) - 1;
  655. if (crtc >= 0) {
  656. pclk = nv_rd32(dev, NV50_PDISPLAY_CRTC_P(crtc, CLOCK));
  657. pclk &= 0x003fffff;
  658. if (pclk)
  659. nv50_crtc_set_clock(dev, crtc, pclk);
  660. tmp = nv_rd32(dev, NV50_PDISPLAY_CRTC_CLK_CTRL2(crtc));
  661. tmp &= ~0x000000f;
  662. nv_wr32(dev, NV50_PDISPLAY_CRTC_CLK_CTRL2(crtc), tmp);
  663. }
  664. /* Nothing needs to be done for the encoder */
  665. crtc = ffs((unk30 & 0x00000180) >> 7) - 1;
  666. if (crtc < 0)
  667. goto ack;
  668. pclk = nv_rd32(dev, NV50_PDISPLAY_CRTC_P(crtc, CLOCK)) & 0x003fffff;
  669. /* Find which encoder is connected to the CRTC */
  670. for (i = 0; type == OUTPUT_ANY && i < 3; i++) {
  671. mc = nv_rd32(dev, NV50_PDISPLAY_DAC_MODE_CTRL_P(i));
  672. NV_DEBUG_KMS(dev, "DAC-%d mc: 0x%08x\n", i, mc);
  673. if (!(mc & (1 << crtc)))
  674. continue;
  675. switch ((mc & 0x00000f00) >> 8) {
  676. case 0: type = OUTPUT_ANALOG; break;
  677. case 1: type = OUTPUT_TV; break;
  678. default:
  679. NV_ERROR(dev, "invalid mc, DAC-%d: 0x%08x\n", i, mc);
  680. goto ack;
  681. }
  682. or = i;
  683. }
  684. for (i = 0; type == OUTPUT_ANY && i < nv50_sor_nr(dev); i++) {
  685. if (dev_priv->chipset < 0x90 ||
  686. dev_priv->chipset == 0x92 ||
  687. dev_priv->chipset == 0xa0)
  688. mc = nv_rd32(dev, NV50_PDISPLAY_SOR_MODE_CTRL_P(i));
  689. else
  690. mc = nv_rd32(dev, NV90_PDISPLAY_SOR_MODE_CTRL_P(i));
  691. NV_DEBUG_KMS(dev, "SOR-%d mc: 0x%08x\n", i, mc);
  692. if (!(mc & (1 << crtc)))
  693. continue;
  694. switch ((mc & 0x00000f00) >> 8) {
  695. case 0: type = OUTPUT_LVDS; break;
  696. case 1: type = OUTPUT_TMDS; break;
  697. case 2: type = OUTPUT_TMDS; break;
  698. case 5: type = OUTPUT_TMDS; break;
  699. case 8: type = OUTPUT_DP; break;
  700. case 9: type = OUTPUT_DP; break;
  701. default:
  702. NV_ERROR(dev, "invalid mc, SOR-%d: 0x%08x\n", i, mc);
  703. goto ack;
  704. }
  705. or = i;
  706. }
  707. if (type == OUTPUT_ANY)
  708. goto ack;
  709. /* Enable the encoder */
  710. for (i = 0; i < dev_priv->vbios.dcb.entries; i++) {
  711. dcb = &dev_priv->vbios.dcb.entry[i];
  712. if (dcb->type == type && (dcb->or & (1 << or)))
  713. break;
  714. }
  715. if (i == dev_priv->vbios.dcb.entries) {
  716. NV_ERROR(dev, "no dcb for %d %d 0x%08x\n", or, type, mc);
  717. goto ack;
  718. }
  719. script = nv50_display_script_select(dev, dcb, mc, pclk);
  720. nouveau_bios_run_display_table(dev, script, pclk, dcb, -1);
  721. if (type == OUTPUT_DP) {
  722. int link = !(dcb->dpconf.sor.link & 1);
  723. if ((mc & 0x000f0000) == 0x00020000)
  724. nouveau_dp_tu_update(dev, or, link, pclk, 18);
  725. else
  726. nouveau_dp_tu_update(dev, or, link, pclk, 24);
  727. }
  728. if (dcb->type != OUTPUT_ANALOG) {
  729. tmp = nv_rd32(dev, NV50_PDISPLAY_SOR_CLK_CTRL2(or));
  730. tmp &= ~0x00000f0f;
  731. if (script & 0x0100)
  732. tmp |= 0x00000101;
  733. nv_wr32(dev, NV50_PDISPLAY_SOR_CLK_CTRL2(or), tmp);
  734. } else {
  735. nv_wr32(dev, NV50_PDISPLAY_DAC_CLK_CTRL2(or), 0);
  736. }
  737. disp->irq.dcb = dcb;
  738. disp->irq.pclk = pclk;
  739. disp->irq.script = script;
  740. ack:
  741. nv_wr32(dev, NV50_PDISPLAY_INTR_1, NV50_PDISPLAY_INTR_1_CLK_UNK20);
  742. nv_wr32(dev, 0x610030, 0x80000000);
  743. }
  744. /* If programming a TMDS output on a SOR that can also be configured for
  745. * DisplayPort, make sure NV50_SOR_DP_CTRL_ENABLE is forced off.
  746. *
  747. * It looks like the VBIOS TMDS scripts make an attempt at this, however,
  748. * the VBIOS scripts on at least one board I have only switch it off on
  749. * link 0, causing a blank display if the output has previously been
  750. * programmed for DisplayPort.
  751. */
  752. static void
  753. nv50_display_unk40_dp_set_tmds(struct drm_device *dev, struct dcb_entry *dcb)
  754. {
  755. int or = ffs(dcb->or) - 1, link = !(dcb->dpconf.sor.link & 1);
  756. struct drm_encoder *encoder;
  757. u32 tmp;
  758. if (dcb->type != OUTPUT_TMDS)
  759. return;
  760. list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
  761. struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
  762. if (nv_encoder->dcb->type == OUTPUT_DP &&
  763. nv_encoder->dcb->or & (1 << or)) {
  764. tmp = nv_rd32(dev, NV50_SOR_DP_CTRL(or, link));
  765. tmp &= ~NV50_SOR_DP_CTRL_ENABLED;
  766. nv_wr32(dev, NV50_SOR_DP_CTRL(or, link), tmp);
  767. break;
  768. }
  769. }
  770. }
  771. static void
  772. nv50_display_unk40_handler(struct drm_device *dev)
  773. {
  774. struct nv50_display *disp = nv50_display(dev);
  775. struct dcb_entry *dcb = disp->irq.dcb;
  776. u16 script = disp->irq.script;
  777. u32 unk30 = nv_rd32(dev, 0x610030), pclk = disp->irq.pclk;
  778. NV_DEBUG_KMS(dev, "0x610030: 0x%08x\n", unk30);
  779. disp->irq.dcb = NULL;
  780. if (!dcb)
  781. goto ack;
  782. nouveau_bios_run_display_table(dev, script, -pclk, dcb, -1);
  783. nv50_display_unk40_dp_set_tmds(dev, dcb);
  784. ack:
  785. nv_wr32(dev, NV50_PDISPLAY_INTR_1, NV50_PDISPLAY_INTR_1_CLK_UNK40);
  786. nv_wr32(dev, 0x610030, 0x80000000);
  787. nv_wr32(dev, 0x619494, nv_rd32(dev, 0x619494) | 8);
  788. }
  789. static void
  790. nv50_display_bh(unsigned long data)
  791. {
  792. struct drm_device *dev = (struct drm_device *)data;
  793. for (;;) {
  794. uint32_t intr0 = nv_rd32(dev, NV50_PDISPLAY_INTR_0);
  795. uint32_t intr1 = nv_rd32(dev, NV50_PDISPLAY_INTR_1);
  796. NV_DEBUG_KMS(dev, "PDISPLAY_INTR_BH 0x%08x 0x%08x\n", intr0, intr1);
  797. if (intr1 & NV50_PDISPLAY_INTR_1_CLK_UNK10)
  798. nv50_display_unk10_handler(dev);
  799. else
  800. if (intr1 & NV50_PDISPLAY_INTR_1_CLK_UNK20)
  801. nv50_display_unk20_handler(dev);
  802. else
  803. if (intr1 & NV50_PDISPLAY_INTR_1_CLK_UNK40)
  804. nv50_display_unk40_handler(dev);
  805. else
  806. break;
  807. }
  808. nv_wr32(dev, NV03_PMC_INTR_EN_0, 1);
  809. }
  810. static void
  811. nv50_display_error_handler(struct drm_device *dev)
  812. {
  813. u32 channels = (nv_rd32(dev, NV50_PDISPLAY_INTR_0) & 0x001f0000) >> 16;
  814. u32 addr, data;
  815. int chid;
  816. for (chid = 0; chid < 5; chid++) {
  817. if (!(channels & (1 << chid)))
  818. continue;
  819. nv_wr32(dev, NV50_PDISPLAY_INTR_0, 0x00010000 << chid);
  820. addr = nv_rd32(dev, NV50_PDISPLAY_TRAPPED_ADDR(chid));
  821. data = nv_rd32(dev, NV50_PDISPLAY_TRAPPED_DATA(chid));
  822. NV_ERROR(dev, "EvoCh %d Mthd 0x%04x Data 0x%08x "
  823. "(0x%04x 0x%02x)\n", chid,
  824. addr & 0xffc, data, addr >> 16, (addr >> 12) & 0xf);
  825. nv_wr32(dev, NV50_PDISPLAY_TRAPPED_ADDR(chid), 0x90000000);
  826. }
  827. }
  828. static void
  829. nv50_display_isr(struct drm_device *dev)
  830. {
  831. struct nv50_display *disp = nv50_display(dev);
  832. uint32_t delayed = 0;
  833. while (nv_rd32(dev, NV50_PMC_INTR_0) & NV50_PMC_INTR_0_DISPLAY) {
  834. uint32_t intr0 = nv_rd32(dev, NV50_PDISPLAY_INTR_0);
  835. uint32_t intr1 = nv_rd32(dev, NV50_PDISPLAY_INTR_1);
  836. uint32_t clock;
  837. NV_DEBUG_KMS(dev, "PDISPLAY_INTR 0x%08x 0x%08x\n", intr0, intr1);
  838. if (!intr0 && !(intr1 & ~delayed))
  839. break;
  840. if (intr0 & 0x001f0000) {
  841. nv50_display_error_handler(dev);
  842. intr0 &= ~0x001f0000;
  843. }
  844. if (intr1 & NV50_PDISPLAY_INTR_1_VBLANK_CRTC) {
  845. nv50_display_vblank_handler(dev, intr1);
  846. intr1 &= ~NV50_PDISPLAY_INTR_1_VBLANK_CRTC;
  847. }
  848. clock = (intr1 & (NV50_PDISPLAY_INTR_1_CLK_UNK10 |
  849. NV50_PDISPLAY_INTR_1_CLK_UNK20 |
  850. NV50_PDISPLAY_INTR_1_CLK_UNK40));
  851. if (clock) {
  852. nv_wr32(dev, NV03_PMC_INTR_EN_0, 0);
  853. tasklet_schedule(&disp->tasklet);
  854. delayed |= clock;
  855. intr1 &= ~clock;
  856. }
  857. if (intr0) {
  858. NV_ERROR(dev, "unknown PDISPLAY_INTR_0: 0x%08x\n", intr0);
  859. nv_wr32(dev, NV50_PDISPLAY_INTR_0, intr0);
  860. }
  861. if (intr1) {
  862. NV_ERROR(dev,
  863. "unknown PDISPLAY_INTR_1: 0x%08x\n", intr1);
  864. nv_wr32(dev, NV50_PDISPLAY_INTR_1, intr1);
  865. }
  866. }
  867. }