radeon_display.c 46 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507
  1. /*
  2. * Copyright 2007-8 Advanced Micro Devices, Inc.
  3. * Copyright 2008 Red Hat Inc.
  4. *
  5. * Permission is hereby granted, free of charge, to any person obtaining a
  6. * copy of this software and associated documentation files (the "Software"),
  7. * to deal in the Software without restriction, including without limitation
  8. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  9. * and/or sell copies of the Software, and to permit persons to whom the
  10. * Software is furnished to do so, subject to the following conditions:
  11. *
  12. * The above copyright notice and this permission notice shall be included in
  13. * all copies or substantial portions of the Software.
  14. *
  15. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  18. * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
  19. * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  20. * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  21. * OTHER DEALINGS IN THE SOFTWARE.
  22. *
  23. * Authors: Dave Airlie
  24. * Alex Deucher
  25. */
  26. #include "drmP.h"
  27. #include "radeon_drm.h"
  28. #include "radeon.h"
  29. #include "atom.h"
  30. #include <asm/div64.h>
  31. #include "drm_crtc_helper.h"
  32. #include "drm_edid.h"
  33. static int radeon_ddc_dump(struct drm_connector *connector);
  34. static void avivo_crtc_load_lut(struct drm_crtc *crtc)
  35. {
  36. struct radeon_crtc *radeon_crtc = to_radeon_crtc(crtc);
  37. struct drm_device *dev = crtc->dev;
  38. struct radeon_device *rdev = dev->dev_private;
  39. int i;
  40. DRM_DEBUG_KMS("%d\n", radeon_crtc->crtc_id);
  41. WREG32(AVIVO_DC_LUTA_CONTROL + radeon_crtc->crtc_offset, 0);
  42. WREG32(AVIVO_DC_LUTA_BLACK_OFFSET_BLUE + radeon_crtc->crtc_offset, 0);
  43. WREG32(AVIVO_DC_LUTA_BLACK_OFFSET_GREEN + radeon_crtc->crtc_offset, 0);
  44. WREG32(AVIVO_DC_LUTA_BLACK_OFFSET_RED + radeon_crtc->crtc_offset, 0);
  45. WREG32(AVIVO_DC_LUTA_WHITE_OFFSET_BLUE + radeon_crtc->crtc_offset, 0xffff);
  46. WREG32(AVIVO_DC_LUTA_WHITE_OFFSET_GREEN + radeon_crtc->crtc_offset, 0xffff);
  47. WREG32(AVIVO_DC_LUTA_WHITE_OFFSET_RED + radeon_crtc->crtc_offset, 0xffff);
  48. WREG32(AVIVO_DC_LUT_RW_SELECT, radeon_crtc->crtc_id);
  49. WREG32(AVIVO_DC_LUT_RW_MODE, 0);
  50. WREG32(AVIVO_DC_LUT_WRITE_EN_MASK, 0x0000003f);
  51. WREG8(AVIVO_DC_LUT_RW_INDEX, 0);
  52. for (i = 0; i < 256; i++) {
  53. WREG32(AVIVO_DC_LUT_30_COLOR,
  54. (radeon_crtc->lut_r[i] << 20) |
  55. (radeon_crtc->lut_g[i] << 10) |
  56. (radeon_crtc->lut_b[i] << 0));
  57. }
  58. WREG32(AVIVO_D1GRPH_LUT_SEL + radeon_crtc->crtc_offset, radeon_crtc->crtc_id);
  59. }
  60. static void dce4_crtc_load_lut(struct drm_crtc *crtc)
  61. {
  62. struct radeon_crtc *radeon_crtc = to_radeon_crtc(crtc);
  63. struct drm_device *dev = crtc->dev;
  64. struct radeon_device *rdev = dev->dev_private;
  65. int i;
  66. DRM_DEBUG_KMS("%d\n", radeon_crtc->crtc_id);
  67. WREG32(EVERGREEN_DC_LUT_CONTROL + radeon_crtc->crtc_offset, 0);
  68. WREG32(EVERGREEN_DC_LUT_BLACK_OFFSET_BLUE + radeon_crtc->crtc_offset, 0);
  69. WREG32(EVERGREEN_DC_LUT_BLACK_OFFSET_GREEN + radeon_crtc->crtc_offset, 0);
  70. WREG32(EVERGREEN_DC_LUT_BLACK_OFFSET_RED + radeon_crtc->crtc_offset, 0);
  71. WREG32(EVERGREEN_DC_LUT_WHITE_OFFSET_BLUE + radeon_crtc->crtc_offset, 0xffff);
  72. WREG32(EVERGREEN_DC_LUT_WHITE_OFFSET_GREEN + radeon_crtc->crtc_offset, 0xffff);
  73. WREG32(EVERGREEN_DC_LUT_WHITE_OFFSET_RED + radeon_crtc->crtc_offset, 0xffff);
  74. WREG32(EVERGREEN_DC_LUT_RW_MODE + radeon_crtc->crtc_offset, 0);
  75. WREG32(EVERGREEN_DC_LUT_WRITE_EN_MASK + radeon_crtc->crtc_offset, 0x00000007);
  76. WREG32(EVERGREEN_DC_LUT_RW_INDEX + radeon_crtc->crtc_offset, 0);
  77. for (i = 0; i < 256; i++) {
  78. WREG32(EVERGREEN_DC_LUT_30_COLOR + radeon_crtc->crtc_offset,
  79. (radeon_crtc->lut_r[i] << 20) |
  80. (radeon_crtc->lut_g[i] << 10) |
  81. (radeon_crtc->lut_b[i] << 0));
  82. }
  83. }
  84. static void dce5_crtc_load_lut(struct drm_crtc *crtc)
  85. {
  86. struct radeon_crtc *radeon_crtc = to_radeon_crtc(crtc);
  87. struct drm_device *dev = crtc->dev;
  88. struct radeon_device *rdev = dev->dev_private;
  89. int i;
  90. DRM_DEBUG_KMS("%d\n", radeon_crtc->crtc_id);
  91. WREG32(NI_INPUT_CSC_CONTROL + radeon_crtc->crtc_offset,
  92. (NI_INPUT_CSC_GRPH_MODE(NI_INPUT_CSC_BYPASS) |
  93. NI_INPUT_CSC_OVL_MODE(NI_INPUT_CSC_BYPASS)));
  94. WREG32(NI_PRESCALE_GRPH_CONTROL + radeon_crtc->crtc_offset,
  95. NI_GRPH_PRESCALE_BYPASS);
  96. WREG32(NI_PRESCALE_OVL_CONTROL + radeon_crtc->crtc_offset,
  97. NI_OVL_PRESCALE_BYPASS);
  98. WREG32(NI_INPUT_GAMMA_CONTROL + radeon_crtc->crtc_offset,
  99. (NI_GRPH_INPUT_GAMMA_MODE(NI_INPUT_GAMMA_USE_LUT) |
  100. NI_OVL_INPUT_GAMMA_MODE(NI_INPUT_GAMMA_USE_LUT)));
  101. WREG32(EVERGREEN_DC_LUT_CONTROL + radeon_crtc->crtc_offset, 0);
  102. WREG32(EVERGREEN_DC_LUT_BLACK_OFFSET_BLUE + radeon_crtc->crtc_offset, 0);
  103. WREG32(EVERGREEN_DC_LUT_BLACK_OFFSET_GREEN + radeon_crtc->crtc_offset, 0);
  104. WREG32(EVERGREEN_DC_LUT_BLACK_OFFSET_RED + radeon_crtc->crtc_offset, 0);
  105. WREG32(EVERGREEN_DC_LUT_WHITE_OFFSET_BLUE + radeon_crtc->crtc_offset, 0xffff);
  106. WREG32(EVERGREEN_DC_LUT_WHITE_OFFSET_GREEN + radeon_crtc->crtc_offset, 0xffff);
  107. WREG32(EVERGREEN_DC_LUT_WHITE_OFFSET_RED + radeon_crtc->crtc_offset, 0xffff);
  108. WREG32(EVERGREEN_DC_LUT_RW_MODE + radeon_crtc->crtc_offset, 0);
  109. WREG32(EVERGREEN_DC_LUT_WRITE_EN_MASK + radeon_crtc->crtc_offset, 0x00000007);
  110. WREG32(EVERGREEN_DC_LUT_RW_INDEX + radeon_crtc->crtc_offset, 0);
  111. for (i = 0; i < 256; i++) {
  112. WREG32(EVERGREEN_DC_LUT_30_COLOR + radeon_crtc->crtc_offset,
  113. (radeon_crtc->lut_r[i] << 20) |
  114. (radeon_crtc->lut_g[i] << 10) |
  115. (radeon_crtc->lut_b[i] << 0));
  116. }
  117. WREG32(NI_DEGAMMA_CONTROL + radeon_crtc->crtc_offset,
  118. (NI_GRPH_DEGAMMA_MODE(NI_DEGAMMA_BYPASS) |
  119. NI_OVL_DEGAMMA_MODE(NI_DEGAMMA_BYPASS) |
  120. NI_ICON_DEGAMMA_MODE(NI_DEGAMMA_BYPASS) |
  121. NI_CURSOR_DEGAMMA_MODE(NI_DEGAMMA_BYPASS)));
  122. WREG32(NI_GAMUT_REMAP_CONTROL + radeon_crtc->crtc_offset,
  123. (NI_GRPH_GAMUT_REMAP_MODE(NI_GAMUT_REMAP_BYPASS) |
  124. NI_OVL_GAMUT_REMAP_MODE(NI_GAMUT_REMAP_BYPASS)));
  125. WREG32(NI_REGAMMA_CONTROL + radeon_crtc->crtc_offset,
  126. (NI_GRPH_REGAMMA_MODE(NI_REGAMMA_BYPASS) |
  127. NI_OVL_REGAMMA_MODE(NI_REGAMMA_BYPASS)));
  128. WREG32(NI_OUTPUT_CSC_CONTROL + radeon_crtc->crtc_offset,
  129. (NI_OUTPUT_CSC_GRPH_MODE(NI_OUTPUT_CSC_BYPASS) |
  130. NI_OUTPUT_CSC_OVL_MODE(NI_OUTPUT_CSC_BYPASS)));
  131. /* XXX match this to the depth of the crtc fmt block, move to modeset? */
  132. WREG32(0x6940 + radeon_crtc->crtc_offset, 0);
  133. }
  134. static void legacy_crtc_load_lut(struct drm_crtc *crtc)
  135. {
  136. struct radeon_crtc *radeon_crtc = to_radeon_crtc(crtc);
  137. struct drm_device *dev = crtc->dev;
  138. struct radeon_device *rdev = dev->dev_private;
  139. int i;
  140. uint32_t dac2_cntl;
  141. dac2_cntl = RREG32(RADEON_DAC_CNTL2);
  142. if (radeon_crtc->crtc_id == 0)
  143. dac2_cntl &= (uint32_t)~RADEON_DAC2_PALETTE_ACC_CTL;
  144. else
  145. dac2_cntl |= RADEON_DAC2_PALETTE_ACC_CTL;
  146. WREG32(RADEON_DAC_CNTL2, dac2_cntl);
  147. WREG8(RADEON_PALETTE_INDEX, 0);
  148. for (i = 0; i < 256; i++) {
  149. WREG32(RADEON_PALETTE_30_DATA,
  150. (radeon_crtc->lut_r[i] << 20) |
  151. (radeon_crtc->lut_g[i] << 10) |
  152. (radeon_crtc->lut_b[i] << 0));
  153. }
  154. }
  155. void radeon_crtc_load_lut(struct drm_crtc *crtc)
  156. {
  157. struct drm_device *dev = crtc->dev;
  158. struct radeon_device *rdev = dev->dev_private;
  159. if (!crtc->enabled)
  160. return;
  161. if (ASIC_IS_DCE5(rdev))
  162. dce5_crtc_load_lut(crtc);
  163. else if (ASIC_IS_DCE4(rdev))
  164. dce4_crtc_load_lut(crtc);
  165. else if (ASIC_IS_AVIVO(rdev))
  166. avivo_crtc_load_lut(crtc);
  167. else
  168. legacy_crtc_load_lut(crtc);
  169. }
  170. /** Sets the color ramps on behalf of fbcon */
  171. void radeon_crtc_fb_gamma_set(struct drm_crtc *crtc, u16 red, u16 green,
  172. u16 blue, int regno)
  173. {
  174. struct radeon_crtc *radeon_crtc = to_radeon_crtc(crtc);
  175. radeon_crtc->lut_r[regno] = red >> 6;
  176. radeon_crtc->lut_g[regno] = green >> 6;
  177. radeon_crtc->lut_b[regno] = blue >> 6;
  178. }
  179. /** Gets the color ramps on behalf of fbcon */
  180. void radeon_crtc_fb_gamma_get(struct drm_crtc *crtc, u16 *red, u16 *green,
  181. u16 *blue, int regno)
  182. {
  183. struct radeon_crtc *radeon_crtc = to_radeon_crtc(crtc);
  184. *red = radeon_crtc->lut_r[regno] << 6;
  185. *green = radeon_crtc->lut_g[regno] << 6;
  186. *blue = radeon_crtc->lut_b[regno] << 6;
  187. }
  188. static void radeon_crtc_gamma_set(struct drm_crtc *crtc, u16 *red, u16 *green,
  189. u16 *blue, uint32_t start, uint32_t size)
  190. {
  191. struct radeon_crtc *radeon_crtc = to_radeon_crtc(crtc);
  192. int end = (start + size > 256) ? 256 : start + size, i;
  193. /* userspace palettes are always correct as is */
  194. for (i = start; i < end; i++) {
  195. radeon_crtc->lut_r[i] = red[i] >> 6;
  196. radeon_crtc->lut_g[i] = green[i] >> 6;
  197. radeon_crtc->lut_b[i] = blue[i] >> 6;
  198. }
  199. radeon_crtc_load_lut(crtc);
  200. }
  201. static void radeon_crtc_destroy(struct drm_crtc *crtc)
  202. {
  203. struct radeon_crtc *radeon_crtc = to_radeon_crtc(crtc);
  204. drm_crtc_cleanup(crtc);
  205. kfree(radeon_crtc);
  206. }
  207. /*
  208. * Handle unpin events outside the interrupt handler proper.
  209. */
  210. static void radeon_unpin_work_func(struct work_struct *__work)
  211. {
  212. struct radeon_unpin_work *work =
  213. container_of(__work, struct radeon_unpin_work, work);
  214. int r;
  215. /* unpin of the old buffer */
  216. r = radeon_bo_reserve(work->old_rbo, false);
  217. if (likely(r == 0)) {
  218. r = radeon_bo_unpin(work->old_rbo);
  219. if (unlikely(r != 0)) {
  220. DRM_ERROR("failed to unpin buffer after flip\n");
  221. }
  222. radeon_bo_unreserve(work->old_rbo);
  223. } else
  224. DRM_ERROR("failed to reserve buffer after flip\n");
  225. kfree(work);
  226. }
  227. void radeon_crtc_handle_flip(struct radeon_device *rdev, int crtc_id)
  228. {
  229. struct radeon_crtc *radeon_crtc = rdev->mode_info.crtcs[crtc_id];
  230. struct radeon_unpin_work *work;
  231. struct drm_pending_vblank_event *e;
  232. struct timeval now;
  233. unsigned long flags;
  234. u32 update_pending;
  235. int vpos, hpos;
  236. spin_lock_irqsave(&rdev->ddev->event_lock, flags);
  237. work = radeon_crtc->unpin_work;
  238. if (work == NULL ||
  239. !radeon_fence_signaled(work->fence)) {
  240. spin_unlock_irqrestore(&rdev->ddev->event_lock, flags);
  241. return;
  242. }
  243. /* New pageflip, or just completion of a previous one? */
  244. if (!radeon_crtc->deferred_flip_completion) {
  245. /* do the flip (mmio) */
  246. update_pending = radeon_page_flip(rdev, crtc_id, work->new_crtc_base);
  247. } else {
  248. /* This is just a completion of a flip queued in crtc
  249. * at last invocation. Make sure we go directly to
  250. * completion routine.
  251. */
  252. update_pending = 0;
  253. radeon_crtc->deferred_flip_completion = 0;
  254. }
  255. /* Has the pageflip already completed in crtc, or is it certain
  256. * to complete in this vblank?
  257. */
  258. if (update_pending &&
  259. (DRM_SCANOUTPOS_VALID & radeon_get_crtc_scanoutpos(rdev->ddev, crtc_id,
  260. &vpos, &hpos)) &&
  261. (vpos >=0) &&
  262. (vpos < (99 * rdev->mode_info.crtcs[crtc_id]->base.hwmode.crtc_vdisplay)/100)) {
  263. /* crtc didn't flip in this target vblank interval,
  264. * but flip is pending in crtc. It will complete it
  265. * in next vblank interval, so complete the flip at
  266. * next vblank irq.
  267. */
  268. radeon_crtc->deferred_flip_completion = 1;
  269. spin_unlock_irqrestore(&rdev->ddev->event_lock, flags);
  270. return;
  271. }
  272. /* Pageflip (will be) certainly completed in this vblank. Clean up. */
  273. radeon_crtc->unpin_work = NULL;
  274. /* wakeup userspace */
  275. if (work->event) {
  276. e = work->event;
  277. e->event.sequence = drm_vblank_count_and_time(rdev->ddev, crtc_id, &now);
  278. e->event.tv_sec = now.tv_sec;
  279. e->event.tv_usec = now.tv_usec;
  280. list_add_tail(&e->base.link, &e->base.file_priv->event_list);
  281. wake_up_interruptible(&e->base.file_priv->event_wait);
  282. }
  283. spin_unlock_irqrestore(&rdev->ddev->event_lock, flags);
  284. drm_vblank_put(rdev->ddev, radeon_crtc->crtc_id);
  285. radeon_fence_unref(&work->fence);
  286. radeon_post_page_flip(work->rdev, work->crtc_id);
  287. schedule_work(&work->work);
  288. }
  289. static int radeon_crtc_page_flip(struct drm_crtc *crtc,
  290. struct drm_framebuffer *fb,
  291. struct drm_pending_vblank_event *event)
  292. {
  293. struct drm_device *dev = crtc->dev;
  294. struct radeon_device *rdev = dev->dev_private;
  295. struct radeon_crtc *radeon_crtc = to_radeon_crtc(crtc);
  296. struct radeon_framebuffer *old_radeon_fb;
  297. struct radeon_framebuffer *new_radeon_fb;
  298. struct drm_gem_object *obj;
  299. struct radeon_bo *rbo;
  300. struct radeon_fence *fence;
  301. struct radeon_unpin_work *work;
  302. unsigned long flags;
  303. u32 tiling_flags, pitch_pixels;
  304. u64 base;
  305. int r;
  306. work = kzalloc(sizeof *work, GFP_KERNEL);
  307. if (work == NULL)
  308. return -ENOMEM;
  309. r = radeon_fence_create(rdev, &fence);
  310. if (unlikely(r != 0)) {
  311. kfree(work);
  312. DRM_ERROR("flip queue: failed to create fence.\n");
  313. return -ENOMEM;
  314. }
  315. work->event = event;
  316. work->rdev = rdev;
  317. work->crtc_id = radeon_crtc->crtc_id;
  318. work->fence = radeon_fence_ref(fence);
  319. old_radeon_fb = to_radeon_framebuffer(crtc->fb);
  320. new_radeon_fb = to_radeon_framebuffer(fb);
  321. /* schedule unpin of the old buffer */
  322. obj = old_radeon_fb->obj;
  323. rbo = obj->driver_private;
  324. work->old_rbo = rbo;
  325. INIT_WORK(&work->work, radeon_unpin_work_func);
  326. /* We borrow the event spin lock for protecting unpin_work */
  327. spin_lock_irqsave(&dev->event_lock, flags);
  328. if (radeon_crtc->unpin_work) {
  329. spin_unlock_irqrestore(&dev->event_lock, flags);
  330. kfree(work);
  331. radeon_fence_unref(&fence);
  332. DRM_DEBUG_DRIVER("flip queue: crtc already busy\n");
  333. return -EBUSY;
  334. }
  335. radeon_crtc->unpin_work = work;
  336. radeon_crtc->deferred_flip_completion = 0;
  337. spin_unlock_irqrestore(&dev->event_lock, flags);
  338. /* pin the new buffer */
  339. obj = new_radeon_fb->obj;
  340. rbo = obj->driver_private;
  341. DRM_DEBUG_DRIVER("flip-ioctl() cur_fbo = %p, cur_bbo = %p\n",
  342. work->old_rbo, rbo);
  343. r = radeon_bo_reserve(rbo, false);
  344. if (unlikely(r != 0)) {
  345. DRM_ERROR("failed to reserve new rbo buffer before flip\n");
  346. goto pflip_cleanup;
  347. }
  348. r = radeon_bo_pin(rbo, RADEON_GEM_DOMAIN_VRAM, &base);
  349. if (unlikely(r != 0)) {
  350. radeon_bo_unreserve(rbo);
  351. r = -EINVAL;
  352. DRM_ERROR("failed to pin new rbo buffer before flip\n");
  353. goto pflip_cleanup;
  354. }
  355. radeon_bo_get_tiling_flags(rbo, &tiling_flags, NULL);
  356. radeon_bo_unreserve(rbo);
  357. if (!ASIC_IS_AVIVO(rdev)) {
  358. /* crtc offset is from display base addr not FB location */
  359. base -= radeon_crtc->legacy_display_base_addr;
  360. pitch_pixels = fb->pitch / (fb->bits_per_pixel / 8);
  361. if (tiling_flags & RADEON_TILING_MACRO) {
  362. if (ASIC_IS_R300(rdev)) {
  363. base &= ~0x7ff;
  364. } else {
  365. int byteshift = fb->bits_per_pixel >> 4;
  366. int tile_addr = (((crtc->y >> 3) * pitch_pixels + crtc->x) >> (8 - byteshift)) << 11;
  367. base += tile_addr + ((crtc->x << byteshift) % 256) + ((crtc->y % 8) << 8);
  368. }
  369. } else {
  370. int offset = crtc->y * pitch_pixels + crtc->x;
  371. switch (fb->bits_per_pixel) {
  372. case 8:
  373. default:
  374. offset *= 1;
  375. break;
  376. case 15:
  377. case 16:
  378. offset *= 2;
  379. break;
  380. case 24:
  381. offset *= 3;
  382. break;
  383. case 32:
  384. offset *= 4;
  385. break;
  386. }
  387. base += offset;
  388. }
  389. base &= ~7;
  390. }
  391. spin_lock_irqsave(&dev->event_lock, flags);
  392. work->new_crtc_base = base;
  393. spin_unlock_irqrestore(&dev->event_lock, flags);
  394. /* update crtc fb */
  395. crtc->fb = fb;
  396. r = drm_vblank_get(dev, radeon_crtc->crtc_id);
  397. if (r) {
  398. DRM_ERROR("failed to get vblank before flip\n");
  399. goto pflip_cleanup1;
  400. }
  401. /* 32 ought to cover us */
  402. r = radeon_ring_lock(rdev, 32);
  403. if (r) {
  404. DRM_ERROR("failed to lock the ring before flip\n");
  405. goto pflip_cleanup2;
  406. }
  407. /* emit the fence */
  408. radeon_fence_emit(rdev, fence);
  409. /* set the proper interrupt */
  410. radeon_pre_page_flip(rdev, radeon_crtc->crtc_id);
  411. /* fire the ring */
  412. radeon_ring_unlock_commit(rdev);
  413. return 0;
  414. pflip_cleanup2:
  415. drm_vblank_put(dev, radeon_crtc->crtc_id);
  416. pflip_cleanup1:
  417. r = radeon_bo_reserve(rbo, false);
  418. if (unlikely(r != 0)) {
  419. DRM_ERROR("failed to reserve new rbo in error path\n");
  420. goto pflip_cleanup;
  421. }
  422. r = radeon_bo_unpin(rbo);
  423. if (unlikely(r != 0)) {
  424. radeon_bo_unreserve(rbo);
  425. r = -EINVAL;
  426. DRM_ERROR("failed to unpin new rbo in error path\n");
  427. goto pflip_cleanup;
  428. }
  429. radeon_bo_unreserve(rbo);
  430. pflip_cleanup:
  431. spin_lock_irqsave(&dev->event_lock, flags);
  432. radeon_crtc->unpin_work = NULL;
  433. spin_unlock_irqrestore(&dev->event_lock, flags);
  434. radeon_fence_unref(&fence);
  435. kfree(work);
  436. return r;
  437. }
  438. static const struct drm_crtc_funcs radeon_crtc_funcs = {
  439. .cursor_set = radeon_crtc_cursor_set,
  440. .cursor_move = radeon_crtc_cursor_move,
  441. .gamma_set = radeon_crtc_gamma_set,
  442. .set_config = drm_crtc_helper_set_config,
  443. .destroy = radeon_crtc_destroy,
  444. .page_flip = radeon_crtc_page_flip,
  445. };
  446. static void radeon_crtc_init(struct drm_device *dev, int index)
  447. {
  448. struct radeon_device *rdev = dev->dev_private;
  449. struct radeon_crtc *radeon_crtc;
  450. int i;
  451. radeon_crtc = kzalloc(sizeof(struct radeon_crtc) + (RADEONFB_CONN_LIMIT * sizeof(struct drm_connector *)), GFP_KERNEL);
  452. if (radeon_crtc == NULL)
  453. return;
  454. drm_crtc_init(dev, &radeon_crtc->base, &radeon_crtc_funcs);
  455. drm_mode_crtc_set_gamma_size(&radeon_crtc->base, 256);
  456. radeon_crtc->crtc_id = index;
  457. rdev->mode_info.crtcs[index] = radeon_crtc;
  458. #if 0
  459. radeon_crtc->mode_set.crtc = &radeon_crtc->base;
  460. radeon_crtc->mode_set.connectors = (struct drm_connector **)(radeon_crtc + 1);
  461. radeon_crtc->mode_set.num_connectors = 0;
  462. #endif
  463. for (i = 0; i < 256; i++) {
  464. radeon_crtc->lut_r[i] = i << 2;
  465. radeon_crtc->lut_g[i] = i << 2;
  466. radeon_crtc->lut_b[i] = i << 2;
  467. }
  468. if (rdev->is_atom_bios && (ASIC_IS_AVIVO(rdev) || radeon_r4xx_atom))
  469. radeon_atombios_init_crtc(dev, radeon_crtc);
  470. else
  471. radeon_legacy_init_crtc(dev, radeon_crtc);
  472. }
  473. static const char *encoder_names[36] = {
  474. "NONE",
  475. "INTERNAL_LVDS",
  476. "INTERNAL_TMDS1",
  477. "INTERNAL_TMDS2",
  478. "INTERNAL_DAC1",
  479. "INTERNAL_DAC2",
  480. "INTERNAL_SDVOA",
  481. "INTERNAL_SDVOB",
  482. "SI170B",
  483. "CH7303",
  484. "CH7301",
  485. "INTERNAL_DVO1",
  486. "EXTERNAL_SDVOA",
  487. "EXTERNAL_SDVOB",
  488. "TITFP513",
  489. "INTERNAL_LVTM1",
  490. "VT1623",
  491. "HDMI_SI1930",
  492. "HDMI_INTERNAL",
  493. "INTERNAL_KLDSCP_TMDS1",
  494. "INTERNAL_KLDSCP_DVO1",
  495. "INTERNAL_KLDSCP_DAC1",
  496. "INTERNAL_KLDSCP_DAC2",
  497. "SI178",
  498. "MVPU_FPGA",
  499. "INTERNAL_DDI",
  500. "VT1625",
  501. "HDMI_SI1932",
  502. "DP_AN9801",
  503. "DP_DP501",
  504. "INTERNAL_UNIPHY",
  505. "INTERNAL_KLDSCP_LVTMA",
  506. "INTERNAL_UNIPHY1",
  507. "INTERNAL_UNIPHY2",
  508. "NUTMEG",
  509. "TRAVIS",
  510. };
  511. static const char *connector_names[15] = {
  512. "Unknown",
  513. "VGA",
  514. "DVI-I",
  515. "DVI-D",
  516. "DVI-A",
  517. "Composite",
  518. "S-video",
  519. "LVDS",
  520. "Component",
  521. "DIN",
  522. "DisplayPort",
  523. "HDMI-A",
  524. "HDMI-B",
  525. "TV",
  526. "eDP",
  527. };
  528. static const char *hpd_names[6] = {
  529. "HPD1",
  530. "HPD2",
  531. "HPD3",
  532. "HPD4",
  533. "HPD5",
  534. "HPD6",
  535. };
  536. static void radeon_print_display_setup(struct drm_device *dev)
  537. {
  538. struct drm_connector *connector;
  539. struct radeon_connector *radeon_connector;
  540. struct drm_encoder *encoder;
  541. struct radeon_encoder *radeon_encoder;
  542. uint32_t devices;
  543. int i = 0;
  544. DRM_INFO("Radeon Display Connectors\n");
  545. list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
  546. radeon_connector = to_radeon_connector(connector);
  547. DRM_INFO("Connector %d:\n", i);
  548. DRM_INFO(" %s\n", connector_names[connector->connector_type]);
  549. if (radeon_connector->hpd.hpd != RADEON_HPD_NONE)
  550. DRM_INFO(" %s\n", hpd_names[radeon_connector->hpd.hpd]);
  551. if (radeon_connector->ddc_bus) {
  552. DRM_INFO(" DDC: 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x\n",
  553. radeon_connector->ddc_bus->rec.mask_clk_reg,
  554. radeon_connector->ddc_bus->rec.mask_data_reg,
  555. radeon_connector->ddc_bus->rec.a_clk_reg,
  556. radeon_connector->ddc_bus->rec.a_data_reg,
  557. radeon_connector->ddc_bus->rec.en_clk_reg,
  558. radeon_connector->ddc_bus->rec.en_data_reg,
  559. radeon_connector->ddc_bus->rec.y_clk_reg,
  560. radeon_connector->ddc_bus->rec.y_data_reg);
  561. if (radeon_connector->router.ddc_valid)
  562. DRM_INFO(" DDC Router 0x%x/0x%x\n",
  563. radeon_connector->router.ddc_mux_control_pin,
  564. radeon_connector->router.ddc_mux_state);
  565. if (radeon_connector->router.cd_valid)
  566. DRM_INFO(" Clock/Data Router 0x%x/0x%x\n",
  567. radeon_connector->router.cd_mux_control_pin,
  568. radeon_connector->router.cd_mux_state);
  569. } else {
  570. if (connector->connector_type == DRM_MODE_CONNECTOR_VGA ||
  571. connector->connector_type == DRM_MODE_CONNECTOR_DVII ||
  572. connector->connector_type == DRM_MODE_CONNECTOR_DVID ||
  573. connector->connector_type == DRM_MODE_CONNECTOR_DVIA ||
  574. connector->connector_type == DRM_MODE_CONNECTOR_HDMIA ||
  575. connector->connector_type == DRM_MODE_CONNECTOR_HDMIB)
  576. DRM_INFO(" DDC: no ddc bus - possible BIOS bug - please report to xorg-driver-ati@lists.x.org\n");
  577. }
  578. DRM_INFO(" Encoders:\n");
  579. list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
  580. radeon_encoder = to_radeon_encoder(encoder);
  581. devices = radeon_encoder->devices & radeon_connector->devices;
  582. if (devices) {
  583. if (devices & ATOM_DEVICE_CRT1_SUPPORT)
  584. DRM_INFO(" CRT1: %s\n", encoder_names[radeon_encoder->encoder_id]);
  585. if (devices & ATOM_DEVICE_CRT2_SUPPORT)
  586. DRM_INFO(" CRT2: %s\n", encoder_names[radeon_encoder->encoder_id]);
  587. if (devices & ATOM_DEVICE_LCD1_SUPPORT)
  588. DRM_INFO(" LCD1: %s\n", encoder_names[radeon_encoder->encoder_id]);
  589. if (devices & ATOM_DEVICE_DFP1_SUPPORT)
  590. DRM_INFO(" DFP1: %s\n", encoder_names[radeon_encoder->encoder_id]);
  591. if (devices & ATOM_DEVICE_DFP2_SUPPORT)
  592. DRM_INFO(" DFP2: %s\n", encoder_names[radeon_encoder->encoder_id]);
  593. if (devices & ATOM_DEVICE_DFP3_SUPPORT)
  594. DRM_INFO(" DFP3: %s\n", encoder_names[radeon_encoder->encoder_id]);
  595. if (devices & ATOM_DEVICE_DFP4_SUPPORT)
  596. DRM_INFO(" DFP4: %s\n", encoder_names[radeon_encoder->encoder_id]);
  597. if (devices & ATOM_DEVICE_DFP5_SUPPORT)
  598. DRM_INFO(" DFP5: %s\n", encoder_names[radeon_encoder->encoder_id]);
  599. if (devices & ATOM_DEVICE_DFP6_SUPPORT)
  600. DRM_INFO(" DFP6: %s\n", encoder_names[radeon_encoder->encoder_id]);
  601. if (devices & ATOM_DEVICE_TV1_SUPPORT)
  602. DRM_INFO(" TV1: %s\n", encoder_names[radeon_encoder->encoder_id]);
  603. if (devices & ATOM_DEVICE_CV_SUPPORT)
  604. DRM_INFO(" CV: %s\n", encoder_names[radeon_encoder->encoder_id]);
  605. }
  606. }
  607. i++;
  608. }
  609. }
  610. static bool radeon_setup_enc_conn(struct drm_device *dev)
  611. {
  612. struct radeon_device *rdev = dev->dev_private;
  613. struct drm_connector *drm_connector;
  614. bool ret = false;
  615. if (rdev->bios) {
  616. if (rdev->is_atom_bios) {
  617. ret = radeon_get_atom_connector_info_from_supported_devices_table(dev);
  618. if (ret == false)
  619. ret = radeon_get_atom_connector_info_from_object_table(dev);
  620. } else {
  621. ret = radeon_get_legacy_connector_info_from_bios(dev);
  622. if (ret == false)
  623. ret = radeon_get_legacy_connector_info_from_table(dev);
  624. }
  625. } else {
  626. if (!ASIC_IS_AVIVO(rdev))
  627. ret = radeon_get_legacy_connector_info_from_table(dev);
  628. }
  629. if (ret) {
  630. radeon_setup_encoder_clones(dev);
  631. radeon_print_display_setup(dev);
  632. list_for_each_entry(drm_connector, &dev->mode_config.connector_list, head)
  633. radeon_ddc_dump(drm_connector);
  634. }
  635. return ret;
  636. }
  637. int radeon_ddc_get_modes(struct radeon_connector *radeon_connector)
  638. {
  639. struct drm_device *dev = radeon_connector->base.dev;
  640. struct radeon_device *rdev = dev->dev_private;
  641. int ret = 0;
  642. /* on hw with routers, select right port */
  643. if (radeon_connector->router.ddc_valid)
  644. radeon_router_select_ddc_port(radeon_connector);
  645. if ((radeon_connector->base.connector_type == DRM_MODE_CONNECTOR_DisplayPort) ||
  646. (radeon_connector->base.connector_type == DRM_MODE_CONNECTOR_eDP)) {
  647. struct radeon_connector_atom_dig *dig = radeon_connector->con_priv;
  648. if ((dig->dp_sink_type == CONNECTOR_OBJECT_ID_DISPLAYPORT ||
  649. dig->dp_sink_type == CONNECTOR_OBJECT_ID_eDP) && dig->dp_i2c_bus)
  650. radeon_connector->edid = drm_get_edid(&radeon_connector->base, &dig->dp_i2c_bus->adapter);
  651. }
  652. if (!radeon_connector->ddc_bus)
  653. return -1;
  654. if (!radeon_connector->edid) {
  655. radeon_connector->edid = drm_get_edid(&radeon_connector->base, &radeon_connector->ddc_bus->adapter);
  656. }
  657. if (!radeon_connector->edid) {
  658. if (rdev->is_atom_bios) {
  659. /* some laptops provide a hardcoded edid in rom for LCDs */
  660. if (((radeon_connector->base.connector_type == DRM_MODE_CONNECTOR_LVDS) ||
  661. (radeon_connector->base.connector_type == DRM_MODE_CONNECTOR_eDP)))
  662. radeon_connector->edid = radeon_bios_get_hardcoded_edid(rdev);
  663. } else
  664. /* some servers provide a hardcoded edid in rom for KVMs */
  665. radeon_connector->edid = radeon_bios_get_hardcoded_edid(rdev);
  666. }
  667. if (radeon_connector->edid) {
  668. drm_mode_connector_update_edid_property(&radeon_connector->base, radeon_connector->edid);
  669. ret = drm_add_edid_modes(&radeon_connector->base, radeon_connector->edid);
  670. return ret;
  671. }
  672. drm_mode_connector_update_edid_property(&radeon_connector->base, NULL);
  673. return 0;
  674. }
  675. static int radeon_ddc_dump(struct drm_connector *connector)
  676. {
  677. struct edid *edid;
  678. struct radeon_connector *radeon_connector = to_radeon_connector(connector);
  679. int ret = 0;
  680. /* on hw with routers, select right port */
  681. if (radeon_connector->router.ddc_valid)
  682. radeon_router_select_ddc_port(radeon_connector);
  683. if (!radeon_connector->ddc_bus)
  684. return -1;
  685. edid = drm_get_edid(connector, &radeon_connector->ddc_bus->adapter);
  686. if (edid) {
  687. kfree(edid);
  688. }
  689. return ret;
  690. }
  691. static inline uint32_t radeon_div(uint64_t n, uint32_t d)
  692. {
  693. uint64_t mod;
  694. n += d / 2;
  695. mod = do_div(n, d);
  696. return n;
  697. }
  698. void radeon_compute_pll(struct radeon_pll *pll,
  699. uint64_t freq,
  700. uint32_t *dot_clock_p,
  701. uint32_t *fb_div_p,
  702. uint32_t *frac_fb_div_p,
  703. uint32_t *ref_div_p,
  704. uint32_t *post_div_p)
  705. {
  706. uint32_t min_ref_div = pll->min_ref_div;
  707. uint32_t max_ref_div = pll->max_ref_div;
  708. uint32_t min_post_div = pll->min_post_div;
  709. uint32_t max_post_div = pll->max_post_div;
  710. uint32_t min_fractional_feed_div = 0;
  711. uint32_t max_fractional_feed_div = 0;
  712. uint32_t best_vco = pll->best_vco;
  713. uint32_t best_post_div = 1;
  714. uint32_t best_ref_div = 1;
  715. uint32_t best_feedback_div = 1;
  716. uint32_t best_frac_feedback_div = 0;
  717. uint32_t best_freq = -1;
  718. uint32_t best_error = 0xffffffff;
  719. uint32_t best_vco_diff = 1;
  720. uint32_t post_div;
  721. u32 pll_out_min, pll_out_max;
  722. DRM_DEBUG_KMS("PLL freq %llu %u %u\n", freq, pll->min_ref_div, pll->max_ref_div);
  723. freq = freq * 1000;
  724. if (pll->flags & RADEON_PLL_IS_LCD) {
  725. pll_out_min = pll->lcd_pll_out_min;
  726. pll_out_max = pll->lcd_pll_out_max;
  727. } else {
  728. pll_out_min = pll->pll_out_min;
  729. pll_out_max = pll->pll_out_max;
  730. }
  731. if (pll->flags & RADEON_PLL_USE_REF_DIV)
  732. min_ref_div = max_ref_div = pll->reference_div;
  733. else {
  734. while (min_ref_div < max_ref_div-1) {
  735. uint32_t mid = (min_ref_div + max_ref_div) / 2;
  736. uint32_t pll_in = pll->reference_freq / mid;
  737. if (pll_in < pll->pll_in_min)
  738. max_ref_div = mid;
  739. else if (pll_in > pll->pll_in_max)
  740. min_ref_div = mid;
  741. else
  742. break;
  743. }
  744. }
  745. if (pll->flags & RADEON_PLL_USE_POST_DIV)
  746. min_post_div = max_post_div = pll->post_div;
  747. if (pll->flags & RADEON_PLL_USE_FRAC_FB_DIV) {
  748. min_fractional_feed_div = pll->min_frac_feedback_div;
  749. max_fractional_feed_div = pll->max_frac_feedback_div;
  750. }
  751. for (post_div = max_post_div; post_div >= min_post_div; --post_div) {
  752. uint32_t ref_div;
  753. if ((pll->flags & RADEON_PLL_NO_ODD_POST_DIV) && (post_div & 1))
  754. continue;
  755. /* legacy radeons only have a few post_divs */
  756. if (pll->flags & RADEON_PLL_LEGACY) {
  757. if ((post_div == 5) ||
  758. (post_div == 7) ||
  759. (post_div == 9) ||
  760. (post_div == 10) ||
  761. (post_div == 11) ||
  762. (post_div == 13) ||
  763. (post_div == 14) ||
  764. (post_div == 15))
  765. continue;
  766. }
  767. for (ref_div = min_ref_div; ref_div <= max_ref_div; ++ref_div) {
  768. uint32_t feedback_div, current_freq = 0, error, vco_diff;
  769. uint32_t pll_in = pll->reference_freq / ref_div;
  770. uint32_t min_feed_div = pll->min_feedback_div;
  771. uint32_t max_feed_div = pll->max_feedback_div + 1;
  772. if (pll_in < pll->pll_in_min || pll_in > pll->pll_in_max)
  773. continue;
  774. while (min_feed_div < max_feed_div) {
  775. uint32_t vco;
  776. uint32_t min_frac_feed_div = min_fractional_feed_div;
  777. uint32_t max_frac_feed_div = max_fractional_feed_div + 1;
  778. uint32_t frac_feedback_div;
  779. uint64_t tmp;
  780. feedback_div = (min_feed_div + max_feed_div) / 2;
  781. tmp = (uint64_t)pll->reference_freq * feedback_div;
  782. vco = radeon_div(tmp, ref_div);
  783. if (vco < pll_out_min) {
  784. min_feed_div = feedback_div + 1;
  785. continue;
  786. } else if (vco > pll_out_max) {
  787. max_feed_div = feedback_div;
  788. continue;
  789. }
  790. while (min_frac_feed_div < max_frac_feed_div) {
  791. frac_feedback_div = (min_frac_feed_div + max_frac_feed_div) / 2;
  792. tmp = (uint64_t)pll->reference_freq * 10000 * feedback_div;
  793. tmp += (uint64_t)pll->reference_freq * 1000 * frac_feedback_div;
  794. current_freq = radeon_div(tmp, ref_div * post_div);
  795. if (pll->flags & RADEON_PLL_PREFER_CLOSEST_LOWER) {
  796. if (freq < current_freq)
  797. error = 0xffffffff;
  798. else
  799. error = freq - current_freq;
  800. } else
  801. error = abs(current_freq - freq);
  802. vco_diff = abs(vco - best_vco);
  803. if ((best_vco == 0 && error < best_error) ||
  804. (best_vco != 0 &&
  805. ((best_error > 100 && error < best_error - 100) ||
  806. (abs(error - best_error) < 100 && vco_diff < best_vco_diff)))) {
  807. best_post_div = post_div;
  808. best_ref_div = ref_div;
  809. best_feedback_div = feedback_div;
  810. best_frac_feedback_div = frac_feedback_div;
  811. best_freq = current_freq;
  812. best_error = error;
  813. best_vco_diff = vco_diff;
  814. } else if (current_freq == freq) {
  815. if (best_freq == -1) {
  816. best_post_div = post_div;
  817. best_ref_div = ref_div;
  818. best_feedback_div = feedback_div;
  819. best_frac_feedback_div = frac_feedback_div;
  820. best_freq = current_freq;
  821. best_error = error;
  822. best_vco_diff = vco_diff;
  823. } else if (((pll->flags & RADEON_PLL_PREFER_LOW_REF_DIV) && (ref_div < best_ref_div)) ||
  824. ((pll->flags & RADEON_PLL_PREFER_HIGH_REF_DIV) && (ref_div > best_ref_div)) ||
  825. ((pll->flags & RADEON_PLL_PREFER_LOW_FB_DIV) && (feedback_div < best_feedback_div)) ||
  826. ((pll->flags & RADEON_PLL_PREFER_HIGH_FB_DIV) && (feedback_div > best_feedback_div)) ||
  827. ((pll->flags & RADEON_PLL_PREFER_LOW_POST_DIV) && (post_div < best_post_div)) ||
  828. ((pll->flags & RADEON_PLL_PREFER_HIGH_POST_DIV) && (post_div > best_post_div))) {
  829. best_post_div = post_div;
  830. best_ref_div = ref_div;
  831. best_feedback_div = feedback_div;
  832. best_frac_feedback_div = frac_feedback_div;
  833. best_freq = current_freq;
  834. best_error = error;
  835. best_vco_diff = vco_diff;
  836. }
  837. }
  838. if (current_freq < freq)
  839. min_frac_feed_div = frac_feedback_div + 1;
  840. else
  841. max_frac_feed_div = frac_feedback_div;
  842. }
  843. if (current_freq < freq)
  844. min_feed_div = feedback_div + 1;
  845. else
  846. max_feed_div = feedback_div;
  847. }
  848. }
  849. }
  850. *dot_clock_p = best_freq / 10000;
  851. *fb_div_p = best_feedback_div;
  852. *frac_fb_div_p = best_frac_feedback_div;
  853. *ref_div_p = best_ref_div;
  854. *post_div_p = best_post_div;
  855. }
  856. static void radeon_user_framebuffer_destroy(struct drm_framebuffer *fb)
  857. {
  858. struct radeon_framebuffer *radeon_fb = to_radeon_framebuffer(fb);
  859. if (radeon_fb->obj) {
  860. drm_gem_object_unreference_unlocked(radeon_fb->obj);
  861. }
  862. drm_framebuffer_cleanup(fb);
  863. kfree(radeon_fb);
  864. }
  865. static int radeon_user_framebuffer_create_handle(struct drm_framebuffer *fb,
  866. struct drm_file *file_priv,
  867. unsigned int *handle)
  868. {
  869. struct radeon_framebuffer *radeon_fb = to_radeon_framebuffer(fb);
  870. return drm_gem_handle_create(file_priv, radeon_fb->obj, handle);
  871. }
  872. static const struct drm_framebuffer_funcs radeon_fb_funcs = {
  873. .destroy = radeon_user_framebuffer_destroy,
  874. .create_handle = radeon_user_framebuffer_create_handle,
  875. };
  876. void
  877. radeon_framebuffer_init(struct drm_device *dev,
  878. struct radeon_framebuffer *rfb,
  879. struct drm_mode_fb_cmd *mode_cmd,
  880. struct drm_gem_object *obj)
  881. {
  882. rfb->obj = obj;
  883. drm_framebuffer_init(dev, &rfb->base, &radeon_fb_funcs);
  884. drm_helper_mode_fill_fb_struct(&rfb->base, mode_cmd);
  885. }
  886. static struct drm_framebuffer *
  887. radeon_user_framebuffer_create(struct drm_device *dev,
  888. struct drm_file *file_priv,
  889. struct drm_mode_fb_cmd *mode_cmd)
  890. {
  891. struct drm_gem_object *obj;
  892. struct radeon_framebuffer *radeon_fb;
  893. obj = drm_gem_object_lookup(dev, file_priv, mode_cmd->handle);
  894. if (obj == NULL) {
  895. dev_err(&dev->pdev->dev, "No GEM object associated to handle 0x%08X, "
  896. "can't create framebuffer\n", mode_cmd->handle);
  897. return ERR_PTR(-ENOENT);
  898. }
  899. radeon_fb = kzalloc(sizeof(*radeon_fb), GFP_KERNEL);
  900. if (radeon_fb == NULL)
  901. return ERR_PTR(-ENOMEM);
  902. radeon_framebuffer_init(dev, radeon_fb, mode_cmd, obj);
  903. return &radeon_fb->base;
  904. }
  905. static void radeon_output_poll_changed(struct drm_device *dev)
  906. {
  907. struct radeon_device *rdev = dev->dev_private;
  908. radeon_fb_output_poll_changed(rdev);
  909. }
  910. static const struct drm_mode_config_funcs radeon_mode_funcs = {
  911. .fb_create = radeon_user_framebuffer_create,
  912. .output_poll_changed = radeon_output_poll_changed
  913. };
  914. struct drm_prop_enum_list {
  915. int type;
  916. char *name;
  917. };
  918. static struct drm_prop_enum_list radeon_tmds_pll_enum_list[] =
  919. { { 0, "driver" },
  920. { 1, "bios" },
  921. };
  922. static struct drm_prop_enum_list radeon_tv_std_enum_list[] =
  923. { { TV_STD_NTSC, "ntsc" },
  924. { TV_STD_PAL, "pal" },
  925. { TV_STD_PAL_M, "pal-m" },
  926. { TV_STD_PAL_60, "pal-60" },
  927. { TV_STD_NTSC_J, "ntsc-j" },
  928. { TV_STD_SCART_PAL, "scart-pal" },
  929. { TV_STD_PAL_CN, "pal-cn" },
  930. { TV_STD_SECAM, "secam" },
  931. };
  932. static struct drm_prop_enum_list radeon_underscan_enum_list[] =
  933. { { UNDERSCAN_OFF, "off" },
  934. { UNDERSCAN_ON, "on" },
  935. { UNDERSCAN_AUTO, "auto" },
  936. };
  937. static int radeon_modeset_create_props(struct radeon_device *rdev)
  938. {
  939. int i, sz;
  940. if (rdev->is_atom_bios) {
  941. rdev->mode_info.coherent_mode_property =
  942. drm_property_create(rdev->ddev,
  943. DRM_MODE_PROP_RANGE,
  944. "coherent", 2);
  945. if (!rdev->mode_info.coherent_mode_property)
  946. return -ENOMEM;
  947. rdev->mode_info.coherent_mode_property->values[0] = 0;
  948. rdev->mode_info.coherent_mode_property->values[1] = 1;
  949. }
  950. if (!ASIC_IS_AVIVO(rdev)) {
  951. sz = ARRAY_SIZE(radeon_tmds_pll_enum_list);
  952. rdev->mode_info.tmds_pll_property =
  953. drm_property_create(rdev->ddev,
  954. DRM_MODE_PROP_ENUM,
  955. "tmds_pll", sz);
  956. for (i = 0; i < sz; i++) {
  957. drm_property_add_enum(rdev->mode_info.tmds_pll_property,
  958. i,
  959. radeon_tmds_pll_enum_list[i].type,
  960. radeon_tmds_pll_enum_list[i].name);
  961. }
  962. }
  963. rdev->mode_info.load_detect_property =
  964. drm_property_create(rdev->ddev,
  965. DRM_MODE_PROP_RANGE,
  966. "load detection", 2);
  967. if (!rdev->mode_info.load_detect_property)
  968. return -ENOMEM;
  969. rdev->mode_info.load_detect_property->values[0] = 0;
  970. rdev->mode_info.load_detect_property->values[1] = 1;
  971. drm_mode_create_scaling_mode_property(rdev->ddev);
  972. sz = ARRAY_SIZE(radeon_tv_std_enum_list);
  973. rdev->mode_info.tv_std_property =
  974. drm_property_create(rdev->ddev,
  975. DRM_MODE_PROP_ENUM,
  976. "tv standard", sz);
  977. for (i = 0; i < sz; i++) {
  978. drm_property_add_enum(rdev->mode_info.tv_std_property,
  979. i,
  980. radeon_tv_std_enum_list[i].type,
  981. radeon_tv_std_enum_list[i].name);
  982. }
  983. sz = ARRAY_SIZE(radeon_underscan_enum_list);
  984. rdev->mode_info.underscan_property =
  985. drm_property_create(rdev->ddev,
  986. DRM_MODE_PROP_ENUM,
  987. "underscan", sz);
  988. for (i = 0; i < sz; i++) {
  989. drm_property_add_enum(rdev->mode_info.underscan_property,
  990. i,
  991. radeon_underscan_enum_list[i].type,
  992. radeon_underscan_enum_list[i].name);
  993. }
  994. rdev->mode_info.underscan_hborder_property =
  995. drm_property_create(rdev->ddev,
  996. DRM_MODE_PROP_RANGE,
  997. "underscan hborder", 2);
  998. if (!rdev->mode_info.underscan_hborder_property)
  999. return -ENOMEM;
  1000. rdev->mode_info.underscan_hborder_property->values[0] = 0;
  1001. rdev->mode_info.underscan_hborder_property->values[1] = 128;
  1002. rdev->mode_info.underscan_vborder_property =
  1003. drm_property_create(rdev->ddev,
  1004. DRM_MODE_PROP_RANGE,
  1005. "underscan vborder", 2);
  1006. if (!rdev->mode_info.underscan_vborder_property)
  1007. return -ENOMEM;
  1008. rdev->mode_info.underscan_vborder_property->values[0] = 0;
  1009. rdev->mode_info.underscan_vborder_property->values[1] = 128;
  1010. return 0;
  1011. }
  1012. void radeon_update_display_priority(struct radeon_device *rdev)
  1013. {
  1014. /* adjustment options for the display watermarks */
  1015. if ((radeon_disp_priority == 0) || (radeon_disp_priority > 2)) {
  1016. /* set display priority to high for r3xx, rv515 chips
  1017. * this avoids flickering due to underflow to the
  1018. * display controllers during heavy acceleration.
  1019. * Don't force high on rs4xx igp chips as it seems to
  1020. * affect the sound card. See kernel bug 15982.
  1021. */
  1022. if ((ASIC_IS_R300(rdev) || (rdev->family == CHIP_RV515)) &&
  1023. !(rdev->flags & RADEON_IS_IGP))
  1024. rdev->disp_priority = 2;
  1025. else
  1026. rdev->disp_priority = 0;
  1027. } else
  1028. rdev->disp_priority = radeon_disp_priority;
  1029. }
  1030. int radeon_modeset_init(struct radeon_device *rdev)
  1031. {
  1032. int i;
  1033. int ret;
  1034. drm_mode_config_init(rdev->ddev);
  1035. rdev->mode_info.mode_config_initialized = true;
  1036. rdev->ddev->mode_config.funcs = (void *)&radeon_mode_funcs;
  1037. if (ASIC_IS_DCE5(rdev)) {
  1038. rdev->ddev->mode_config.max_width = 16384;
  1039. rdev->ddev->mode_config.max_height = 16384;
  1040. } else if (ASIC_IS_AVIVO(rdev)) {
  1041. rdev->ddev->mode_config.max_width = 8192;
  1042. rdev->ddev->mode_config.max_height = 8192;
  1043. } else {
  1044. rdev->ddev->mode_config.max_width = 4096;
  1045. rdev->ddev->mode_config.max_height = 4096;
  1046. }
  1047. rdev->ddev->mode_config.fb_base = rdev->mc.aper_base;
  1048. ret = radeon_modeset_create_props(rdev);
  1049. if (ret) {
  1050. return ret;
  1051. }
  1052. /* init i2c buses */
  1053. radeon_i2c_init(rdev);
  1054. /* check combios for a valid hardcoded EDID - Sun servers */
  1055. if (!rdev->is_atom_bios) {
  1056. /* check for hardcoded EDID in BIOS */
  1057. radeon_combios_check_hardcoded_edid(rdev);
  1058. }
  1059. /* allocate crtcs */
  1060. for (i = 0; i < rdev->num_crtc; i++) {
  1061. radeon_crtc_init(rdev->ddev, i);
  1062. }
  1063. /* okay we should have all the bios connectors */
  1064. ret = radeon_setup_enc_conn(rdev->ddev);
  1065. if (!ret) {
  1066. return ret;
  1067. }
  1068. /* initialize hpd */
  1069. radeon_hpd_init(rdev);
  1070. /* Initialize power management */
  1071. radeon_pm_init(rdev);
  1072. radeon_fbdev_init(rdev);
  1073. drm_kms_helper_poll_init(rdev->ddev);
  1074. return 0;
  1075. }
  1076. void radeon_modeset_fini(struct radeon_device *rdev)
  1077. {
  1078. radeon_fbdev_fini(rdev);
  1079. kfree(rdev->mode_info.bios_hardcoded_edid);
  1080. radeon_pm_fini(rdev);
  1081. if (rdev->mode_info.mode_config_initialized) {
  1082. drm_kms_helper_poll_fini(rdev->ddev);
  1083. radeon_hpd_fini(rdev);
  1084. drm_mode_config_cleanup(rdev->ddev);
  1085. rdev->mode_info.mode_config_initialized = false;
  1086. }
  1087. /* free i2c buses */
  1088. radeon_i2c_fini(rdev);
  1089. }
  1090. static bool is_hdtv_mode(struct drm_display_mode *mode)
  1091. {
  1092. /* try and guess if this is a tv or a monitor */
  1093. if ((mode->vdisplay == 480 && mode->hdisplay == 720) || /* 480p */
  1094. (mode->vdisplay == 576) || /* 576p */
  1095. (mode->vdisplay == 720) || /* 720p */
  1096. (mode->vdisplay == 1080)) /* 1080p */
  1097. return true;
  1098. else
  1099. return false;
  1100. }
  1101. bool radeon_crtc_scaling_mode_fixup(struct drm_crtc *crtc,
  1102. struct drm_display_mode *mode,
  1103. struct drm_display_mode *adjusted_mode)
  1104. {
  1105. struct drm_device *dev = crtc->dev;
  1106. struct radeon_device *rdev = dev->dev_private;
  1107. struct drm_encoder *encoder;
  1108. struct radeon_crtc *radeon_crtc = to_radeon_crtc(crtc);
  1109. struct radeon_encoder *radeon_encoder;
  1110. struct drm_connector *connector;
  1111. struct radeon_connector *radeon_connector;
  1112. bool first = true;
  1113. u32 src_v = 1, dst_v = 1;
  1114. u32 src_h = 1, dst_h = 1;
  1115. radeon_crtc->h_border = 0;
  1116. radeon_crtc->v_border = 0;
  1117. list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
  1118. if (encoder->crtc != crtc)
  1119. continue;
  1120. radeon_encoder = to_radeon_encoder(encoder);
  1121. connector = radeon_get_connector_for_encoder(encoder);
  1122. radeon_connector = to_radeon_connector(connector);
  1123. if (first) {
  1124. /* set scaling */
  1125. if (radeon_encoder->rmx_type == RMX_OFF)
  1126. radeon_crtc->rmx_type = RMX_OFF;
  1127. else if (mode->hdisplay < radeon_encoder->native_mode.hdisplay ||
  1128. mode->vdisplay < radeon_encoder->native_mode.vdisplay)
  1129. radeon_crtc->rmx_type = radeon_encoder->rmx_type;
  1130. else
  1131. radeon_crtc->rmx_type = RMX_OFF;
  1132. /* copy native mode */
  1133. memcpy(&radeon_crtc->native_mode,
  1134. &radeon_encoder->native_mode,
  1135. sizeof(struct drm_display_mode));
  1136. src_v = crtc->mode.vdisplay;
  1137. dst_v = radeon_crtc->native_mode.vdisplay;
  1138. src_h = crtc->mode.hdisplay;
  1139. dst_h = radeon_crtc->native_mode.hdisplay;
  1140. /* fix up for overscan on hdmi */
  1141. if (ASIC_IS_AVIVO(rdev) &&
  1142. (!(mode->flags & DRM_MODE_FLAG_INTERLACE)) &&
  1143. ((radeon_encoder->underscan_type == UNDERSCAN_ON) ||
  1144. ((radeon_encoder->underscan_type == UNDERSCAN_AUTO) &&
  1145. drm_detect_hdmi_monitor(radeon_connector->edid) &&
  1146. is_hdtv_mode(mode)))) {
  1147. if (radeon_encoder->underscan_hborder != 0)
  1148. radeon_crtc->h_border = radeon_encoder->underscan_hborder;
  1149. else
  1150. radeon_crtc->h_border = (mode->hdisplay >> 5) + 16;
  1151. if (radeon_encoder->underscan_vborder != 0)
  1152. radeon_crtc->v_border = radeon_encoder->underscan_vborder;
  1153. else
  1154. radeon_crtc->v_border = (mode->vdisplay >> 5) + 16;
  1155. radeon_crtc->rmx_type = RMX_FULL;
  1156. src_v = crtc->mode.vdisplay;
  1157. dst_v = crtc->mode.vdisplay - (radeon_crtc->v_border * 2);
  1158. src_h = crtc->mode.hdisplay;
  1159. dst_h = crtc->mode.hdisplay - (radeon_crtc->h_border * 2);
  1160. }
  1161. first = false;
  1162. } else {
  1163. if (radeon_crtc->rmx_type != radeon_encoder->rmx_type) {
  1164. /* WARNING: Right now this can't happen but
  1165. * in the future we need to check that scaling
  1166. * are consistent across different encoder
  1167. * (ie all encoder can work with the same
  1168. * scaling).
  1169. */
  1170. DRM_ERROR("Scaling not consistent across encoder.\n");
  1171. return false;
  1172. }
  1173. }
  1174. }
  1175. if (radeon_crtc->rmx_type != RMX_OFF) {
  1176. fixed20_12 a, b;
  1177. a.full = dfixed_const(src_v);
  1178. b.full = dfixed_const(dst_v);
  1179. radeon_crtc->vsc.full = dfixed_div(a, b);
  1180. a.full = dfixed_const(src_h);
  1181. b.full = dfixed_const(dst_h);
  1182. radeon_crtc->hsc.full = dfixed_div(a, b);
  1183. } else {
  1184. radeon_crtc->vsc.full = dfixed_const(1);
  1185. radeon_crtc->hsc.full = dfixed_const(1);
  1186. }
  1187. return true;
  1188. }
  1189. /*
  1190. * Retrieve current video scanout position of crtc on a given gpu.
  1191. *
  1192. * \param dev Device to query.
  1193. * \param crtc Crtc to query.
  1194. * \param *vpos Location where vertical scanout position should be stored.
  1195. * \param *hpos Location where horizontal scanout position should go.
  1196. *
  1197. * Returns vpos as a positive number while in active scanout area.
  1198. * Returns vpos as a negative number inside vblank, counting the number
  1199. * of scanlines to go until end of vblank, e.g., -1 means "one scanline
  1200. * until start of active scanout / end of vblank."
  1201. *
  1202. * \return Flags, or'ed together as follows:
  1203. *
  1204. * DRM_SCANOUTPOS_VALID = Query successfull.
  1205. * DRM_SCANOUTPOS_INVBL = Inside vblank.
  1206. * DRM_SCANOUTPOS_ACCURATE = Returned position is accurate. A lack of
  1207. * this flag means that returned position may be offset by a constant but
  1208. * unknown small number of scanlines wrt. real scanout position.
  1209. *
  1210. */
  1211. int radeon_get_crtc_scanoutpos(struct drm_device *dev, int crtc, int *vpos, int *hpos)
  1212. {
  1213. u32 stat_crtc = 0, vbl = 0, position = 0;
  1214. int vbl_start, vbl_end, vtotal, ret = 0;
  1215. bool in_vbl = true;
  1216. struct radeon_device *rdev = dev->dev_private;
  1217. if (ASIC_IS_DCE4(rdev)) {
  1218. if (crtc == 0) {
  1219. vbl = RREG32(EVERGREEN_CRTC_V_BLANK_START_END +
  1220. EVERGREEN_CRTC0_REGISTER_OFFSET);
  1221. position = RREG32(EVERGREEN_CRTC_STATUS_POSITION +
  1222. EVERGREEN_CRTC0_REGISTER_OFFSET);
  1223. ret |= DRM_SCANOUTPOS_VALID;
  1224. }
  1225. if (crtc == 1) {
  1226. vbl = RREG32(EVERGREEN_CRTC_V_BLANK_START_END +
  1227. EVERGREEN_CRTC1_REGISTER_OFFSET);
  1228. position = RREG32(EVERGREEN_CRTC_STATUS_POSITION +
  1229. EVERGREEN_CRTC1_REGISTER_OFFSET);
  1230. ret |= DRM_SCANOUTPOS_VALID;
  1231. }
  1232. if (crtc == 2) {
  1233. vbl = RREG32(EVERGREEN_CRTC_V_BLANK_START_END +
  1234. EVERGREEN_CRTC2_REGISTER_OFFSET);
  1235. position = RREG32(EVERGREEN_CRTC_STATUS_POSITION +
  1236. EVERGREEN_CRTC2_REGISTER_OFFSET);
  1237. ret |= DRM_SCANOUTPOS_VALID;
  1238. }
  1239. if (crtc == 3) {
  1240. vbl = RREG32(EVERGREEN_CRTC_V_BLANK_START_END +
  1241. EVERGREEN_CRTC3_REGISTER_OFFSET);
  1242. position = RREG32(EVERGREEN_CRTC_STATUS_POSITION +
  1243. EVERGREEN_CRTC3_REGISTER_OFFSET);
  1244. ret |= DRM_SCANOUTPOS_VALID;
  1245. }
  1246. if (crtc == 4) {
  1247. vbl = RREG32(EVERGREEN_CRTC_V_BLANK_START_END +
  1248. EVERGREEN_CRTC4_REGISTER_OFFSET);
  1249. position = RREG32(EVERGREEN_CRTC_STATUS_POSITION +
  1250. EVERGREEN_CRTC4_REGISTER_OFFSET);
  1251. ret |= DRM_SCANOUTPOS_VALID;
  1252. }
  1253. if (crtc == 5) {
  1254. vbl = RREG32(EVERGREEN_CRTC_V_BLANK_START_END +
  1255. EVERGREEN_CRTC5_REGISTER_OFFSET);
  1256. position = RREG32(EVERGREEN_CRTC_STATUS_POSITION +
  1257. EVERGREEN_CRTC5_REGISTER_OFFSET);
  1258. ret |= DRM_SCANOUTPOS_VALID;
  1259. }
  1260. } else if (ASIC_IS_AVIVO(rdev)) {
  1261. if (crtc == 0) {
  1262. vbl = RREG32(AVIVO_D1CRTC_V_BLANK_START_END);
  1263. position = RREG32(AVIVO_D1CRTC_STATUS_POSITION);
  1264. ret |= DRM_SCANOUTPOS_VALID;
  1265. }
  1266. if (crtc == 1) {
  1267. vbl = RREG32(AVIVO_D2CRTC_V_BLANK_START_END);
  1268. position = RREG32(AVIVO_D2CRTC_STATUS_POSITION);
  1269. ret |= DRM_SCANOUTPOS_VALID;
  1270. }
  1271. } else {
  1272. /* Pre-AVIVO: Different encoding of scanout pos and vblank interval. */
  1273. if (crtc == 0) {
  1274. /* Assume vbl_end == 0, get vbl_start from
  1275. * upper 16 bits.
  1276. */
  1277. vbl = (RREG32(RADEON_CRTC_V_TOTAL_DISP) &
  1278. RADEON_CRTC_V_DISP) >> RADEON_CRTC_V_DISP_SHIFT;
  1279. /* Only retrieve vpos from upper 16 bits, set hpos == 0. */
  1280. position = (RREG32(RADEON_CRTC_VLINE_CRNT_VLINE) >> 16) & RADEON_CRTC_V_TOTAL;
  1281. stat_crtc = RREG32(RADEON_CRTC_STATUS);
  1282. if (!(stat_crtc & 1))
  1283. in_vbl = false;
  1284. ret |= DRM_SCANOUTPOS_VALID;
  1285. }
  1286. if (crtc == 1) {
  1287. vbl = (RREG32(RADEON_CRTC2_V_TOTAL_DISP) &
  1288. RADEON_CRTC_V_DISP) >> RADEON_CRTC_V_DISP_SHIFT;
  1289. position = (RREG32(RADEON_CRTC2_VLINE_CRNT_VLINE) >> 16) & RADEON_CRTC_V_TOTAL;
  1290. stat_crtc = RREG32(RADEON_CRTC2_STATUS);
  1291. if (!(stat_crtc & 1))
  1292. in_vbl = false;
  1293. ret |= DRM_SCANOUTPOS_VALID;
  1294. }
  1295. }
  1296. /* Decode into vertical and horizontal scanout position. */
  1297. *vpos = position & 0x1fff;
  1298. *hpos = (position >> 16) & 0x1fff;
  1299. /* Valid vblank area boundaries from gpu retrieved? */
  1300. if (vbl > 0) {
  1301. /* Yes: Decode. */
  1302. ret |= DRM_SCANOUTPOS_ACCURATE;
  1303. vbl_start = vbl & 0x1fff;
  1304. vbl_end = (vbl >> 16) & 0x1fff;
  1305. }
  1306. else {
  1307. /* No: Fake something reasonable which gives at least ok results. */
  1308. vbl_start = rdev->mode_info.crtcs[crtc]->base.hwmode.crtc_vdisplay;
  1309. vbl_end = 0;
  1310. }
  1311. /* Test scanout position against vblank region. */
  1312. if ((*vpos < vbl_start) && (*vpos >= vbl_end))
  1313. in_vbl = false;
  1314. /* Check if inside vblank area and apply corrective offsets:
  1315. * vpos will then be >=0 in video scanout area, but negative
  1316. * within vblank area, counting down the number of lines until
  1317. * start of scanout.
  1318. */
  1319. /* Inside "upper part" of vblank area? Apply corrective offset if so: */
  1320. if (in_vbl && (*vpos >= vbl_start)) {
  1321. vtotal = rdev->mode_info.crtcs[crtc]->base.hwmode.crtc_vtotal;
  1322. *vpos = *vpos - vtotal;
  1323. }
  1324. /* Correct for shifted end of vbl at vbl_end. */
  1325. *vpos = *vpos - vbl_end;
  1326. /* In vblank? */
  1327. if (in_vbl)
  1328. ret |= DRM_SCANOUTPOS_INVBL;
  1329. return ret;
  1330. }