nv50_display.c 26 KB

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