nv50_display.c 27 KB

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