nv50_display.c 27 KB

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