nv50_display.c 27 KB

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