nv50_display.c 27 KB

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