nv50_display.c 27 KB

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