nv50_display.c 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988
  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, 24);
  347. if (unlikely(ret))
  348. return ret;
  349. /* synchronise with the rendering channel, if necessary */
  350. if (likely(chan)) {
  351. u64 offset = dispc->sem.bo->vma.offset + dispc->sem.offset;
  352. ret = RING_SPACE(chan, 10);
  353. if (ret) {
  354. WIND_RING(evo);
  355. return ret;
  356. }
  357. if (dev_priv->chipset < 0xc0) {
  358. BEGIN_RING(chan, NvSubSw, 0x0060, 2);
  359. OUT_RING (chan, NvEvoSema0 + nv_crtc->index);
  360. OUT_RING (chan, dispc->sem.offset);
  361. BEGIN_RING(chan, NvSubSw, 0x006c, 1);
  362. OUT_RING (chan, 0xf00d0000 | dispc->sem.value);
  363. BEGIN_RING(chan, NvSubSw, 0x0064, 2);
  364. OUT_RING (chan, dispc->sem.offset ^ 0x10);
  365. OUT_RING (chan, 0x74b1e000);
  366. BEGIN_RING(chan, NvSubSw, 0x0060, 1);
  367. if (dev_priv->chipset < 0x84)
  368. OUT_RING (chan, NvSema);
  369. else
  370. OUT_RING (chan, chan->vram_handle);
  371. } else {
  372. BEGIN_NVC0(chan, 2, NvSubM2MF, 0x0010, 4);
  373. OUT_RING (chan, upper_32_bits(offset));
  374. OUT_RING (chan, lower_32_bits(offset));
  375. OUT_RING (chan, 0xf00d0000 | dispc->sem.value);
  376. OUT_RING (chan, 0x1002);
  377. BEGIN_NVC0(chan, 2, NvSubM2MF, 0x0010, 4);
  378. OUT_RING (chan, upper_32_bits(offset));
  379. OUT_RING (chan, lower_32_bits(offset ^ 0x10));
  380. OUT_RING (chan, 0x74b1e000);
  381. OUT_RING (chan, 0x1001);
  382. }
  383. FIRE_RING (chan);
  384. } else {
  385. nouveau_bo_wr32(dispc->sem.bo, dispc->sem.offset / 4,
  386. 0xf00d0000 | dispc->sem.value);
  387. }
  388. /* queue the flip on the crtc's "display sync" channel */
  389. BEGIN_RING(evo, 0, 0x0100, 1);
  390. OUT_RING (evo, 0xfffe0000);
  391. BEGIN_RING(evo, 0, 0x0084, 5);
  392. OUT_RING (evo, chan ? 0x00000100 : 0x00000010);
  393. OUT_RING (evo, dispc->sem.offset);
  394. OUT_RING (evo, 0xf00d0000 | dispc->sem.value);
  395. OUT_RING (evo, 0x74b1e000);
  396. OUT_RING (evo, NvEvoSync);
  397. BEGIN_RING(evo, 0, 0x00a0, 2);
  398. OUT_RING (evo, 0x00000000);
  399. OUT_RING (evo, 0x00000000);
  400. BEGIN_RING(evo, 0, 0x00c0, 1);
  401. OUT_RING (evo, nv_fb->r_dma);
  402. BEGIN_RING(evo, 0, 0x0110, 2);
  403. OUT_RING (evo, 0x00000000);
  404. OUT_RING (evo, 0x00000000);
  405. BEGIN_RING(evo, 0, 0x0800, 5);
  406. OUT_RING (evo, (nv_fb->nvbo->bo.mem.start << PAGE_SHIFT) >> 8);
  407. OUT_RING (evo, 0);
  408. OUT_RING (evo, (fb->height << 16) | fb->width);
  409. OUT_RING (evo, nv_fb->r_pitch);
  410. OUT_RING (evo, nv_fb->r_format);
  411. BEGIN_RING(evo, 0, 0x0080, 1);
  412. OUT_RING (evo, 0x00000000);
  413. FIRE_RING (evo);
  414. dispc->sem.offset ^= 0x10;
  415. dispc->sem.value++;
  416. return 0;
  417. }
  418. static u16
  419. nv50_display_script_select(struct drm_device *dev, struct dcb_entry *dcb,
  420. u32 mc, int pxclk)
  421. {
  422. struct drm_nouveau_private *dev_priv = dev->dev_private;
  423. struct nouveau_connector *nv_connector = NULL;
  424. struct drm_encoder *encoder;
  425. struct nvbios *bios = &dev_priv->vbios;
  426. u32 script = 0, or;
  427. list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
  428. struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
  429. if (nv_encoder->dcb != dcb)
  430. continue;
  431. nv_connector = nouveau_encoder_connector_get(nv_encoder);
  432. break;
  433. }
  434. or = ffs(dcb->or) - 1;
  435. switch (dcb->type) {
  436. case OUTPUT_LVDS:
  437. script = (mc >> 8) & 0xf;
  438. if (bios->fp_no_ddc) {
  439. if (bios->fp.dual_link)
  440. script |= 0x0100;
  441. if (bios->fp.if_is_24bit)
  442. script |= 0x0200;
  443. } else {
  444. if (pxclk >= bios->fp.duallink_transition_clk) {
  445. script |= 0x0100;
  446. if (bios->fp.strapless_is_24bit & 2)
  447. script |= 0x0200;
  448. } else
  449. if (bios->fp.strapless_is_24bit & 1)
  450. script |= 0x0200;
  451. if (nv_connector && nv_connector->edid &&
  452. (nv_connector->edid->revision >= 4) &&
  453. (nv_connector->edid->input & 0x70) >= 0x20)
  454. script |= 0x0200;
  455. }
  456. if (nouveau_uscript_lvds >= 0) {
  457. NV_INFO(dev, "override script 0x%04x with 0x%04x "
  458. "for output LVDS-%d\n", script,
  459. nouveau_uscript_lvds, or);
  460. script = nouveau_uscript_lvds;
  461. }
  462. break;
  463. case OUTPUT_TMDS:
  464. script = (mc >> 8) & 0xf;
  465. if (pxclk >= 165000)
  466. script |= 0x0100;
  467. if (nouveau_uscript_tmds >= 0) {
  468. NV_INFO(dev, "override script 0x%04x with 0x%04x "
  469. "for output TMDS-%d\n", script,
  470. nouveau_uscript_tmds, or);
  471. script = nouveau_uscript_tmds;
  472. }
  473. break;
  474. case OUTPUT_DP:
  475. script = (mc >> 8) & 0xf;
  476. break;
  477. case OUTPUT_ANALOG:
  478. script = 0xff;
  479. break;
  480. default:
  481. NV_ERROR(dev, "modeset on unsupported output type!\n");
  482. break;
  483. }
  484. return script;
  485. }
  486. static void
  487. nv50_display_vblank_crtc_handler(struct drm_device *dev, int crtc)
  488. {
  489. struct drm_nouveau_private *dev_priv = dev->dev_private;
  490. struct nouveau_channel *chan, *tmp;
  491. list_for_each_entry_safe(chan, tmp, &dev_priv->vbl_waiting,
  492. nvsw.vbl_wait) {
  493. if (chan->nvsw.vblsem_head != crtc)
  494. continue;
  495. nouveau_bo_wr32(chan->notifier_bo, chan->nvsw.vblsem_offset,
  496. chan->nvsw.vblsem_rval);
  497. list_del(&chan->nvsw.vbl_wait);
  498. drm_vblank_put(dev, crtc);
  499. }
  500. drm_handle_vblank(dev, crtc);
  501. }
  502. static void
  503. nv50_display_vblank_handler(struct drm_device *dev, uint32_t intr)
  504. {
  505. if (intr & NV50_PDISPLAY_INTR_1_VBLANK_CRTC_0)
  506. nv50_display_vblank_crtc_handler(dev, 0);
  507. if (intr & NV50_PDISPLAY_INTR_1_VBLANK_CRTC_1)
  508. nv50_display_vblank_crtc_handler(dev, 1);
  509. nv_wr32(dev, NV50_PDISPLAY_INTR_1, NV50_PDISPLAY_INTR_1_VBLANK_CRTC);
  510. }
  511. static void
  512. nv50_display_unk10_handler(struct drm_device *dev)
  513. {
  514. struct drm_nouveau_private *dev_priv = dev->dev_private;
  515. struct nv50_display *disp = nv50_display(dev);
  516. u32 unk30 = nv_rd32(dev, 0x610030), mc;
  517. int i, crtc, or, type = OUTPUT_ANY;
  518. NV_DEBUG_KMS(dev, "0x610030: 0x%08x\n", unk30);
  519. disp->irq.dcb = NULL;
  520. nv_wr32(dev, 0x619494, nv_rd32(dev, 0x619494) & ~8);
  521. /* Determine which CRTC we're dealing with, only 1 ever will be
  522. * signalled at the same time with the current nouveau code.
  523. */
  524. crtc = ffs((unk30 & 0x00000060) >> 5) - 1;
  525. if (crtc < 0)
  526. goto ack;
  527. /* Nothing needs to be done for the encoder */
  528. crtc = ffs((unk30 & 0x00000180) >> 7) - 1;
  529. if (crtc < 0)
  530. goto ack;
  531. /* Find which encoder was connected to the CRTC */
  532. for (i = 0; type == OUTPUT_ANY && i < 3; i++) {
  533. mc = nv_rd32(dev, NV50_PDISPLAY_DAC_MODE_CTRL_C(i));
  534. NV_DEBUG_KMS(dev, "DAC-%d mc: 0x%08x\n", i, mc);
  535. if (!(mc & (1 << crtc)))
  536. continue;
  537. switch ((mc & 0x00000f00) >> 8) {
  538. case 0: type = OUTPUT_ANALOG; break;
  539. case 1: type = OUTPUT_TV; break;
  540. default:
  541. NV_ERROR(dev, "invalid mc, DAC-%d: 0x%08x\n", i, mc);
  542. goto ack;
  543. }
  544. or = i;
  545. }
  546. for (i = 0; type == OUTPUT_ANY && i < nv50_sor_nr(dev); i++) {
  547. if (dev_priv->chipset < 0x90 ||
  548. dev_priv->chipset == 0x92 ||
  549. dev_priv->chipset == 0xa0)
  550. mc = nv_rd32(dev, NV50_PDISPLAY_SOR_MODE_CTRL_C(i));
  551. else
  552. mc = nv_rd32(dev, NV90_PDISPLAY_SOR_MODE_CTRL_C(i));
  553. NV_DEBUG_KMS(dev, "SOR-%d mc: 0x%08x\n", i, mc);
  554. if (!(mc & (1 << crtc)))
  555. continue;
  556. switch ((mc & 0x00000f00) >> 8) {
  557. case 0: type = OUTPUT_LVDS; break;
  558. case 1: type = OUTPUT_TMDS; break;
  559. case 2: type = OUTPUT_TMDS; break;
  560. case 5: type = OUTPUT_TMDS; break;
  561. case 8: type = OUTPUT_DP; break;
  562. case 9: type = OUTPUT_DP; break;
  563. default:
  564. NV_ERROR(dev, "invalid mc, SOR-%d: 0x%08x\n", i, mc);
  565. goto ack;
  566. }
  567. or = i;
  568. }
  569. /* There was no encoder to disable */
  570. if (type == OUTPUT_ANY)
  571. goto ack;
  572. /* Disable the encoder */
  573. for (i = 0; i < dev_priv->vbios.dcb.entries; i++) {
  574. struct dcb_entry *dcb = &dev_priv->vbios.dcb.entry[i];
  575. if (dcb->type == type && (dcb->or & (1 << or))) {
  576. nouveau_bios_run_display_table(dev, dcb, 0, -1);
  577. disp->irq.dcb = dcb;
  578. goto ack;
  579. }
  580. }
  581. NV_ERROR(dev, "no dcb for %d %d 0x%08x\n", or, type, mc);
  582. ack:
  583. nv_wr32(dev, NV50_PDISPLAY_INTR_1, NV50_PDISPLAY_INTR_1_CLK_UNK10);
  584. nv_wr32(dev, 0x610030, 0x80000000);
  585. }
  586. static void
  587. nv50_display_unk20_dp_hack(struct drm_device *dev, struct dcb_entry *dcb)
  588. {
  589. int or = ffs(dcb->or) - 1, link = !(dcb->dpconf.sor.link & 1);
  590. struct drm_encoder *encoder;
  591. uint32_t tmp, unk0 = 0, unk1 = 0;
  592. if (dcb->type != OUTPUT_DP)
  593. return;
  594. list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
  595. struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
  596. if (nv_encoder->dcb == dcb) {
  597. unk0 = nv_encoder->dp.unk0;
  598. unk1 = nv_encoder->dp.unk1;
  599. break;
  600. }
  601. }
  602. if (unk0 || unk1) {
  603. tmp = nv_rd32(dev, NV50_SOR_DP_CTRL(or, link));
  604. tmp &= 0xfffffe03;
  605. nv_wr32(dev, NV50_SOR_DP_CTRL(or, link), tmp | unk0);
  606. tmp = nv_rd32(dev, NV50_SOR_DP_UNK128(or, link));
  607. tmp &= 0xfef080c0;
  608. nv_wr32(dev, NV50_SOR_DP_UNK128(or, link), tmp | unk1);
  609. }
  610. }
  611. static void
  612. nv50_display_unk20_handler(struct drm_device *dev)
  613. {
  614. struct drm_nouveau_private *dev_priv = dev->dev_private;
  615. struct nv50_display *disp = nv50_display(dev);
  616. u32 unk30 = nv_rd32(dev, 0x610030), tmp, pclk, script, mc = 0;
  617. struct dcb_entry *dcb;
  618. int i, crtc, or, type = OUTPUT_ANY;
  619. NV_DEBUG_KMS(dev, "0x610030: 0x%08x\n", unk30);
  620. dcb = disp->irq.dcb;
  621. if (dcb) {
  622. nouveau_bios_run_display_table(dev, dcb, 0, -2);
  623. disp->irq.dcb = NULL;
  624. }
  625. /* CRTC clock change requested? */
  626. crtc = ffs((unk30 & 0x00000600) >> 9) - 1;
  627. if (crtc >= 0) {
  628. pclk = nv_rd32(dev, NV50_PDISPLAY_CRTC_P(crtc, CLOCK));
  629. pclk &= 0x003fffff;
  630. nv50_crtc_set_clock(dev, crtc, pclk);
  631. tmp = nv_rd32(dev, NV50_PDISPLAY_CRTC_CLK_CTRL2(crtc));
  632. tmp &= ~0x000000f;
  633. nv_wr32(dev, NV50_PDISPLAY_CRTC_CLK_CTRL2(crtc), tmp);
  634. }
  635. /* Nothing needs to be done for the encoder */
  636. crtc = ffs((unk30 & 0x00000180) >> 7) - 1;
  637. if (crtc < 0)
  638. goto ack;
  639. pclk = nv_rd32(dev, NV50_PDISPLAY_CRTC_P(crtc, CLOCK)) & 0x003fffff;
  640. /* Find which encoder is connected to the CRTC */
  641. for (i = 0; type == OUTPUT_ANY && i < 3; i++) {
  642. mc = nv_rd32(dev, NV50_PDISPLAY_DAC_MODE_CTRL_P(i));
  643. NV_DEBUG_KMS(dev, "DAC-%d mc: 0x%08x\n", i, mc);
  644. if (!(mc & (1 << crtc)))
  645. continue;
  646. switch ((mc & 0x00000f00) >> 8) {
  647. case 0: type = OUTPUT_ANALOG; break;
  648. case 1: type = OUTPUT_TV; break;
  649. default:
  650. NV_ERROR(dev, "invalid mc, DAC-%d: 0x%08x\n", i, mc);
  651. goto ack;
  652. }
  653. or = i;
  654. }
  655. for (i = 0; type == OUTPUT_ANY && i < nv50_sor_nr(dev); i++) {
  656. if (dev_priv->chipset < 0x90 ||
  657. dev_priv->chipset == 0x92 ||
  658. dev_priv->chipset == 0xa0)
  659. mc = nv_rd32(dev, NV50_PDISPLAY_SOR_MODE_CTRL_P(i));
  660. else
  661. mc = nv_rd32(dev, NV90_PDISPLAY_SOR_MODE_CTRL_P(i));
  662. NV_DEBUG_KMS(dev, "SOR-%d mc: 0x%08x\n", i, mc);
  663. if (!(mc & (1 << crtc)))
  664. continue;
  665. switch ((mc & 0x00000f00) >> 8) {
  666. case 0: type = OUTPUT_LVDS; break;
  667. case 1: type = OUTPUT_TMDS; break;
  668. case 2: type = OUTPUT_TMDS; break;
  669. case 5: type = OUTPUT_TMDS; break;
  670. case 8: type = OUTPUT_DP; break;
  671. case 9: type = OUTPUT_DP; break;
  672. default:
  673. NV_ERROR(dev, "invalid mc, SOR-%d: 0x%08x\n", i, mc);
  674. goto ack;
  675. }
  676. or = i;
  677. }
  678. if (type == OUTPUT_ANY)
  679. goto ack;
  680. /* Enable the encoder */
  681. for (i = 0; i < dev_priv->vbios.dcb.entries; i++) {
  682. dcb = &dev_priv->vbios.dcb.entry[i];
  683. if (dcb->type == type && (dcb->or & (1 << or)))
  684. break;
  685. }
  686. if (i == dev_priv->vbios.dcb.entries) {
  687. NV_ERROR(dev, "no dcb for %d %d 0x%08x\n", or, type, mc);
  688. goto ack;
  689. }
  690. script = nv50_display_script_select(dev, dcb, mc, pclk);
  691. nouveau_bios_run_display_table(dev, dcb, script, pclk);
  692. nv50_display_unk20_dp_hack(dev, dcb);
  693. if (dcb->type != OUTPUT_ANALOG) {
  694. tmp = nv_rd32(dev, NV50_PDISPLAY_SOR_CLK_CTRL2(or));
  695. tmp &= ~0x00000f0f;
  696. if (script & 0x0100)
  697. tmp |= 0x00000101;
  698. nv_wr32(dev, NV50_PDISPLAY_SOR_CLK_CTRL2(or), tmp);
  699. } else {
  700. nv_wr32(dev, NV50_PDISPLAY_DAC_CLK_CTRL2(or), 0);
  701. }
  702. disp->irq.dcb = dcb;
  703. disp->irq.pclk = pclk;
  704. disp->irq.script = script;
  705. ack:
  706. nv_wr32(dev, NV50_PDISPLAY_INTR_1, NV50_PDISPLAY_INTR_1_CLK_UNK20);
  707. nv_wr32(dev, 0x610030, 0x80000000);
  708. }
  709. /* If programming a TMDS output on a SOR that can also be configured for
  710. * DisplayPort, make sure NV50_SOR_DP_CTRL_ENABLE is forced off.
  711. *
  712. * It looks like the VBIOS TMDS scripts make an attempt at this, however,
  713. * the VBIOS scripts on at least one board I have only switch it off on
  714. * link 0, causing a blank display if the output has previously been
  715. * programmed for DisplayPort.
  716. */
  717. static void
  718. nv50_display_unk40_dp_set_tmds(struct drm_device *dev, struct dcb_entry *dcb)
  719. {
  720. int or = ffs(dcb->or) - 1, link = !(dcb->dpconf.sor.link & 1);
  721. struct drm_encoder *encoder;
  722. u32 tmp;
  723. if (dcb->type != OUTPUT_TMDS)
  724. return;
  725. list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
  726. struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
  727. if (nv_encoder->dcb->type == OUTPUT_DP &&
  728. nv_encoder->dcb->or & (1 << or)) {
  729. tmp = nv_rd32(dev, NV50_SOR_DP_CTRL(or, link));
  730. tmp &= ~NV50_SOR_DP_CTRL_ENABLED;
  731. nv_wr32(dev, NV50_SOR_DP_CTRL(or, link), tmp);
  732. break;
  733. }
  734. }
  735. }
  736. static void
  737. nv50_display_unk40_handler(struct drm_device *dev)
  738. {
  739. struct nv50_display *disp = nv50_display(dev);
  740. struct dcb_entry *dcb = disp->irq.dcb;
  741. u16 script = disp->irq.script;
  742. u32 unk30 = nv_rd32(dev, 0x610030), pclk = disp->irq.pclk;
  743. NV_DEBUG_KMS(dev, "0x610030: 0x%08x\n", unk30);
  744. disp->irq.dcb = NULL;
  745. if (!dcb)
  746. goto ack;
  747. nouveau_bios_run_display_table(dev, dcb, script, -pclk);
  748. nv50_display_unk40_dp_set_tmds(dev, dcb);
  749. ack:
  750. nv_wr32(dev, NV50_PDISPLAY_INTR_1, NV50_PDISPLAY_INTR_1_CLK_UNK40);
  751. nv_wr32(dev, 0x610030, 0x80000000);
  752. nv_wr32(dev, 0x619494, nv_rd32(dev, 0x619494) | 8);
  753. }
  754. static void
  755. nv50_display_bh(unsigned long data)
  756. {
  757. struct drm_device *dev = (struct drm_device *)data;
  758. for (;;) {
  759. uint32_t intr0 = nv_rd32(dev, NV50_PDISPLAY_INTR_0);
  760. uint32_t intr1 = nv_rd32(dev, NV50_PDISPLAY_INTR_1);
  761. NV_DEBUG_KMS(dev, "PDISPLAY_INTR_BH 0x%08x 0x%08x\n", intr0, intr1);
  762. if (intr1 & NV50_PDISPLAY_INTR_1_CLK_UNK10)
  763. nv50_display_unk10_handler(dev);
  764. else
  765. if (intr1 & NV50_PDISPLAY_INTR_1_CLK_UNK20)
  766. nv50_display_unk20_handler(dev);
  767. else
  768. if (intr1 & NV50_PDISPLAY_INTR_1_CLK_UNK40)
  769. nv50_display_unk40_handler(dev);
  770. else
  771. break;
  772. }
  773. nv_wr32(dev, NV03_PMC_INTR_EN_0, 1);
  774. }
  775. static void
  776. nv50_display_error_handler(struct drm_device *dev)
  777. {
  778. u32 channels = (nv_rd32(dev, NV50_PDISPLAY_INTR_0) & 0x001f0000) >> 16;
  779. u32 addr, data;
  780. int chid;
  781. for (chid = 0; chid < 5; chid++) {
  782. if (!(channels & (1 << chid)))
  783. continue;
  784. nv_wr32(dev, NV50_PDISPLAY_INTR_0, 0x00010000 << chid);
  785. addr = nv_rd32(dev, NV50_PDISPLAY_TRAPPED_ADDR(chid));
  786. data = nv_rd32(dev, NV50_PDISPLAY_TRAPPED_DATA(chid));
  787. NV_ERROR(dev, "EvoCh %d Mthd 0x%04x Data 0x%08x "
  788. "(0x%04x 0x%02x)\n", chid,
  789. addr & 0xffc, data, addr >> 16, (addr >> 12) & 0xf);
  790. nv_wr32(dev, NV50_PDISPLAY_TRAPPED_ADDR(chid), 0x90000000);
  791. }
  792. }
  793. static void
  794. nv50_display_isr(struct drm_device *dev)
  795. {
  796. struct nv50_display *disp = nv50_display(dev);
  797. uint32_t delayed = 0;
  798. while (nv_rd32(dev, NV50_PMC_INTR_0) & NV50_PMC_INTR_0_DISPLAY) {
  799. uint32_t intr0 = nv_rd32(dev, NV50_PDISPLAY_INTR_0);
  800. uint32_t intr1 = nv_rd32(dev, NV50_PDISPLAY_INTR_1);
  801. uint32_t clock;
  802. NV_DEBUG_KMS(dev, "PDISPLAY_INTR 0x%08x 0x%08x\n", intr0, intr1);
  803. if (!intr0 && !(intr1 & ~delayed))
  804. break;
  805. if (intr0 & 0x001f0000) {
  806. nv50_display_error_handler(dev);
  807. intr0 &= ~0x001f0000;
  808. }
  809. if (intr1 & NV50_PDISPLAY_INTR_1_VBLANK_CRTC) {
  810. nv50_display_vblank_handler(dev, intr1);
  811. intr1 &= ~NV50_PDISPLAY_INTR_1_VBLANK_CRTC;
  812. }
  813. clock = (intr1 & (NV50_PDISPLAY_INTR_1_CLK_UNK10 |
  814. NV50_PDISPLAY_INTR_1_CLK_UNK20 |
  815. NV50_PDISPLAY_INTR_1_CLK_UNK40));
  816. if (clock) {
  817. nv_wr32(dev, NV03_PMC_INTR_EN_0, 0);
  818. tasklet_schedule(&disp->tasklet);
  819. delayed |= clock;
  820. intr1 &= ~clock;
  821. }
  822. if (intr0) {
  823. NV_ERROR(dev, "unknown PDISPLAY_INTR_0: 0x%08x\n", intr0);
  824. nv_wr32(dev, NV50_PDISPLAY_INTR_0, intr0);
  825. }
  826. if (intr1) {
  827. NV_ERROR(dev,
  828. "unknown PDISPLAY_INTR_1: 0x%08x\n", intr1);
  829. nv_wr32(dev, NV50_PDISPLAY_INTR_1, intr1);
  830. }
  831. }
  832. }