nv50_display.c 28 KB

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