nv50_display.c 28 KB

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