nv50_display.c 28 KB

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