blob: 7b4fe91d3aecd82ea6ecb6b747bfc51118ca232b [file] [log] [blame]
Alex Deucherd38ceaf2015-04-20 16:55:21 -04001/*
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 <drm/drmP.h>
27#include <drm/amdgpu_drm.h>
28#include "amdgpu.h"
29#include "amdgpu_i2c.h"
30#include "atom.h"
31#include "amdgpu_connectors.h"
32#include <asm/div64.h>
33
34#include <linux/pm_runtime.h>
35#include <drm/drm_crtc_helper.h>
36#include <drm/drm_edid.h>
37
Chris Wilsonf54d1862016-10-25 13:00:45 +010038static void amdgpu_flip_callback(struct dma_fence *f, struct dma_fence_cb *cb)
Christian König1ffd2652015-08-11 17:29:52 +020039{
Christian Königc3874b72016-02-11 15:48:30 +010040 struct amdgpu_flip_work *work =
41 container_of(cb, struct amdgpu_flip_work, cb);
Christian König1ffd2652015-08-11 17:29:52 +020042
Chris Wilsonf54d1862016-10-25 13:00:45 +010043 dma_fence_put(f);
Michel Dänzer325cbba2016-08-04 12:39:37 +090044 schedule_work(&work->flip_work.work);
Christian Königc3874b72016-02-11 15:48:30 +010045}
Christian König1ffd2652015-08-11 17:29:52 +020046
Christian Königc3874b72016-02-11 15:48:30 +010047static bool amdgpu_flip_handle_fence(struct amdgpu_flip_work *work,
Chris Wilsonf54d1862016-10-25 13:00:45 +010048 struct dma_fence **f)
Christian Königc3874b72016-02-11 15:48:30 +010049{
Chris Wilsonf54d1862016-10-25 13:00:45 +010050 struct dma_fence *fence= *f;
Christian König1ffd2652015-08-11 17:29:52 +020051
Christian Königc3874b72016-02-11 15:48:30 +010052 if (fence == NULL)
53 return false;
54
Christian König1ffd2652015-08-11 17:29:52 +020055 *f = NULL;
Christian Königc3874b72016-02-11 15:48:30 +010056
Chris Wilsonf54d1862016-10-25 13:00:45 +010057 if (!dma_fence_add_callback(fence, &work->cb, amdgpu_flip_callback))
Christian Königc3874b72016-02-11 15:48:30 +010058 return true;
59
Chris Wilsonf54d1862016-10-25 13:00:45 +010060 dma_fence_put(fence);
Christian Königc3874b72016-02-11 15:48:30 +010061 return false;
Christian König1ffd2652015-08-11 17:29:52 +020062}
Alex Deucherd38ceaf2015-04-20 16:55:21 -040063
64static void amdgpu_flip_work_func(struct work_struct *__work)
65{
Michel Dänzer325cbba2016-08-04 12:39:37 +090066 struct delayed_work *delayed_work =
67 container_of(__work, struct delayed_work, work);
Alex Deucherd38ceaf2015-04-20 16:55:21 -040068 struct amdgpu_flip_work *work =
Michel Dänzer325cbba2016-08-04 12:39:37 +090069 container_of(delayed_work, struct amdgpu_flip_work, flip_work);
Alex Deucherd38ceaf2015-04-20 16:55:21 -040070 struct amdgpu_device *adev = work->adev;
Alex Deucherf93932b2016-10-21 16:36:12 -040071 struct amdgpu_crtc *amdgpu_crtc = adev->mode_info.crtcs[work->crtc_id];
Alex Deucherd38ceaf2015-04-20 16:55:21 -040072
Alex Deucherf93932b2016-10-21 16:36:12 -040073 struct drm_crtc *crtc = &amdgpu_crtc->base;
Alex Deucherd38ceaf2015-04-20 16:55:21 -040074 unsigned long flags;
Michel Dänzer325cbba2016-08-04 12:39:37 +090075 unsigned i;
76 int vpos, hpos;
Alex Deucherd38ceaf2015-04-20 16:55:21 -040077
Christian Königc3874b72016-02-11 15:48:30 +010078 if (amdgpu_flip_handle_fence(work, &work->excl))
79 return;
80
Christian König1ffd2652015-08-11 17:29:52 +020081 for (i = 0; i < work->shared_count; ++i)
Christian Königc3874b72016-02-11 15:48:30 +010082 if (amdgpu_flip_handle_fence(work, &work->shared[i]))
83 return;
Alex Deucherd38ceaf2015-04-20 16:55:21 -040084
Michel Dänzer325cbba2016-08-04 12:39:37 +090085 /* Wait until we're out of the vertical blank period before the one
86 * targeted by the flip
Alex Deucher8e36f9d2015-12-03 12:31:56 -050087 */
Alex Deucherf93932b2016-10-21 16:36:12 -040088 if (amdgpu_crtc->enabled &&
Michel Dänzer325cbba2016-08-04 12:39:37 +090089 (amdgpu_get_crtc_scanoutpos(adev->ddev, work->crtc_id, 0,
90 &vpos, &hpos, NULL, NULL,
91 &crtc->hwmode)
92 & (DRM_SCANOUTPOS_VALID | DRM_SCANOUTPOS_IN_VBLANK)) ==
93 (DRM_SCANOUTPOS_VALID | DRM_SCANOUTPOS_IN_VBLANK) &&
94 (int)(work->target_vblank -
Alex Deucherf93932b2016-10-21 16:36:12 -040095 amdgpu_get_vblank_counter_kms(adev->ddev, amdgpu_crtc->crtc_id)) > 0) {
Michel Dänzer325cbba2016-08-04 12:39:37 +090096 schedule_delayed_work(&work->flip_work, usecs_to_jiffies(1000));
97 return;
Edward O'Callaghan9c3578a2016-07-12 10:17:51 +100098 }
Alex Deucher8e36f9d2015-12-03 12:31:56 -050099
Michel Dänzer325cbba2016-08-04 12:39:37 +0900100 /* We borrow the event spin lock for protecting flip_status */
101 spin_lock_irqsave(&crtc->dev->event_lock, flags);
Mario Kleinere1d09dc2016-02-19 02:06:39 +0100102
Andrey Grodzovskybd4c72d2016-03-30 17:34:27 -0400103 /* Do the flip (mmio) */
Alex Deuchercb9e59d2016-05-05 16:03:57 -0400104 adev->mode_info.funcs->page_flip(adev, work->crtc_id, work->base, work->async);
Andrey Grodzovskybd4c72d2016-03-30 17:34:27 -0400105
106 /* Set the flip status */
Alex Deucherf93932b2016-10-21 16:36:12 -0400107 amdgpu_crtc->pflip_status = AMDGPU_FLIP_SUBMITTED;
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400108 spin_unlock_irqrestore(&crtc->dev->event_lock, flags);
Vitaly Prosyak6bd9e872015-10-20 15:02:03 -0400109
Andrey Grodzovskybd4c72d2016-03-30 17:34:27 -0400110
111 DRM_DEBUG_DRIVER("crtc:%d[%p], pflip_stat:AMDGPU_FLIP_SUBMITTED, work: %p,\n",
Alex Deucherf93932b2016-10-21 16:36:12 -0400112 amdgpu_crtc->crtc_id, amdgpu_crtc, work);
Andrey Grodzovskybd4c72d2016-03-30 17:34:27 -0400113
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400114}
115
116/*
117 * Handle unpin events outside the interrupt handler proper.
118 */
119static void amdgpu_unpin_work_func(struct work_struct *__work)
120{
121 struct amdgpu_flip_work *work =
122 container_of(__work, struct amdgpu_flip_work, unpin_work);
123 int r;
124
125 /* unpin of the old buffer */
Christian König765e7fb2016-09-15 15:06:50 +0200126 r = amdgpu_bo_reserve(work->old_abo, false);
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400127 if (likely(r == 0)) {
Christian König765e7fb2016-09-15 15:06:50 +0200128 r = amdgpu_bo_unpin(work->old_abo);
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400129 if (unlikely(r != 0)) {
130 DRM_ERROR("failed to unpin buffer after flip\n");
131 }
Christian König765e7fb2016-09-15 15:06:50 +0200132 amdgpu_bo_unreserve(work->old_abo);
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400133 } else
134 DRM_ERROR("failed to reserve buffer after flip\n");
135
Christian König765e7fb2016-09-15 15:06:50 +0200136 amdgpu_bo_unref(&work->old_abo);
Christian König1ffd2652015-08-11 17:29:52 +0200137 kfree(work->shared);
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400138 kfree(work);
139}
140
Andrey Grodzovskycb341a32016-12-05 15:15:33 -0500141
142static void amdgpu_flip_work_cleanup(struct amdgpu_flip_work *work)
143{
144 int i;
145
146 amdgpu_bo_unref(&work->old_abo);
147 dma_fence_put(work->excl);
148 for (i = 0; i < work->shared_count; ++i)
149 dma_fence_put(work->shared[i]);
150 kfree(work->shared);
151 kfree(work);
152}
153
154static void amdgpu_flip_cleanup_unreserve(struct amdgpu_flip_work *work,
155 struct amdgpu_bo *new_abo)
156{
157 amdgpu_bo_unreserve(new_abo);
158 amdgpu_flip_work_cleanup(work);
159}
160
161static void amdgpu_flip_cleanup_unpin(struct amdgpu_flip_work *work,
162 struct amdgpu_bo *new_abo)
163{
164 if (unlikely(amdgpu_bo_unpin(new_abo) != 0))
165 DRM_ERROR("failed to unpin new abo in error path\n");
166 amdgpu_flip_cleanup_unreserve(work, new_abo);
167}
168
169void amdgpu_crtc_cleanup_flip_ctx(struct amdgpu_flip_work *work,
170 struct amdgpu_bo *new_abo)
171{
172 if (unlikely(amdgpu_bo_reserve(new_abo, false) != 0)) {
173 DRM_ERROR("failed to reserve new abo in error path\n");
174 amdgpu_flip_work_cleanup(work);
175 return;
176 }
177 amdgpu_flip_cleanup_unpin(work, new_abo);
178}
179
180int amdgpu_crtc_prepare_flip(struct drm_crtc *crtc,
181 struct drm_framebuffer *fb,
182 struct drm_pending_vblank_event *event,
183 uint32_t page_flip_flags,
184 uint32_t target,
185 struct amdgpu_flip_work **work_p,
186 struct amdgpu_bo **new_abo_p)
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400187{
188 struct drm_device *dev = crtc->dev;
189 struct amdgpu_device *adev = dev->dev_private;
190 struct amdgpu_crtc *amdgpu_crtc = to_amdgpu_crtc(crtc);
191 struct amdgpu_framebuffer *old_amdgpu_fb;
192 struct amdgpu_framebuffer *new_amdgpu_fb;
193 struct drm_gem_object *obj;
194 struct amdgpu_flip_work *work;
Christian König765e7fb2016-09-15 15:06:50 +0200195 struct amdgpu_bo *new_abo;
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400196 unsigned long flags;
197 u64 tiling_flags;
198 u64 base;
Andrey Grodzovskycb341a32016-12-05 15:15:33 -0500199 int r;
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400200
201 work = kzalloc(sizeof *work, GFP_KERNEL);
202 if (work == NULL)
203 return -ENOMEM;
204
Michel Dänzer325cbba2016-08-04 12:39:37 +0900205 INIT_DELAYED_WORK(&work->flip_work, amdgpu_flip_work_func);
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400206 INIT_WORK(&work->unpin_work, amdgpu_unpin_work_func);
207
208 work->event = event;
209 work->adev = adev;
210 work->crtc_id = amdgpu_crtc->crtc_id;
Alex Deuchercb9e59d2016-05-05 16:03:57 -0400211 work->async = (page_flip_flags & DRM_MODE_PAGE_FLIP_ASYNC) != 0;
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400212
213 /* schedule unpin of the old buffer */
214 old_amdgpu_fb = to_amdgpu_framebuffer(crtc->primary->fb);
215 obj = old_amdgpu_fb->obj;
216
217 /* take a reference to the old object */
Christian König765e7fb2016-09-15 15:06:50 +0200218 work->old_abo = gem_to_amdgpu_bo(obj);
219 amdgpu_bo_ref(work->old_abo);
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400220
221 new_amdgpu_fb = to_amdgpu_framebuffer(fb);
222 obj = new_amdgpu_fb->obj;
Christian König765e7fb2016-09-15 15:06:50 +0200223 new_abo = gem_to_amdgpu_bo(obj);
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400224
225 /* pin the new buffer */
Christian König765e7fb2016-09-15 15:06:50 +0200226 r = amdgpu_bo_reserve(new_abo, false);
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400227 if (unlikely(r != 0)) {
Christian König765e7fb2016-09-15 15:06:50 +0200228 DRM_ERROR("failed to reserve new abo buffer before flip\n");
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400229 goto cleanup;
230 }
231
Alex Deucher7fe28572016-12-07 16:14:38 -0500232 r = amdgpu_bo_pin(new_abo, AMDGPU_GEM_DOMAIN_VRAM, &base);
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400233 if (unlikely(r != 0)) {
Christian König765e7fb2016-09-15 15:06:50 +0200234 DRM_ERROR("failed to pin new abo buffer before flip\n");
Michel Dänzeree7fd952016-06-24 17:30:08 +0900235 goto unreserve;
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400236 }
237
Christian König765e7fb2016-09-15 15:06:50 +0200238 r = reservation_object_get_fences_rcu(new_abo->tbo.resv, &work->excl,
Christian König1ffd2652015-08-11 17:29:52 +0200239 &work->shared_count,
240 &work->shared);
241 if (unlikely(r != 0)) {
Christian König1ffd2652015-08-11 17:29:52 +0200242 DRM_ERROR("failed to get fences for buffer\n");
Michel Dänzeree7fd952016-06-24 17:30:08 +0900243 goto unpin;
Christian König1ffd2652015-08-11 17:29:52 +0200244 }
245
Christian König765e7fb2016-09-15 15:06:50 +0200246 amdgpu_bo_get_tiling_flags(new_abo, &tiling_flags);
247 amdgpu_bo_unreserve(new_abo);
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400248
249 work->base = base;
Michel Dänzer325cbba2016-08-04 12:39:37 +0900250 work->target_vblank = target - drm_crtc_vblank_count(crtc) +
251 amdgpu_get_vblank_counter_kms(dev, work->crtc_id);
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400252
253 /* we borrow the event spin lock for protecting flip_wrok */
254 spin_lock_irqsave(&crtc->dev->event_lock, flags);
255 if (amdgpu_crtc->pflip_status != AMDGPU_FLIP_NONE) {
256 DRM_DEBUG_DRIVER("flip queue: crtc already busy\n");
257 spin_unlock_irqrestore(&crtc->dev->event_lock, flags);
258 r = -EBUSY;
Michel Dänzer325cbba2016-08-04 12:39:37 +0900259 goto pflip_cleanup;
Andrey Grodzovskycb341a32016-12-05 15:15:33 -0500260
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400261 }
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400262 spin_unlock_irqrestore(&crtc->dev->event_lock, flags);
Andrey Grodzovskycb341a32016-12-05 15:15:33 -0500263
264 *work_p = work;
265 *new_abo_p = new_abo;
266
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400267 return 0;
268
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400269pflip_cleanup:
Andrey Grodzovskycb341a32016-12-05 15:15:33 -0500270 amdgpu_crtc_cleanup_flip_ctx(work, new_abo);
271 return r;
272
Michel Dänzeree7fd952016-06-24 17:30:08 +0900273unpin:
Andrey Grodzovskycb341a32016-12-05 15:15:33 -0500274 amdgpu_flip_cleanup_unpin(work, new_abo);
275 return r;
276
Michel Dänzeree7fd952016-06-24 17:30:08 +0900277unreserve:
Andrey Grodzovskycb341a32016-12-05 15:15:33 -0500278 amdgpu_flip_cleanup_unreserve(work, new_abo);
279 return r;
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400280
281cleanup:
Andrey Grodzovskycb341a32016-12-05 15:15:33 -0500282 amdgpu_flip_work_cleanup(work);
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400283 return r;
Andrey Grodzovskycb341a32016-12-05 15:15:33 -0500284
285}
286
287void amdgpu_crtc_submit_flip(struct drm_crtc *crtc,
288 struct drm_framebuffer *fb,
289 struct amdgpu_flip_work *work,
290 struct amdgpu_bo *new_abo)
291{
292 unsigned long flags;
293 struct amdgpu_crtc *amdgpu_crtc = to_amdgpu_crtc(crtc);
294
295 spin_lock_irqsave(&crtc->dev->event_lock, flags);
296 amdgpu_crtc->pflip_status = AMDGPU_FLIP_PENDING;
297 amdgpu_crtc->pflip_works = work;
298
299 /* update crtc fb */
300 crtc->primary->fb = fb;
301 spin_unlock_irqrestore(&crtc->dev->event_lock, flags);
302
303 DRM_DEBUG_DRIVER(
304 "crtc:%d[%p], pflip_stat:AMDGPU_FLIP_PENDING, work: %p,\n",
305 amdgpu_crtc->crtc_id, amdgpu_crtc, work);
306
307 amdgpu_flip_work_func(&work->flip_work.work);
308}
309
310int amdgpu_crtc_page_flip_target(struct drm_crtc *crtc,
311 struct drm_framebuffer *fb,
312 struct drm_pending_vblank_event *event,
313 uint32_t page_flip_flags,
Daniel Vetter41292b1f2017-03-22 22:50:50 +0100314 uint32_t target,
315 struct drm_modeset_acquire_ctx *ctx)
Andrey Grodzovskycb341a32016-12-05 15:15:33 -0500316{
317 struct amdgpu_bo *new_abo;
318 struct amdgpu_flip_work *work;
319 int r;
320
321 r = amdgpu_crtc_prepare_flip(crtc,
322 fb,
323 event,
324 page_flip_flags,
325 target,
326 &work,
327 &new_abo);
328 if (r)
329 return r;
330
331 amdgpu_crtc_submit_flip(crtc, fb, work, new_abo);
332
333 return 0;
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400334}
335
336int amdgpu_crtc_set_config(struct drm_mode_set *set)
337{
338 struct drm_device *dev;
339 struct amdgpu_device *adev;
340 struct drm_crtc *crtc;
341 bool active = false;
342 int ret;
343
344 if (!set || !set->crtc)
345 return -EINVAL;
346
347 dev = set->crtc->dev;
348
349 ret = pm_runtime_get_sync(dev->dev);
350 if (ret < 0)
351 return ret;
352
353 ret = drm_crtc_helper_set_config(set);
354
355 list_for_each_entry(crtc, &dev->mode_config.crtc_list, head)
356 if (crtc->enabled)
357 active = true;
358
359 pm_runtime_mark_last_busy(dev->dev);
360
361 adev = dev->dev_private;
362 /* if we have active crtcs and we don't have a power ref,
363 take the current one */
364 if (active && !adev->have_disp_power_ref) {
365 adev->have_disp_power_ref = true;
366 return ret;
367 }
368 /* if we have no active crtcs, then drop the power ref
369 we got before */
370 if (!active && adev->have_disp_power_ref) {
371 pm_runtime_put_autosuspend(dev->dev);
372 adev->have_disp_power_ref = false;
373 }
374
375 /* drop the power reference we got coming in here */
376 pm_runtime_put_autosuspend(dev->dev);
377 return ret;
378}
379
Emily Dengc6e14f42016-08-08 11:30:50 +0800380static const char *encoder_names[41] = {
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400381 "NONE",
382 "INTERNAL_LVDS",
383 "INTERNAL_TMDS1",
384 "INTERNAL_TMDS2",
385 "INTERNAL_DAC1",
386 "INTERNAL_DAC2",
387 "INTERNAL_SDVOA",
388 "INTERNAL_SDVOB",
389 "SI170B",
390 "CH7303",
391 "CH7301",
392 "INTERNAL_DVO1",
393 "EXTERNAL_SDVOA",
394 "EXTERNAL_SDVOB",
395 "TITFP513",
396 "INTERNAL_LVTM1",
397 "VT1623",
398 "HDMI_SI1930",
399 "HDMI_INTERNAL",
400 "INTERNAL_KLDSCP_TMDS1",
401 "INTERNAL_KLDSCP_DVO1",
402 "INTERNAL_KLDSCP_DAC1",
403 "INTERNAL_KLDSCP_DAC2",
404 "SI178",
405 "MVPU_FPGA",
406 "INTERNAL_DDI",
407 "VT1625",
408 "HDMI_SI1932",
409 "DP_AN9801",
410 "DP_DP501",
411 "INTERNAL_UNIPHY",
412 "INTERNAL_KLDSCP_LVTMA",
413 "INTERNAL_UNIPHY1",
414 "INTERNAL_UNIPHY2",
415 "NUTMEG",
416 "TRAVIS",
417 "INTERNAL_VCE",
418 "INTERNAL_UNIPHY3",
Emily Dengc6e14f42016-08-08 11:30:50 +0800419 "HDMI_ANX9805",
420 "INTERNAL_AMCLK",
421 "VIRTUAL",
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400422};
423
424static const char *hpd_names[6] = {
425 "HPD1",
426 "HPD2",
427 "HPD3",
428 "HPD4",
429 "HPD5",
430 "HPD6",
431};
432
433void amdgpu_print_display_setup(struct drm_device *dev)
434{
435 struct drm_connector *connector;
436 struct amdgpu_connector *amdgpu_connector;
437 struct drm_encoder *encoder;
438 struct amdgpu_encoder *amdgpu_encoder;
439 uint32_t devices;
440 int i = 0;
441
442 DRM_INFO("AMDGPU Display Connectors\n");
443 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
444 amdgpu_connector = to_amdgpu_connector(connector);
445 DRM_INFO("Connector %d:\n", i);
446 DRM_INFO(" %s\n", connector->name);
447 if (amdgpu_connector->hpd.hpd != AMDGPU_HPD_NONE)
448 DRM_INFO(" %s\n", hpd_names[amdgpu_connector->hpd.hpd]);
449 if (amdgpu_connector->ddc_bus) {
450 DRM_INFO(" DDC: 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x\n",
451 amdgpu_connector->ddc_bus->rec.mask_clk_reg,
452 amdgpu_connector->ddc_bus->rec.mask_data_reg,
453 amdgpu_connector->ddc_bus->rec.a_clk_reg,
454 amdgpu_connector->ddc_bus->rec.a_data_reg,
455 amdgpu_connector->ddc_bus->rec.en_clk_reg,
456 amdgpu_connector->ddc_bus->rec.en_data_reg,
457 amdgpu_connector->ddc_bus->rec.y_clk_reg,
458 amdgpu_connector->ddc_bus->rec.y_data_reg);
459 if (amdgpu_connector->router.ddc_valid)
460 DRM_INFO(" DDC Router 0x%x/0x%x\n",
461 amdgpu_connector->router.ddc_mux_control_pin,
462 amdgpu_connector->router.ddc_mux_state);
463 if (amdgpu_connector->router.cd_valid)
464 DRM_INFO(" Clock/Data Router 0x%x/0x%x\n",
465 amdgpu_connector->router.cd_mux_control_pin,
466 amdgpu_connector->router.cd_mux_state);
467 } else {
468 if (connector->connector_type == DRM_MODE_CONNECTOR_VGA ||
469 connector->connector_type == DRM_MODE_CONNECTOR_DVII ||
470 connector->connector_type == DRM_MODE_CONNECTOR_DVID ||
471 connector->connector_type == DRM_MODE_CONNECTOR_DVIA ||
472 connector->connector_type == DRM_MODE_CONNECTOR_HDMIA ||
473 connector->connector_type == DRM_MODE_CONNECTOR_HDMIB)
474 DRM_INFO(" DDC: no ddc bus - possible BIOS bug - please report to xorg-driver-ati@lists.x.org\n");
475 }
476 DRM_INFO(" Encoders:\n");
477 list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
478 amdgpu_encoder = to_amdgpu_encoder(encoder);
479 devices = amdgpu_encoder->devices & amdgpu_connector->devices;
480 if (devices) {
481 if (devices & ATOM_DEVICE_CRT1_SUPPORT)
482 DRM_INFO(" CRT1: %s\n", encoder_names[amdgpu_encoder->encoder_id]);
483 if (devices & ATOM_DEVICE_CRT2_SUPPORT)
484 DRM_INFO(" CRT2: %s\n", encoder_names[amdgpu_encoder->encoder_id]);
485 if (devices & ATOM_DEVICE_LCD1_SUPPORT)
486 DRM_INFO(" LCD1: %s\n", encoder_names[amdgpu_encoder->encoder_id]);
487 if (devices & ATOM_DEVICE_DFP1_SUPPORT)
488 DRM_INFO(" DFP1: %s\n", encoder_names[amdgpu_encoder->encoder_id]);
489 if (devices & ATOM_DEVICE_DFP2_SUPPORT)
490 DRM_INFO(" DFP2: %s\n", encoder_names[amdgpu_encoder->encoder_id]);
491 if (devices & ATOM_DEVICE_DFP3_SUPPORT)
492 DRM_INFO(" DFP3: %s\n", encoder_names[amdgpu_encoder->encoder_id]);
493 if (devices & ATOM_DEVICE_DFP4_SUPPORT)
494 DRM_INFO(" DFP4: %s\n", encoder_names[amdgpu_encoder->encoder_id]);
495 if (devices & ATOM_DEVICE_DFP5_SUPPORT)
496 DRM_INFO(" DFP5: %s\n", encoder_names[amdgpu_encoder->encoder_id]);
497 if (devices & ATOM_DEVICE_DFP6_SUPPORT)
498 DRM_INFO(" DFP6: %s\n", encoder_names[amdgpu_encoder->encoder_id]);
499 if (devices & ATOM_DEVICE_TV1_SUPPORT)
500 DRM_INFO(" TV1: %s\n", encoder_names[amdgpu_encoder->encoder_id]);
501 if (devices & ATOM_DEVICE_CV_SUPPORT)
502 DRM_INFO(" CV: %s\n", encoder_names[amdgpu_encoder->encoder_id]);
503 }
504 }
505 i++;
506 }
507}
508
509/**
510 * amdgpu_ddc_probe
511 *
512 */
513bool amdgpu_ddc_probe(struct amdgpu_connector *amdgpu_connector,
514 bool use_aux)
515{
516 u8 out = 0x0;
517 u8 buf[8];
518 int ret;
519 struct i2c_msg msgs[] = {
520 {
521 .addr = DDC_ADDR,
522 .flags = 0,
523 .len = 1,
524 .buf = &out,
525 },
526 {
527 .addr = DDC_ADDR,
528 .flags = I2C_M_RD,
529 .len = 8,
530 .buf = buf,
531 }
532 };
533
534 /* on hw with routers, select right port */
535 if (amdgpu_connector->router.ddc_valid)
536 amdgpu_i2c_router_select_ddc_port(amdgpu_connector);
537
538 if (use_aux) {
539 ret = i2c_transfer(&amdgpu_connector->ddc_bus->aux.ddc, msgs, 2);
540 } else {
541 ret = i2c_transfer(&amdgpu_connector->ddc_bus->adapter, msgs, 2);
542 }
543
544 if (ret != 2)
545 /* Couldn't find an accessible DDC on this connector */
546 return false;
547 /* Probe also for valid EDID header
548 * EDID header starts with:
549 * 0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x00.
550 * Only the first 6 bytes must be valid as
551 * drm_edid_block_valid() can fix the last 2 bytes */
552 if (drm_edid_header_is_valid(buf) < 6) {
553 /* Couldn't find an accessible EDID on this
554 * connector */
555 return false;
556 }
557 return true;
558}
559
560static void amdgpu_user_framebuffer_destroy(struct drm_framebuffer *fb)
561{
562 struct amdgpu_framebuffer *amdgpu_fb = to_amdgpu_framebuffer(fb);
563
Markus Elfring1721c692016-07-16 11:28:36 +0200564 drm_gem_object_unreference_unlocked(amdgpu_fb->obj);
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400565 drm_framebuffer_cleanup(fb);
566 kfree(amdgpu_fb);
567}
568
569static int amdgpu_user_framebuffer_create_handle(struct drm_framebuffer *fb,
570 struct drm_file *file_priv,
571 unsigned int *handle)
572{
573 struct amdgpu_framebuffer *amdgpu_fb = to_amdgpu_framebuffer(fb);
574
575 return drm_gem_handle_create(file_priv, amdgpu_fb->obj, handle);
576}
577
578static const struct drm_framebuffer_funcs amdgpu_fb_funcs = {
579 .destroy = amdgpu_user_framebuffer_destroy,
580 .create_handle = amdgpu_user_framebuffer_create_handle,
581};
582
583int
584amdgpu_framebuffer_init(struct drm_device *dev,
585 struct amdgpu_framebuffer *rfb,
Ville Syrjälä1eb83452015-11-11 19:11:29 +0200586 const struct drm_mode_fb_cmd2 *mode_cmd,
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400587 struct drm_gem_object *obj)
588{
589 int ret;
590 rfb->obj = obj;
Ville Syrjäläa3f913c2016-12-14 22:48:59 +0200591 drm_helper_mode_fill_fb_struct(dev, &rfb->base, mode_cmd);
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400592 ret = drm_framebuffer_init(dev, &rfb->base, &amdgpu_fb_funcs);
593 if (ret) {
594 rfb->obj = NULL;
595 return ret;
596 }
597 return 0;
598}
599
600static struct drm_framebuffer *
601amdgpu_user_framebuffer_create(struct drm_device *dev,
602 struct drm_file *file_priv,
Ville Syrjälä1eb83452015-11-11 19:11:29 +0200603 const struct drm_mode_fb_cmd2 *mode_cmd)
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400604{
605 struct drm_gem_object *obj;
606 struct amdgpu_framebuffer *amdgpu_fb;
607 int ret;
608
Chris Wilsona8ad0bd2016-05-09 11:04:54 +0100609 obj = drm_gem_object_lookup(file_priv, mode_cmd->handles[0]);
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400610 if (obj == NULL) {
611 dev_err(&dev->pdev->dev, "No GEM object associated to handle 0x%08X, "
612 "can't create framebuffer\n", mode_cmd->handles[0]);
613 return ERR_PTR(-ENOENT);
614 }
615
616 amdgpu_fb = kzalloc(sizeof(*amdgpu_fb), GFP_KERNEL);
617 if (amdgpu_fb == NULL) {
618 drm_gem_object_unreference_unlocked(obj);
619 return ERR_PTR(-ENOMEM);
620 }
621
622 ret = amdgpu_framebuffer_init(dev, amdgpu_fb, mode_cmd, obj);
623 if (ret) {
624 kfree(amdgpu_fb);
625 drm_gem_object_unreference_unlocked(obj);
626 return ERR_PTR(ret);
627 }
628
629 return &amdgpu_fb->base;
630}
631
632static void amdgpu_output_poll_changed(struct drm_device *dev)
633{
634 struct amdgpu_device *adev = dev->dev_private;
635 amdgpu_fb_output_poll_changed(adev);
636}
637
638const struct drm_mode_config_funcs amdgpu_mode_funcs = {
639 .fb_create = amdgpu_user_framebuffer_create,
640 .output_poll_changed = amdgpu_output_poll_changed
641};
642
Nils Wallméniusf498d9e2016-04-10 16:29:59 +0200643static const struct drm_prop_enum_list amdgpu_underscan_enum_list[] =
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400644{ { UNDERSCAN_OFF, "off" },
645 { UNDERSCAN_ON, "on" },
646 { UNDERSCAN_AUTO, "auto" },
647};
648
Nils Wallméniusf498d9e2016-04-10 16:29:59 +0200649static const struct drm_prop_enum_list amdgpu_audio_enum_list[] =
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400650{ { AMDGPU_AUDIO_DISABLE, "off" },
651 { AMDGPU_AUDIO_ENABLE, "on" },
652 { AMDGPU_AUDIO_AUTO, "auto" },
653};
654
655/* XXX support different dither options? spatial, temporal, both, etc. */
Nils Wallméniusf498d9e2016-04-10 16:29:59 +0200656static const struct drm_prop_enum_list amdgpu_dither_enum_list[] =
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400657{ { AMDGPU_FMT_DITHER_DISABLE, "off" },
658 { AMDGPU_FMT_DITHER_ENABLE, "on" },
659};
660
661int amdgpu_modeset_create_props(struct amdgpu_device *adev)
662{
663 int sz;
664
Nils Wallméniusf7e9e9f2016-12-14 21:52:45 +0100665 adev->mode_info.coherent_mode_property =
666 drm_property_create_range(adev->ddev, 0 , "coherent", 0, 1);
667 if (!adev->mode_info.coherent_mode_property)
668 return -ENOMEM;
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400669
670 adev->mode_info.load_detect_property =
671 drm_property_create_range(adev->ddev, 0, "load detection", 0, 1);
672 if (!adev->mode_info.load_detect_property)
673 return -ENOMEM;
674
675 drm_mode_create_scaling_mode_property(adev->ddev);
676
677 sz = ARRAY_SIZE(amdgpu_underscan_enum_list);
678 adev->mode_info.underscan_property =
679 drm_property_create_enum(adev->ddev, 0,
680 "underscan",
681 amdgpu_underscan_enum_list, sz);
682
683 adev->mode_info.underscan_hborder_property =
684 drm_property_create_range(adev->ddev, 0,
685 "underscan hborder", 0, 128);
686 if (!adev->mode_info.underscan_hborder_property)
687 return -ENOMEM;
688
689 adev->mode_info.underscan_vborder_property =
690 drm_property_create_range(adev->ddev, 0,
691 "underscan vborder", 0, 128);
692 if (!adev->mode_info.underscan_vborder_property)
693 return -ENOMEM;
694
695 sz = ARRAY_SIZE(amdgpu_audio_enum_list);
696 adev->mode_info.audio_property =
697 drm_property_create_enum(adev->ddev, 0,
698 "audio",
699 amdgpu_audio_enum_list, sz);
700
701 sz = ARRAY_SIZE(amdgpu_dither_enum_list);
702 adev->mode_info.dither_property =
703 drm_property_create_enum(adev->ddev, 0,
704 "dither",
705 amdgpu_dither_enum_list, sz);
706
707 return 0;
708}
709
710void amdgpu_update_display_priority(struct amdgpu_device *adev)
711{
712 /* adjustment options for the display watermarks */
713 if ((amdgpu_disp_priority == 0) || (amdgpu_disp_priority > 2))
714 adev->mode_info.disp_priority = 0;
715 else
716 adev->mode_info.disp_priority = amdgpu_disp_priority;
717
718}
719
720static bool is_hdtv_mode(const struct drm_display_mode *mode)
721{
722 /* try and guess if this is a tv or a monitor */
723 if ((mode->vdisplay == 480 && mode->hdisplay == 720) || /* 480p */
724 (mode->vdisplay == 576) || /* 576p */
725 (mode->vdisplay == 720) || /* 720p */
726 (mode->vdisplay == 1080)) /* 1080p */
727 return true;
728 else
729 return false;
730}
731
732bool amdgpu_crtc_scaling_mode_fixup(struct drm_crtc *crtc,
733 const struct drm_display_mode *mode,
734 struct drm_display_mode *adjusted_mode)
735{
736 struct drm_device *dev = crtc->dev;
737 struct drm_encoder *encoder;
738 struct amdgpu_crtc *amdgpu_crtc = to_amdgpu_crtc(crtc);
739 struct amdgpu_encoder *amdgpu_encoder;
740 struct drm_connector *connector;
741 struct amdgpu_connector *amdgpu_connector;
742 u32 src_v = 1, dst_v = 1;
743 u32 src_h = 1, dst_h = 1;
744
745 amdgpu_crtc->h_border = 0;
746 amdgpu_crtc->v_border = 0;
747
748 list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
749 if (encoder->crtc != crtc)
750 continue;
751 amdgpu_encoder = to_amdgpu_encoder(encoder);
752 connector = amdgpu_get_connector_for_encoder(encoder);
753 amdgpu_connector = to_amdgpu_connector(connector);
754
755 /* set scaling */
756 if (amdgpu_encoder->rmx_type == RMX_OFF)
757 amdgpu_crtc->rmx_type = RMX_OFF;
758 else if (mode->hdisplay < amdgpu_encoder->native_mode.hdisplay ||
759 mode->vdisplay < amdgpu_encoder->native_mode.vdisplay)
760 amdgpu_crtc->rmx_type = amdgpu_encoder->rmx_type;
761 else
762 amdgpu_crtc->rmx_type = RMX_OFF;
763 /* copy native mode */
764 memcpy(&amdgpu_crtc->native_mode,
765 &amdgpu_encoder->native_mode,
766 sizeof(struct drm_display_mode));
767 src_v = crtc->mode.vdisplay;
768 dst_v = amdgpu_crtc->native_mode.vdisplay;
769 src_h = crtc->mode.hdisplay;
770 dst_h = amdgpu_crtc->native_mode.hdisplay;
771
772 /* fix up for overscan on hdmi */
773 if ((!(mode->flags & DRM_MODE_FLAG_INTERLACE)) &&
774 ((amdgpu_encoder->underscan_type == UNDERSCAN_ON) ||
775 ((amdgpu_encoder->underscan_type == UNDERSCAN_AUTO) &&
776 drm_detect_hdmi_monitor(amdgpu_connector_edid(connector)) &&
777 is_hdtv_mode(mode)))) {
778 if (amdgpu_encoder->underscan_hborder != 0)
779 amdgpu_crtc->h_border = amdgpu_encoder->underscan_hborder;
780 else
781 amdgpu_crtc->h_border = (mode->hdisplay >> 5) + 16;
782 if (amdgpu_encoder->underscan_vborder != 0)
783 amdgpu_crtc->v_border = amdgpu_encoder->underscan_vborder;
784 else
785 amdgpu_crtc->v_border = (mode->vdisplay >> 5) + 16;
786 amdgpu_crtc->rmx_type = RMX_FULL;
787 src_v = crtc->mode.vdisplay;
788 dst_v = crtc->mode.vdisplay - (amdgpu_crtc->v_border * 2);
789 src_h = crtc->mode.hdisplay;
790 dst_h = crtc->mode.hdisplay - (amdgpu_crtc->h_border * 2);
791 }
792 }
793 if (amdgpu_crtc->rmx_type != RMX_OFF) {
794 fixed20_12 a, b;
795 a.full = dfixed_const(src_v);
796 b.full = dfixed_const(dst_v);
797 amdgpu_crtc->vsc.full = dfixed_div(a, b);
798 a.full = dfixed_const(src_h);
799 b.full = dfixed_const(dst_h);
800 amdgpu_crtc->hsc.full = dfixed_div(a, b);
801 } else {
802 amdgpu_crtc->vsc.full = dfixed_const(1);
803 amdgpu_crtc->hsc.full = dfixed_const(1);
804 }
805 return true;
806}
807
808/*
809 * Retrieve current video scanout position of crtc on a given gpu, and
810 * an optional accurate timestamp of when query happened.
811 *
812 * \param dev Device to query.
Thierry Reding88e72712015-09-24 18:35:31 +0200813 * \param pipe Crtc to query.
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400814 * \param flags Flags from caller (DRM_CALLED_FROM_VBLIRQ or 0).
Alex Deucher8e36f9d2015-12-03 12:31:56 -0500815 * For driver internal use only also supports these flags:
816 *
817 * USE_REAL_VBLANKSTART to use the real start of vblank instead
818 * of a fudged earlier start of vblank.
819 *
820 * GET_DISTANCE_TO_VBLANKSTART to return distance to the
821 * fudged earlier start of vblank in *vpos and the distance
822 * to true start of vblank in *hpos.
823 *
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400824 * \param *vpos Location where vertical scanout position should be stored.
825 * \param *hpos Location where horizontal scanout position should go.
826 * \param *stime Target location for timestamp taken immediately before
827 * scanout position query. Can be NULL to skip timestamp.
828 * \param *etime Target location for timestamp taken immediately after
829 * scanout position query. Can be NULL to skip timestamp.
830 *
831 * Returns vpos as a positive number while in active scanout area.
832 * Returns vpos as a negative number inside vblank, counting the number
833 * of scanlines to go until end of vblank, e.g., -1 means "one scanline
834 * until start of active scanout / end of vblank."
835 *
836 * \return Flags, or'ed together as follows:
837 *
838 * DRM_SCANOUTPOS_VALID = Query successful.
839 * DRM_SCANOUTPOS_INVBL = Inside vblank.
840 * DRM_SCANOUTPOS_ACCURATE = Returned position is accurate. A lack of
841 * this flag means that returned position may be offset by a constant but
842 * unknown small number of scanlines wrt. real scanout position.
843 *
844 */
Thierry Reding88e72712015-09-24 18:35:31 +0200845int amdgpu_get_crtc_scanoutpos(struct drm_device *dev, unsigned int pipe,
846 unsigned int flags, int *vpos, int *hpos,
847 ktime_t *stime, ktime_t *etime,
Ville Syrjälä3bb403b2015-09-14 22:43:44 +0300848 const struct drm_display_mode *mode)
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400849{
850 u32 vbl = 0, position = 0;
851 int vbl_start, vbl_end, vtotal, ret = 0;
852 bool in_vbl = true;
853
854 struct amdgpu_device *adev = dev->dev_private;
855
856 /* preempt_disable_rt() should go right here in PREEMPT_RT patchset. */
857
858 /* Get optional system timestamp before query. */
859 if (stime)
860 *stime = ktime_get();
861
Thierry Reding88e72712015-09-24 18:35:31 +0200862 if (amdgpu_display_page_flip_get_scanoutpos(adev, pipe, &vbl, &position) == 0)
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400863 ret |= DRM_SCANOUTPOS_VALID;
864
865 /* Get optional system timestamp after query. */
866 if (etime)
867 *etime = ktime_get();
868
869 /* preempt_enable_rt() should go right here in PREEMPT_RT patchset. */
870
871 /* Decode into vertical and horizontal scanout position. */
872 *vpos = position & 0x1fff;
873 *hpos = (position >> 16) & 0x1fff;
874
875 /* Valid vblank area boundaries from gpu retrieved? */
876 if (vbl > 0) {
877 /* Yes: Decode. */
878 ret |= DRM_SCANOUTPOS_ACCURATE;
879 vbl_start = vbl & 0x1fff;
880 vbl_end = (vbl >> 16) & 0x1fff;
881 }
882 else {
883 /* No: Fake something reasonable which gives at least ok results. */
Ville Syrjälä3bb403b2015-09-14 22:43:44 +0300884 vbl_start = mode->crtc_vdisplay;
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400885 vbl_end = 0;
886 }
887
Alex Deucher8e36f9d2015-12-03 12:31:56 -0500888 /* Called from driver internal vblank counter query code? */
889 if (flags & GET_DISTANCE_TO_VBLANKSTART) {
890 /* Caller wants distance from real vbl_start in *hpos */
891 *hpos = *vpos - vbl_start;
892 }
893
894 /* Fudge vblank to start a few scanlines earlier to handle the
895 * problem that vblank irqs fire a few scanlines before start
896 * of vblank. Some driver internal callers need the true vblank
897 * start to be used and signal this via the USE_REAL_VBLANKSTART flag.
898 *
899 * The cause of the "early" vblank irq is that the irq is triggered
900 * by the line buffer logic when the line buffer read position enters
901 * the vblank, whereas our crtc scanout position naturally lags the
902 * line buffer read position.
903 */
904 if (!(flags & USE_REAL_VBLANKSTART))
905 vbl_start -= adev->mode_info.crtcs[pipe]->lb_vblank_lead_lines;
906
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400907 /* Test scanout position against vblank region. */
908 if ((*vpos < vbl_start) && (*vpos >= vbl_end))
909 in_vbl = false;
910
Alex Deucher8e36f9d2015-12-03 12:31:56 -0500911 /* In vblank? */
912 if (in_vbl)
913 ret |= DRM_SCANOUTPOS_IN_VBLANK;
914
915 /* Called from driver internal vblank counter query code? */
916 if (flags & GET_DISTANCE_TO_VBLANKSTART) {
917 /* Caller wants distance from fudged earlier vbl_start */
918 *vpos -= vbl_start;
919 return ret;
920 }
921
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400922 /* Check if inside vblank area and apply corrective offsets:
923 * vpos will then be >=0 in video scanout area, but negative
924 * within vblank area, counting down the number of lines until
925 * start of scanout.
926 */
927
928 /* Inside "upper part" of vblank area? Apply corrective offset if so: */
929 if (in_vbl && (*vpos >= vbl_start)) {
Ville Syrjälä3bb403b2015-09-14 22:43:44 +0300930 vtotal = mode->crtc_vtotal;
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400931 *vpos = *vpos - vtotal;
932 }
933
934 /* Correct for shifted end of vbl at vbl_end. */
935 *vpos = *vpos - vbl_end;
936
Alex Deucherd38ceaf2015-04-20 16:55:21 -0400937 return ret;
938}
939
940int amdgpu_crtc_idx_to_irq_type(struct amdgpu_device *adev, int crtc)
941{
942 if (crtc < 0 || crtc >= adev->mode_info.num_crtc)
943 return AMDGPU_CRTC_IRQ_NONE;
944
945 switch (crtc) {
946 case 0:
947 return AMDGPU_CRTC_IRQ_VBLANK1;
948 case 1:
949 return AMDGPU_CRTC_IRQ_VBLANK2;
950 case 2:
951 return AMDGPU_CRTC_IRQ_VBLANK3;
952 case 3:
953 return AMDGPU_CRTC_IRQ_VBLANK4;
954 case 4:
955 return AMDGPU_CRTC_IRQ_VBLANK5;
956 case 5:
957 return AMDGPU_CRTC_IRQ_VBLANK6;
958 default:
959 return AMDGPU_CRTC_IRQ_NONE;
960 }
961}