nv50_display.c 27 KB

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