nv50_display.c 28 KB

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