Emily Deng | c6e14f4 | 2016-08-08 11:30:50 +0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2014 Advanced Micro Devices, Inc. |
| 3 | * |
| 4 | * Permission is hereby granted, free of charge, to any person obtaining a |
| 5 | * copy of this software and associated documentation files (the "Software"), |
| 6 | * to deal in the Software without restriction, including without limitation |
| 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 8 | * and/or sell copies of the Software, and to permit persons to whom the |
| 9 | * Software is furnished to do so, subject to the following conditions: |
| 10 | * |
| 11 | * The above copyright notice and this permission notice shall be included in |
| 12 | * all copies or substantial portions of the Software. |
| 13 | * |
| 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 17 | * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR |
| 18 | * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, |
| 19 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
| 20 | * OTHER DEALINGS IN THE SOFTWARE. |
| 21 | * |
| 22 | */ |
Masahiro Yamada | 248a1d6 | 2017-04-24 13:50:21 +0900 | [diff] [blame] | 23 | #include <drm/drmP.h> |
Emily Deng | c6e14f4 | 2016-08-08 11:30:50 +0800 | [diff] [blame] | 24 | #include "amdgpu.h" |
| 25 | #include "amdgpu_pm.h" |
| 26 | #include "amdgpu_i2c.h" |
| 27 | #include "atom.h" |
Emily Deng | c6e14f4 | 2016-08-08 11:30:50 +0800 | [diff] [blame] | 28 | #include "amdgpu_pll.h" |
| 29 | #include "amdgpu_connectors.h" |
Alex Deucher | a1d3704 | 2016-09-29 23:36:12 -0400 | [diff] [blame] | 30 | #ifdef CONFIG_DRM_AMDGPU_SI |
| 31 | #include "dce_v6_0.h" |
| 32 | #endif |
Emily Deng | 83c9b02 | 2016-08-08 11:33:11 +0800 | [diff] [blame] | 33 | #ifdef CONFIG_DRM_AMDGPU_CIK |
| 34 | #include "dce_v8_0.h" |
| 35 | #endif |
| 36 | #include "dce_v10_0.h" |
| 37 | #include "dce_v11_0.h" |
Emily Deng | 46ac362 | 2016-08-08 11:35:39 +0800 | [diff] [blame] | 38 | #include "dce_virtual.h" |
Emily Deng | c6e14f4 | 2016-08-08 11:30:50 +0800 | [diff] [blame] | 39 | |
Alex Deucher | 623fea1 | 2016-10-13 17:36:46 -0400 | [diff] [blame] | 40 | #define DCE_VIRTUAL_VBLANK_PERIOD 16666666 |
| 41 | |
| 42 | |
Emily Deng | c6e14f4 | 2016-08-08 11:30:50 +0800 | [diff] [blame] | 43 | static void dce_virtual_set_display_funcs(struct amdgpu_device *adev); |
| 44 | static void dce_virtual_set_irq_funcs(struct amdgpu_device *adev); |
Alex Deucher | 66264ba | 2016-09-30 12:37:36 -0400 | [diff] [blame] | 45 | static int dce_virtual_connector_encoder_init(struct amdgpu_device *adev, |
| 46 | int index); |
Monk Liu | 1719efc | 2017-11-16 11:11:39 +0800 | [diff] [blame] | 47 | static void dce_virtual_set_crtc_vblank_interrupt_state(struct amdgpu_device *adev, |
| 48 | int crtc, |
| 49 | enum amdgpu_interrupt_state state); |
Emily Deng | c6e14f4 | 2016-08-08 11:30:50 +0800 | [diff] [blame] | 50 | |
Emily Deng | 8e6de75 | 2016-08-08 11:31:13 +0800 | [diff] [blame] | 51 | static u32 dce_virtual_vblank_get_counter(struct amdgpu_device *adev, int crtc) |
| 52 | { |
Emily Deng | 041aa65 | 2016-08-17 14:59:20 +0800 | [diff] [blame] | 53 | return 0; |
Emily Deng | 8e6de75 | 2016-08-08 11:31:13 +0800 | [diff] [blame] | 54 | } |
| 55 | |
| 56 | static void dce_virtual_page_flip(struct amdgpu_device *adev, |
| 57 | int crtc_id, u64 crtc_base, bool async) |
| 58 | { |
| 59 | return; |
| 60 | } |
| 61 | |
| 62 | static int dce_virtual_crtc_get_scanoutpos(struct amdgpu_device *adev, int crtc, |
| 63 | u32 *vbl, u32 *position) |
| 64 | { |
Emily Deng | 8e6de75 | 2016-08-08 11:31:13 +0800 | [diff] [blame] | 65 | *vbl = 0; |
| 66 | *position = 0; |
| 67 | |
Emily Deng | 041aa65 | 2016-08-17 14:59:20 +0800 | [diff] [blame] | 68 | return -EINVAL; |
Emily Deng | 8e6de75 | 2016-08-08 11:31:13 +0800 | [diff] [blame] | 69 | } |
| 70 | |
| 71 | static bool dce_virtual_hpd_sense(struct amdgpu_device *adev, |
| 72 | enum amdgpu_hpd_id hpd) |
| 73 | { |
| 74 | return true; |
| 75 | } |
| 76 | |
| 77 | static void dce_virtual_hpd_set_polarity(struct amdgpu_device *adev, |
| 78 | enum amdgpu_hpd_id hpd) |
| 79 | { |
| 80 | return; |
| 81 | } |
| 82 | |
| 83 | static u32 dce_virtual_hpd_get_gpio_reg(struct amdgpu_device *adev) |
| 84 | { |
| 85 | return 0; |
| 86 | } |
| 87 | |
Emily Deng | 8e6de75 | 2016-08-08 11:31:13 +0800 | [diff] [blame] | 88 | /** |
| 89 | * dce_virtual_bandwidth_update - program display watermarks |
| 90 | * |
| 91 | * @adev: amdgpu_device pointer |
| 92 | * |
| 93 | * Calculate and program the display watermarks and line |
| 94 | * buffer allocation (CIK). |
| 95 | */ |
| 96 | static void dce_virtual_bandwidth_update(struct amdgpu_device *adev) |
| 97 | { |
| 98 | return; |
| 99 | } |
| 100 | |
Emily Deng | 0d43f3b | 2016-08-08 11:32:22 +0800 | [diff] [blame] | 101 | static int dce_virtual_crtc_gamma_set(struct drm_crtc *crtc, u16 *red, |
Daniel Vetter | 6d124ff | 2017-04-03 10:33:01 +0200 | [diff] [blame] | 102 | u16 *green, u16 *blue, uint32_t size, |
| 103 | struct drm_modeset_acquire_ctx *ctx) |
Emily Deng | 0d43f3b | 2016-08-08 11:32:22 +0800 | [diff] [blame] | 104 | { |
Emily Deng | 0d43f3b | 2016-08-08 11:32:22 +0800 | [diff] [blame] | 105 | return 0; |
| 106 | } |
| 107 | |
| 108 | static void dce_virtual_crtc_destroy(struct drm_crtc *crtc) |
| 109 | { |
| 110 | struct amdgpu_crtc *amdgpu_crtc = to_amdgpu_crtc(crtc); |
| 111 | |
| 112 | drm_crtc_cleanup(crtc); |
| 113 | kfree(amdgpu_crtc); |
| 114 | } |
| 115 | |
Emily Deng | c6e14f4 | 2016-08-08 11:30:50 +0800 | [diff] [blame] | 116 | static const struct drm_crtc_funcs dce_virtual_crtc_funcs = { |
| 117 | .cursor_set2 = NULL, |
| 118 | .cursor_move = NULL, |
Emily Deng | 0d43f3b | 2016-08-08 11:32:22 +0800 | [diff] [blame] | 119 | .gamma_set = dce_virtual_crtc_gamma_set, |
Samuel Li | 775a836 | 2018-01-19 11:53:31 -0500 | [diff] [blame] | 120 | .set_config = amdgpu_display_crtc_set_config, |
Emily Deng | 0d43f3b | 2016-08-08 11:32:22 +0800 | [diff] [blame] | 121 | .destroy = dce_virtual_crtc_destroy, |
Samuel Li | 0cd1193 | 2018-01-19 11:22:59 -0500 | [diff] [blame] | 122 | .page_flip_target = amdgpu_display_crtc_page_flip_target, |
Emily Deng | c6e14f4 | 2016-08-08 11:30:50 +0800 | [diff] [blame] | 123 | }; |
| 124 | |
Emily Deng | f1f5ef9 | 2016-08-08 11:32:00 +0800 | [diff] [blame] | 125 | static void dce_virtual_crtc_dpms(struct drm_crtc *crtc, int mode) |
| 126 | { |
| 127 | struct drm_device *dev = crtc->dev; |
| 128 | struct amdgpu_device *adev = dev->dev_private; |
| 129 | struct amdgpu_crtc *amdgpu_crtc = to_amdgpu_crtc(crtc); |
| 130 | unsigned type; |
| 131 | |
Xiangliang Yu | ebe0a80 | 2017-02-14 16:08:18 +0800 | [diff] [blame] | 132 | if (amdgpu_sriov_vf(adev)) |
| 133 | return; |
| 134 | |
Emily Deng | f1f5ef9 | 2016-08-08 11:32:00 +0800 | [diff] [blame] | 135 | switch (mode) { |
| 136 | case DRM_MODE_DPMS_ON: |
| 137 | amdgpu_crtc->enabled = true; |
Alex Deucher | 82b9f81 | 2016-09-30 11:19:41 -0400 | [diff] [blame] | 138 | /* Make sure VBLANK interrupts are still enabled */ |
Samuel Li | 734dd01 | 2018-01-19 16:06:41 -0500 | [diff] [blame] | 139 | type = amdgpu_display_crtc_idx_to_irq_type(adev, |
| 140 | amdgpu_crtc->crtc_id); |
Emily Deng | f1f5ef9 | 2016-08-08 11:32:00 +0800 | [diff] [blame] | 141 | amdgpu_irq_update(adev, &adev->crtc_irq, type); |
Daniel Vetter | 2d1e331 | 2016-11-14 10:02:54 +0100 | [diff] [blame] | 142 | drm_crtc_vblank_on(crtc); |
Emily Deng | f1f5ef9 | 2016-08-08 11:32:00 +0800 | [diff] [blame] | 143 | break; |
| 144 | case DRM_MODE_DPMS_STANDBY: |
| 145 | case DRM_MODE_DPMS_SUSPEND: |
| 146 | case DRM_MODE_DPMS_OFF: |
Daniel Vetter | 2d1e331 | 2016-11-14 10:02:54 +0100 | [diff] [blame] | 147 | drm_crtc_vblank_off(crtc); |
Emily Deng | f1f5ef9 | 2016-08-08 11:32:00 +0800 | [diff] [blame] | 148 | amdgpu_crtc->enabled = false; |
| 149 | break; |
| 150 | } |
| 151 | } |
| 152 | |
| 153 | |
| 154 | static void dce_virtual_crtc_prepare(struct drm_crtc *crtc) |
| 155 | { |
| 156 | dce_virtual_crtc_dpms(crtc, DRM_MODE_DPMS_OFF); |
| 157 | } |
| 158 | |
| 159 | static void dce_virtual_crtc_commit(struct drm_crtc *crtc) |
| 160 | { |
| 161 | dce_virtual_crtc_dpms(crtc, DRM_MODE_DPMS_ON); |
| 162 | } |
| 163 | |
| 164 | static void dce_virtual_crtc_disable(struct drm_crtc *crtc) |
| 165 | { |
| 166 | struct amdgpu_crtc *amdgpu_crtc = to_amdgpu_crtc(crtc); |
| 167 | |
| 168 | dce_virtual_crtc_dpms(crtc, DRM_MODE_DPMS_OFF); |
| 169 | if (crtc->primary->fb) { |
| 170 | int r; |
Christian König | 765e7fb | 2016-09-15 15:06:50 +0200 | [diff] [blame] | 171 | struct amdgpu_bo *abo; |
Emily Deng | f1f5ef9 | 2016-08-08 11:32:00 +0800 | [diff] [blame] | 172 | |
Daniel Stone | e68d14d | 2018-03-30 15:11:38 +0100 | [diff] [blame] | 173 | abo = gem_to_amdgpu_bo(crtc->primary->fb->obj[0]); |
Michel Dänzer | c81a1a7 | 2017-04-28 17:28:14 +0900 | [diff] [blame] | 174 | r = amdgpu_bo_reserve(abo, true); |
Emily Deng | f1f5ef9 | 2016-08-08 11:32:00 +0800 | [diff] [blame] | 175 | if (unlikely(r)) |
Christian König | 765e7fb | 2016-09-15 15:06:50 +0200 | [diff] [blame] | 176 | DRM_ERROR("failed to reserve abo before unpin\n"); |
Emily Deng | f1f5ef9 | 2016-08-08 11:32:00 +0800 | [diff] [blame] | 177 | else { |
Christian König | 765e7fb | 2016-09-15 15:06:50 +0200 | [diff] [blame] | 178 | amdgpu_bo_unpin(abo); |
| 179 | amdgpu_bo_unreserve(abo); |
Emily Deng | f1f5ef9 | 2016-08-08 11:32:00 +0800 | [diff] [blame] | 180 | } |
| 181 | } |
| 182 | |
| 183 | amdgpu_crtc->pll_id = ATOM_PPLL_INVALID; |
| 184 | amdgpu_crtc->encoder = NULL; |
| 185 | amdgpu_crtc->connector = NULL; |
| 186 | } |
| 187 | |
| 188 | static int dce_virtual_crtc_mode_set(struct drm_crtc *crtc, |
| 189 | struct drm_display_mode *mode, |
| 190 | struct drm_display_mode *adjusted_mode, |
| 191 | int x, int y, struct drm_framebuffer *old_fb) |
| 192 | { |
| 193 | struct amdgpu_crtc *amdgpu_crtc = to_amdgpu_crtc(crtc); |
| 194 | |
| 195 | /* update the hw version fpr dpm */ |
| 196 | amdgpu_crtc->hw_mode = *adjusted_mode; |
| 197 | |
| 198 | return 0; |
| 199 | } |
| 200 | |
| 201 | static bool dce_virtual_crtc_mode_fixup(struct drm_crtc *crtc, |
| 202 | const struct drm_display_mode *mode, |
| 203 | struct drm_display_mode *adjusted_mode) |
| 204 | { |
Emily Deng | f1f5ef9 | 2016-08-08 11:32:00 +0800 | [diff] [blame] | 205 | return true; |
| 206 | } |
| 207 | |
| 208 | |
| 209 | static int dce_virtual_crtc_set_base(struct drm_crtc *crtc, int x, int y, |
| 210 | struct drm_framebuffer *old_fb) |
| 211 | { |
| 212 | return 0; |
| 213 | } |
| 214 | |
Emily Deng | f1f5ef9 | 2016-08-08 11:32:00 +0800 | [diff] [blame] | 215 | static int dce_virtual_crtc_set_base_atomic(struct drm_crtc *crtc, |
| 216 | struct drm_framebuffer *fb, |
| 217 | int x, int y, enum mode_set_atomic state) |
| 218 | { |
| 219 | return 0; |
| 220 | } |
| 221 | |
Emily Deng | c6e14f4 | 2016-08-08 11:30:50 +0800 | [diff] [blame] | 222 | static const struct drm_crtc_helper_funcs dce_virtual_crtc_helper_funcs = { |
Emily Deng | f1f5ef9 | 2016-08-08 11:32:00 +0800 | [diff] [blame] | 223 | .dpms = dce_virtual_crtc_dpms, |
| 224 | .mode_fixup = dce_virtual_crtc_mode_fixup, |
| 225 | .mode_set = dce_virtual_crtc_mode_set, |
| 226 | .mode_set_base = dce_virtual_crtc_set_base, |
| 227 | .mode_set_base_atomic = dce_virtual_crtc_set_base_atomic, |
| 228 | .prepare = dce_virtual_crtc_prepare, |
| 229 | .commit = dce_virtual_crtc_commit, |
Emily Deng | f1f5ef9 | 2016-08-08 11:32:00 +0800 | [diff] [blame] | 230 | .disable = dce_virtual_crtc_disable, |
Emily Deng | c6e14f4 | 2016-08-08 11:30:50 +0800 | [diff] [blame] | 231 | }; |
| 232 | |
| 233 | static int dce_virtual_crtc_init(struct amdgpu_device *adev, int index) |
| 234 | { |
| 235 | struct amdgpu_crtc *amdgpu_crtc; |
Emily Deng | c6e14f4 | 2016-08-08 11:30:50 +0800 | [diff] [blame] | 236 | |
| 237 | amdgpu_crtc = kzalloc(sizeof(struct amdgpu_crtc) + |
| 238 | (AMDGPUFB_CONN_LIMIT * sizeof(struct drm_connector *)), GFP_KERNEL); |
| 239 | if (amdgpu_crtc == NULL) |
| 240 | return -ENOMEM; |
| 241 | |
| 242 | drm_crtc_init(adev->ddev, &amdgpu_crtc->base, &dce_virtual_crtc_funcs); |
| 243 | |
| 244 | drm_mode_crtc_set_gamma_size(&amdgpu_crtc->base, 256); |
| 245 | amdgpu_crtc->crtc_id = index; |
| 246 | adev->mode_info.crtcs[index] = amdgpu_crtc; |
| 247 | |
Emily Deng | c6e14f4 | 2016-08-08 11:30:50 +0800 | [diff] [blame] | 248 | amdgpu_crtc->pll_id = ATOM_PPLL_INVALID; |
| 249 | amdgpu_crtc->encoder = NULL; |
| 250 | amdgpu_crtc->connector = NULL; |
Emily Deng | 0f66356 | 2016-09-30 13:02:18 -0400 | [diff] [blame] | 251 | amdgpu_crtc->vsync_timer_enabled = AMDGPU_IRQ_STATE_DISABLE; |
Emily Deng | c6e14f4 | 2016-08-08 11:30:50 +0800 | [diff] [blame] | 252 | drm_crtc_helper_add(&amdgpu_crtc->base, &dce_virtual_crtc_helper_funcs); |
| 253 | |
| 254 | return 0; |
| 255 | } |
| 256 | |
| 257 | static int dce_virtual_early_init(void *handle) |
| 258 | { |
| 259 | struct amdgpu_device *adev = (struct amdgpu_device *)handle; |
| 260 | |
| 261 | dce_virtual_set_display_funcs(adev); |
| 262 | dce_virtual_set_irq_funcs(adev); |
| 263 | |
Emily Deng | c6e14f4 | 2016-08-08 11:30:50 +0800 | [diff] [blame] | 264 | adev->mode_info.num_hpd = 1; |
| 265 | adev->mode_info.num_dig = 1; |
| 266 | return 0; |
| 267 | } |
| 268 | |
Alex Deucher | 66264ba | 2016-09-30 12:37:36 -0400 | [diff] [blame] | 269 | static struct drm_encoder * |
| 270 | dce_virtual_encoder(struct drm_connector *connector) |
Emily Deng | c6e14f4 | 2016-08-08 11:30:50 +0800 | [diff] [blame] | 271 | { |
Alex Deucher | 66264ba | 2016-09-30 12:37:36 -0400 | [diff] [blame] | 272 | int enc_id = connector->encoder_ids[0]; |
| 273 | struct drm_encoder *encoder; |
| 274 | int i; |
Emily Deng | c6e14f4 | 2016-08-08 11:30:50 +0800 | [diff] [blame] | 275 | |
Alex Deucher | 66264ba | 2016-09-30 12:37:36 -0400 | [diff] [blame] | 276 | for (i = 0; i < DRM_CONNECTOR_MAX_ENCODER; i++) { |
| 277 | if (connector->encoder_ids[i] == 0) |
| 278 | break; |
Emily Deng | c6e14f4 | 2016-08-08 11:30:50 +0800 | [diff] [blame] | 279 | |
Keith Packard | 418da17 | 2017-03-14 23:25:07 -0700 | [diff] [blame] | 280 | encoder = drm_encoder_find(connector->dev, NULL, connector->encoder_ids[i]); |
Alex Deucher | 66264ba | 2016-09-30 12:37:36 -0400 | [diff] [blame] | 281 | if (!encoder) |
| 282 | continue; |
Emily Deng | c6e14f4 | 2016-08-08 11:30:50 +0800 | [diff] [blame] | 283 | |
Alex Deucher | 66264ba | 2016-09-30 12:37:36 -0400 | [diff] [blame] | 284 | if (encoder->encoder_type == DRM_MODE_ENCODER_VIRTUAL) |
| 285 | return encoder; |
| 286 | } |
Emily Deng | c6e14f4 | 2016-08-08 11:30:50 +0800 | [diff] [blame] | 287 | |
Alex Deucher | 66264ba | 2016-09-30 12:37:36 -0400 | [diff] [blame] | 288 | /* pick the first one */ |
| 289 | if (enc_id) |
Keith Packard | 418da17 | 2017-03-14 23:25:07 -0700 | [diff] [blame] | 290 | return drm_encoder_find(connector->dev, NULL, enc_id); |
Alex Deucher | 66264ba | 2016-09-30 12:37:36 -0400 | [diff] [blame] | 291 | return NULL; |
Emily Deng | c6e14f4 | 2016-08-08 11:30:50 +0800 | [diff] [blame] | 292 | } |
| 293 | |
Alex Deucher | 66264ba | 2016-09-30 12:37:36 -0400 | [diff] [blame] | 294 | static int dce_virtual_get_modes(struct drm_connector *connector) |
| 295 | { |
| 296 | struct drm_device *dev = connector->dev; |
| 297 | struct drm_display_mode *mode = NULL; |
| 298 | unsigned i; |
| 299 | static const struct mode_size { |
| 300 | int w; |
| 301 | int h; |
| 302 | } common_modes[17] = { |
| 303 | { 640, 480}, |
| 304 | { 720, 480}, |
| 305 | { 800, 600}, |
| 306 | { 848, 480}, |
| 307 | {1024, 768}, |
| 308 | {1152, 768}, |
| 309 | {1280, 720}, |
| 310 | {1280, 800}, |
| 311 | {1280, 854}, |
| 312 | {1280, 960}, |
| 313 | {1280, 1024}, |
| 314 | {1440, 900}, |
| 315 | {1400, 1050}, |
| 316 | {1680, 1050}, |
| 317 | {1600, 1200}, |
| 318 | {1920, 1080}, |
| 319 | {1920, 1200} |
| 320 | }; |
| 321 | |
| 322 | for (i = 0; i < 17; i++) { |
| 323 | mode = drm_cvt_mode(dev, common_modes[i].w, common_modes[i].h, 60, false, false, false); |
| 324 | drm_mode_probed_add(connector, mode); |
| 325 | } |
| 326 | |
| 327 | return 0; |
| 328 | } |
| 329 | |
Luc Van Oostenryck | ba9ca08 | 2018-04-24 15:14:18 +0200 | [diff] [blame] | 330 | static enum drm_mode_status dce_virtual_mode_valid(struct drm_connector *connector, |
Alex Deucher | 66264ba | 2016-09-30 12:37:36 -0400 | [diff] [blame] | 331 | struct drm_display_mode *mode) |
| 332 | { |
| 333 | return MODE_OK; |
| 334 | } |
| 335 | |
| 336 | static int |
| 337 | dce_virtual_dpms(struct drm_connector *connector, int mode) |
| 338 | { |
| 339 | return 0; |
| 340 | } |
| 341 | |
Alex Deucher | 66264ba | 2016-09-30 12:37:36 -0400 | [diff] [blame] | 342 | static int |
| 343 | dce_virtual_set_property(struct drm_connector *connector, |
| 344 | struct drm_property *property, |
| 345 | uint64_t val) |
| 346 | { |
| 347 | return 0; |
| 348 | } |
| 349 | |
| 350 | static void dce_virtual_destroy(struct drm_connector *connector) |
| 351 | { |
| 352 | drm_connector_unregister(connector); |
| 353 | drm_connector_cleanup(connector); |
| 354 | kfree(connector); |
| 355 | } |
| 356 | |
| 357 | static void dce_virtual_force(struct drm_connector *connector) |
| 358 | { |
| 359 | return; |
| 360 | } |
| 361 | |
| 362 | static const struct drm_connector_helper_funcs dce_virtual_connector_helper_funcs = { |
| 363 | .get_modes = dce_virtual_get_modes, |
| 364 | .mode_valid = dce_virtual_mode_valid, |
| 365 | .best_encoder = dce_virtual_encoder, |
| 366 | }; |
| 367 | |
| 368 | static const struct drm_connector_funcs dce_virtual_connector_funcs = { |
| 369 | .dpms = dce_virtual_dpms, |
Alex Deucher | 66264ba | 2016-09-30 12:37:36 -0400 | [diff] [blame] | 370 | .fill_modes = drm_helper_probe_single_connector_modes, |
| 371 | .set_property = dce_virtual_set_property, |
| 372 | .destroy = dce_virtual_destroy, |
| 373 | .force = dce_virtual_force, |
| 374 | }; |
| 375 | |
Emily Deng | c6e14f4 | 2016-08-08 11:30:50 +0800 | [diff] [blame] | 376 | static int dce_virtual_sw_init(void *handle) |
| 377 | { |
| 378 | int r, i; |
| 379 | struct amdgpu_device *adev = (struct amdgpu_device *)handle; |
| 380 | |
Alex Deucher | d766e6a | 2016-03-29 18:28:50 -0400 | [diff] [blame] | 381 | r = amdgpu_irq_add_id(adev, AMDGPU_IH_CLIENTID_LEGACY, 229, &adev->crtc_irq); |
Emily Deng | c6e14f4 | 2016-08-08 11:30:50 +0800 | [diff] [blame] | 382 | if (r) |
| 383 | return r; |
| 384 | |
Emily Deng | 041aa65 | 2016-08-17 14:59:20 +0800 | [diff] [blame] | 385 | adev->ddev->max_vblank_count = 0; |
| 386 | |
Emily Deng | c6e14f4 | 2016-08-08 11:30:50 +0800 | [diff] [blame] | 387 | adev->ddev->mode_config.funcs = &amdgpu_mode_funcs; |
| 388 | |
| 389 | adev->ddev->mode_config.max_width = 16384; |
| 390 | adev->ddev->mode_config.max_height = 16384; |
| 391 | |
| 392 | adev->ddev->mode_config.preferred_depth = 24; |
| 393 | adev->ddev->mode_config.prefer_shadow = 1; |
| 394 | |
Christian König | 770d13b | 2018-01-12 14:52:22 +0100 | [diff] [blame] | 395 | adev->ddev->mode_config.fb_base = adev->gmc.aper_base; |
Emily Deng | c6e14f4 | 2016-08-08 11:30:50 +0800 | [diff] [blame] | 396 | |
Samuel Li | 3dc9b1c | 2018-01-19 12:47:40 -0500 | [diff] [blame] | 397 | r = amdgpu_display_modeset_create_props(adev); |
Emily Deng | c6e14f4 | 2016-08-08 11:30:50 +0800 | [diff] [blame] | 398 | if (r) |
| 399 | return r; |
| 400 | |
| 401 | adev->ddev->mode_config.max_width = 16384; |
| 402 | adev->ddev->mode_config.max_height = 16384; |
| 403 | |
Alex Deucher | 66264ba | 2016-09-30 12:37:36 -0400 | [diff] [blame] | 404 | /* allocate crtcs, encoders, connectors */ |
Emily Deng | c6e14f4 | 2016-08-08 11:30:50 +0800 | [diff] [blame] | 405 | for (i = 0; i < adev->mode_info.num_crtc; i++) { |
| 406 | r = dce_virtual_crtc_init(adev, i); |
| 407 | if (r) |
| 408 | return r; |
Alex Deucher | 66264ba | 2016-09-30 12:37:36 -0400 | [diff] [blame] | 409 | r = dce_virtual_connector_encoder_init(adev, i); |
| 410 | if (r) |
| 411 | return r; |
Emily Deng | c6e14f4 | 2016-08-08 11:30:50 +0800 | [diff] [blame] | 412 | } |
| 413 | |
Emily Deng | c6e14f4 | 2016-08-08 11:30:50 +0800 | [diff] [blame] | 414 | drm_kms_helper_poll_init(adev->ddev); |
| 415 | |
| 416 | adev->mode_info.mode_config_initialized = true; |
| 417 | return 0; |
| 418 | } |
| 419 | |
| 420 | static int dce_virtual_sw_fini(void *handle) |
| 421 | { |
| 422 | struct amdgpu_device *adev = (struct amdgpu_device *)handle; |
| 423 | |
| 424 | kfree(adev->mode_info.bios_hardcoded_edid); |
| 425 | |
| 426 | drm_kms_helper_poll_fini(adev->ddev); |
| 427 | |
| 428 | drm_mode_config_cleanup(adev->ddev); |
Monk Liu | 129d65c | 2017-11-15 17:10:13 +0800 | [diff] [blame] | 429 | /* clear crtcs pointer to avoid dce irq finish routine access freed data */ |
| 430 | memset(adev->mode_info.crtcs, 0, sizeof(adev->mode_info.crtcs[0]) * AMDGPU_MAX_CRTCS); |
Emily Deng | c6e14f4 | 2016-08-08 11:30:50 +0800 | [diff] [blame] | 431 | adev->mode_info.mode_config_initialized = false; |
| 432 | return 0; |
| 433 | } |
| 434 | |
| 435 | static int dce_virtual_hw_init(void *handle) |
| 436 | { |
Alex Deucher | e4f6b39 | 2016-12-08 14:53:27 -0500 | [diff] [blame] | 437 | struct amdgpu_device *adev = (struct amdgpu_device *)handle; |
| 438 | |
| 439 | switch (adev->asic_type) { |
| 440 | #ifdef CONFIG_DRM_AMDGPU_SI |
| 441 | case CHIP_TAHITI: |
| 442 | case CHIP_PITCAIRN: |
| 443 | case CHIP_VERDE: |
| 444 | case CHIP_OLAND: |
| 445 | dce_v6_0_disable_dce(adev); |
| 446 | break; |
| 447 | #endif |
| 448 | #ifdef CONFIG_DRM_AMDGPU_CIK |
| 449 | case CHIP_BONAIRE: |
| 450 | case CHIP_HAWAII: |
| 451 | case CHIP_KAVERI: |
| 452 | case CHIP_KABINI: |
| 453 | case CHIP_MULLINS: |
| 454 | dce_v8_0_disable_dce(adev); |
| 455 | break; |
| 456 | #endif |
| 457 | case CHIP_FIJI: |
| 458 | case CHIP_TONGA: |
| 459 | dce_v10_0_disable_dce(adev); |
| 460 | break; |
| 461 | case CHIP_CARRIZO: |
| 462 | case CHIP_STONEY: |
Alex Deucher | e4f6b39 | 2016-12-08 14:53:27 -0500 | [diff] [blame] | 463 | case CHIP_POLARIS10: |
Leo Liu | be2c8cd | 2017-11-03 14:22:16 -0400 | [diff] [blame] | 464 | case CHIP_POLARIS11: |
| 465 | case CHIP_VEGAM: |
Alex Deucher | e4f6b39 | 2016-12-08 14:53:27 -0500 | [diff] [blame] | 466 | dce_v11_0_disable_dce(adev); |
| 467 | break; |
| 468 | case CHIP_TOPAZ: |
| 469 | #ifdef CONFIG_DRM_AMDGPU_SI |
| 470 | case CHIP_HAINAN: |
| 471 | #endif |
| 472 | /* no DCE */ |
| 473 | break; |
Xiangliang.Yu | 4a70af4 | 2017-07-25 17:34:54 +0800 | [diff] [blame] | 474 | case CHIP_VEGA10: |
Alex Deucher | f79f3fc | 2017-09-01 16:37:59 -0400 | [diff] [blame] | 475 | case CHIP_VEGA12: |
Feifei Xu | a2c319b | 2018-04-20 13:48:23 +0800 | [diff] [blame] | 476 | case CHIP_VEGA20: |
Xiangliang.Yu | 4a70af4 | 2017-07-25 17:34:54 +0800 | [diff] [blame] | 477 | break; |
Alex Deucher | e4f6b39 | 2016-12-08 14:53:27 -0500 | [diff] [blame] | 478 | default: |
| 479 | DRM_ERROR("Virtual display unsupported ASIC type: 0x%X\n", adev->asic_type); |
| 480 | } |
Emily Deng | c6e14f4 | 2016-08-08 11:30:50 +0800 | [diff] [blame] | 481 | return 0; |
| 482 | } |
| 483 | |
| 484 | static int dce_virtual_hw_fini(void *handle) |
| 485 | { |
Monk Liu | 1719efc | 2017-11-16 11:11:39 +0800 | [diff] [blame] | 486 | struct amdgpu_device *adev = (struct amdgpu_device *)handle; |
| 487 | int i = 0; |
| 488 | |
| 489 | for (i = 0; i<adev->mode_info.num_crtc; i++) |
| 490 | if (adev->mode_info.crtcs[i]) |
| 491 | dce_virtual_set_crtc_vblank_interrupt_state(adev, i, AMDGPU_IRQ_STATE_DISABLE); |
| 492 | |
Emily Deng | c6e14f4 | 2016-08-08 11:30:50 +0800 | [diff] [blame] | 493 | return 0; |
| 494 | } |
| 495 | |
| 496 | static int dce_virtual_suspend(void *handle) |
| 497 | { |
| 498 | return dce_virtual_hw_fini(handle); |
| 499 | } |
| 500 | |
| 501 | static int dce_virtual_resume(void *handle) |
| 502 | { |
Masahiro Yamada | d912ade | 2016-09-14 23:39:08 +0900 | [diff] [blame] | 503 | return dce_virtual_hw_init(handle); |
Emily Deng | c6e14f4 | 2016-08-08 11:30:50 +0800 | [diff] [blame] | 504 | } |
| 505 | |
| 506 | static bool dce_virtual_is_idle(void *handle) |
| 507 | { |
| 508 | return true; |
| 509 | } |
| 510 | |
| 511 | static int dce_virtual_wait_for_idle(void *handle) |
| 512 | { |
| 513 | return 0; |
| 514 | } |
| 515 | |
| 516 | static int dce_virtual_soft_reset(void *handle) |
| 517 | { |
| 518 | return 0; |
| 519 | } |
| 520 | |
| 521 | static int dce_virtual_set_clockgating_state(void *handle, |
| 522 | enum amd_clockgating_state state) |
| 523 | { |
| 524 | return 0; |
| 525 | } |
| 526 | |
| 527 | static int dce_virtual_set_powergating_state(void *handle, |
| 528 | enum amd_powergating_state state) |
| 529 | { |
| 530 | return 0; |
| 531 | } |
| 532 | |
Alex Deucher | a125510 | 2016-10-13 17:41:13 -0400 | [diff] [blame] | 533 | static const struct amd_ip_funcs dce_virtual_ip_funcs = { |
Emily Deng | c6e14f4 | 2016-08-08 11:30:50 +0800 | [diff] [blame] | 534 | .name = "dce_virtual", |
| 535 | .early_init = dce_virtual_early_init, |
| 536 | .late_init = NULL, |
| 537 | .sw_init = dce_virtual_sw_init, |
| 538 | .sw_fini = dce_virtual_sw_fini, |
| 539 | .hw_init = dce_virtual_hw_init, |
| 540 | .hw_fini = dce_virtual_hw_fini, |
| 541 | .suspend = dce_virtual_suspend, |
| 542 | .resume = dce_virtual_resume, |
| 543 | .is_idle = dce_virtual_is_idle, |
| 544 | .wait_for_idle = dce_virtual_wait_for_idle, |
| 545 | .soft_reset = dce_virtual_soft_reset, |
| 546 | .set_clockgating_state = dce_virtual_set_clockgating_state, |
| 547 | .set_powergating_state = dce_virtual_set_powergating_state, |
| 548 | }; |
| 549 | |
Emily Deng | 8e6de75 | 2016-08-08 11:31:13 +0800 | [diff] [blame] | 550 | /* these are handled by the primary encoders */ |
| 551 | static void dce_virtual_encoder_prepare(struct drm_encoder *encoder) |
| 552 | { |
| 553 | return; |
| 554 | } |
| 555 | |
| 556 | static void dce_virtual_encoder_commit(struct drm_encoder *encoder) |
| 557 | { |
| 558 | return; |
| 559 | } |
| 560 | |
| 561 | static void |
| 562 | dce_virtual_encoder_mode_set(struct drm_encoder *encoder, |
Alex Deucher | 66264ba | 2016-09-30 12:37:36 -0400 | [diff] [blame] | 563 | struct drm_display_mode *mode, |
| 564 | struct drm_display_mode *adjusted_mode) |
Emily Deng | 8e6de75 | 2016-08-08 11:31:13 +0800 | [diff] [blame] | 565 | { |
| 566 | return; |
| 567 | } |
| 568 | |
| 569 | static void dce_virtual_encoder_disable(struct drm_encoder *encoder) |
| 570 | { |
| 571 | return; |
| 572 | } |
| 573 | |
| 574 | static void |
| 575 | dce_virtual_encoder_dpms(struct drm_encoder *encoder, int mode) |
| 576 | { |
| 577 | return; |
| 578 | } |
| 579 | |
| 580 | static bool dce_virtual_encoder_mode_fixup(struct drm_encoder *encoder, |
| 581 | const struct drm_display_mode *mode, |
| 582 | struct drm_display_mode *adjusted_mode) |
| 583 | { |
Emily Deng | 8e6de75 | 2016-08-08 11:31:13 +0800 | [diff] [blame] | 584 | return true; |
| 585 | } |
| 586 | |
| 587 | static const struct drm_encoder_helper_funcs dce_virtual_encoder_helper_funcs = { |
| 588 | .dpms = dce_virtual_encoder_dpms, |
| 589 | .mode_fixup = dce_virtual_encoder_mode_fixup, |
| 590 | .prepare = dce_virtual_encoder_prepare, |
| 591 | .mode_set = dce_virtual_encoder_mode_set, |
| 592 | .commit = dce_virtual_encoder_commit, |
| 593 | .disable = dce_virtual_encoder_disable, |
| 594 | }; |
| 595 | |
| 596 | static void dce_virtual_encoder_destroy(struct drm_encoder *encoder) |
| 597 | { |
Emily Deng | 8e6de75 | 2016-08-08 11:31:13 +0800 | [diff] [blame] | 598 | drm_encoder_cleanup(encoder); |
Xiangliang Yu | 3a1d19a | 2017-01-19 09:57:41 +0800 | [diff] [blame] | 599 | kfree(encoder); |
Emily Deng | 8e6de75 | 2016-08-08 11:31:13 +0800 | [diff] [blame] | 600 | } |
| 601 | |
| 602 | static const struct drm_encoder_funcs dce_virtual_encoder_funcs = { |
| 603 | .destroy = dce_virtual_encoder_destroy, |
| 604 | }; |
| 605 | |
Alex Deucher | 66264ba | 2016-09-30 12:37:36 -0400 | [diff] [blame] | 606 | static int dce_virtual_connector_encoder_init(struct amdgpu_device *adev, |
| 607 | int index) |
Emily Deng | 8e6de75 | 2016-08-08 11:31:13 +0800 | [diff] [blame] | 608 | { |
Emily Deng | 8e6de75 | 2016-08-08 11:31:13 +0800 | [diff] [blame] | 609 | struct drm_encoder *encoder; |
Alex Deucher | 66264ba | 2016-09-30 12:37:36 -0400 | [diff] [blame] | 610 | struct drm_connector *connector; |
Emily Deng | 8e6de75 | 2016-08-08 11:31:13 +0800 | [diff] [blame] | 611 | |
Alex Deucher | 66264ba | 2016-09-30 12:37:36 -0400 | [diff] [blame] | 612 | /* add a new encoder */ |
| 613 | encoder = kzalloc(sizeof(struct drm_encoder), GFP_KERNEL); |
| 614 | if (!encoder) |
| 615 | return -ENOMEM; |
| 616 | encoder->possible_crtcs = 1 << index; |
| 617 | drm_encoder_init(adev->ddev, encoder, &dce_virtual_encoder_funcs, |
| 618 | DRM_MODE_ENCODER_VIRTUAL, NULL); |
| 619 | drm_encoder_helper_add(encoder, &dce_virtual_encoder_helper_funcs); |
Emily Deng | 8e6de75 | 2016-08-08 11:31:13 +0800 | [diff] [blame] | 620 | |
Alex Deucher | 66264ba | 2016-09-30 12:37:36 -0400 | [diff] [blame] | 621 | connector = kzalloc(sizeof(struct drm_connector), GFP_KERNEL); |
| 622 | if (!connector) { |
| 623 | kfree(encoder); |
| 624 | return -ENOMEM; |
Emily Deng | 8e6de75 | 2016-08-08 11:31:13 +0800 | [diff] [blame] | 625 | } |
| 626 | |
Alex Deucher | 66264ba | 2016-09-30 12:37:36 -0400 | [diff] [blame] | 627 | /* add a new connector */ |
| 628 | drm_connector_init(adev->ddev, connector, &dce_virtual_connector_funcs, |
| 629 | DRM_MODE_CONNECTOR_VIRTUAL); |
| 630 | drm_connector_helper_add(connector, &dce_virtual_connector_helper_funcs); |
| 631 | connector->display_info.subpixel_order = SubPixelHorizontalRGB; |
| 632 | connector->interlace_allowed = false; |
| 633 | connector->doublescan_allowed = false; |
| 634 | drm_connector_register(connector); |
Emily Deng | 8e6de75 | 2016-08-08 11:31:13 +0800 | [diff] [blame] | 635 | |
Alex Deucher | 66264ba | 2016-09-30 12:37:36 -0400 | [diff] [blame] | 636 | /* link them */ |
| 637 | drm_mode_connector_attach_encoder(connector, encoder); |
Emily Deng | 8e6de75 | 2016-08-08 11:31:13 +0800 | [diff] [blame] | 638 | |
Alex Deucher | 66264ba | 2016-09-30 12:37:36 -0400 | [diff] [blame] | 639 | return 0; |
Emily Deng | 8e6de75 | 2016-08-08 11:31:13 +0800 | [diff] [blame] | 640 | } |
| 641 | |
Emily Deng | c6e14f4 | 2016-08-08 11:30:50 +0800 | [diff] [blame] | 642 | static const struct amdgpu_display_funcs dce_virtual_display_funcs = { |
Emily Deng | 8e6de75 | 2016-08-08 11:31:13 +0800 | [diff] [blame] | 643 | .bandwidth_update = &dce_virtual_bandwidth_update, |
| 644 | .vblank_get_counter = &dce_virtual_vblank_get_counter, |
Emily Deng | c6e14f4 | 2016-08-08 11:30:50 +0800 | [diff] [blame] | 645 | .backlight_set_level = NULL, |
| 646 | .backlight_get_level = NULL, |
Emily Deng | 8e6de75 | 2016-08-08 11:31:13 +0800 | [diff] [blame] | 647 | .hpd_sense = &dce_virtual_hpd_sense, |
| 648 | .hpd_set_polarity = &dce_virtual_hpd_set_polarity, |
| 649 | .hpd_get_gpio_reg = &dce_virtual_hpd_get_gpio_reg, |
| 650 | .page_flip = &dce_virtual_page_flip, |
| 651 | .page_flip_get_scanoutpos = &dce_virtual_crtc_get_scanoutpos, |
Alex Deucher | 66264ba | 2016-09-30 12:37:36 -0400 | [diff] [blame] | 652 | .add_encoder = NULL, |
| 653 | .add_connector = NULL, |
Emily Deng | c6e14f4 | 2016-08-08 11:30:50 +0800 | [diff] [blame] | 654 | }; |
| 655 | |
| 656 | static void dce_virtual_set_display_funcs(struct amdgpu_device *adev) |
| 657 | { |
| 658 | if (adev->mode_info.funcs == NULL) |
| 659 | adev->mode_info.funcs = &dce_virtual_display_funcs; |
| 660 | } |
| 661 | |
Alex Deucher | 9405e47 | 2016-09-30 11:41:37 -0400 | [diff] [blame] | 662 | static int dce_virtual_pageflip(struct amdgpu_device *adev, |
| 663 | unsigned crtc_id) |
| 664 | { |
| 665 | unsigned long flags; |
| 666 | struct amdgpu_crtc *amdgpu_crtc; |
| 667 | struct amdgpu_flip_work *works; |
| 668 | |
| 669 | amdgpu_crtc = adev->mode_info.crtcs[crtc_id]; |
| 670 | |
| 671 | if (crtc_id >= adev->mode_info.num_crtc) { |
| 672 | DRM_ERROR("invalid pageflip crtc %d\n", crtc_id); |
| 673 | return -EINVAL; |
| 674 | } |
| 675 | |
| 676 | /* IRQ could occur when in initial stage */ |
| 677 | if (amdgpu_crtc == NULL) |
| 678 | return 0; |
| 679 | |
| 680 | spin_lock_irqsave(&adev->ddev->event_lock, flags); |
| 681 | works = amdgpu_crtc->pflip_works; |
| 682 | if (amdgpu_crtc->pflip_status != AMDGPU_FLIP_SUBMITTED) { |
| 683 | DRM_DEBUG_DRIVER("amdgpu_crtc->pflip_status = %d != " |
| 684 | "AMDGPU_FLIP_SUBMITTED(%d)\n", |
| 685 | amdgpu_crtc->pflip_status, |
| 686 | AMDGPU_FLIP_SUBMITTED); |
| 687 | spin_unlock_irqrestore(&adev->ddev->event_lock, flags); |
| 688 | return 0; |
| 689 | } |
| 690 | |
| 691 | /* page flip completed. clean up */ |
| 692 | amdgpu_crtc->pflip_status = AMDGPU_FLIP_NONE; |
| 693 | amdgpu_crtc->pflip_works = NULL; |
| 694 | |
| 695 | /* wakeup usersapce */ |
| 696 | if (works->event) |
| 697 | drm_crtc_send_vblank_event(&amdgpu_crtc->base, works->event); |
| 698 | |
| 699 | spin_unlock_irqrestore(&adev->ddev->event_lock, flags); |
| 700 | |
| 701 | drm_crtc_vblank_put(&amdgpu_crtc->base); |
| 702 | schedule_work(&works->unpin_work); |
| 703 | |
| 704 | return 0; |
| 705 | } |
| 706 | |
Emily Deng | 46ac362 | 2016-08-08 11:35:39 +0800 | [diff] [blame] | 707 | static enum hrtimer_restart dce_virtual_vblank_timer_handle(struct hrtimer *vblank_timer) |
| 708 | { |
Emily Deng | 0f66356 | 2016-09-30 13:02:18 -0400 | [diff] [blame] | 709 | struct amdgpu_crtc *amdgpu_crtc = container_of(vblank_timer, |
| 710 | struct amdgpu_crtc, vblank_timer); |
| 711 | struct drm_device *ddev = amdgpu_crtc->base.dev; |
| 712 | struct amdgpu_device *adev = ddev->dev_private; |
Alex Deucher | 9405e47 | 2016-09-30 11:41:37 -0400 | [diff] [blame] | 713 | |
Emily Deng | 0f66356 | 2016-09-30 13:02:18 -0400 | [diff] [blame] | 714 | drm_handle_vblank(ddev, amdgpu_crtc->crtc_id); |
| 715 | dce_virtual_pageflip(adev, amdgpu_crtc->crtc_id); |
Thomas Gleixner | 8b0e195 | 2016-12-25 12:30:41 +0100 | [diff] [blame] | 716 | hrtimer_start(vblank_timer, DCE_VIRTUAL_VBLANK_PERIOD, |
Alex Deucher | 9405e47 | 2016-09-30 11:41:37 -0400 | [diff] [blame] | 717 | HRTIMER_MODE_REL); |
| 718 | |
Emily Deng | 46ac362 | 2016-08-08 11:35:39 +0800 | [diff] [blame] | 719 | return HRTIMER_NORESTART; |
| 720 | } |
| 721 | |
Emily Deng | e13273d | 2016-08-08 11:31:37 +0800 | [diff] [blame] | 722 | static void dce_virtual_set_crtc_vblank_interrupt_state(struct amdgpu_device *adev, |
Alex Deucher | 82b9f81 | 2016-09-30 11:19:41 -0400 | [diff] [blame] | 723 | int crtc, |
| 724 | enum amdgpu_interrupt_state state) |
Emily Deng | e13273d | 2016-08-08 11:31:37 +0800 | [diff] [blame] | 725 | { |
Monk Liu | 129d65c | 2017-11-15 17:10:13 +0800 | [diff] [blame] | 726 | if (crtc >= adev->mode_info.num_crtc || !adev->mode_info.crtcs[crtc]) { |
Emily Deng | e13273d | 2016-08-08 11:31:37 +0800 | [diff] [blame] | 727 | DRM_DEBUG("invalid crtc %d\n", crtc); |
| 728 | return; |
| 729 | } |
Emily Deng | 46ac362 | 2016-08-08 11:35:39 +0800 | [diff] [blame] | 730 | |
Emily Deng | 0f66356 | 2016-09-30 13:02:18 -0400 | [diff] [blame] | 731 | if (state && !adev->mode_info.crtcs[crtc]->vsync_timer_enabled) { |
Emily Deng | 46ac362 | 2016-08-08 11:35:39 +0800 | [diff] [blame] | 732 | DRM_DEBUG("Enable software vsync timer\n"); |
Emily Deng | 0f66356 | 2016-09-30 13:02:18 -0400 | [diff] [blame] | 733 | hrtimer_init(&adev->mode_info.crtcs[crtc]->vblank_timer, |
| 734 | CLOCK_MONOTONIC, HRTIMER_MODE_REL); |
| 735 | hrtimer_set_expires(&adev->mode_info.crtcs[crtc]->vblank_timer, |
Thomas Gleixner | 8b0e195 | 2016-12-25 12:30:41 +0100 | [diff] [blame] | 736 | DCE_VIRTUAL_VBLANK_PERIOD); |
Emily Deng | 0f66356 | 2016-09-30 13:02:18 -0400 | [diff] [blame] | 737 | adev->mode_info.crtcs[crtc]->vblank_timer.function = |
| 738 | dce_virtual_vblank_timer_handle; |
| 739 | hrtimer_start(&adev->mode_info.crtcs[crtc]->vblank_timer, |
Thomas Gleixner | 8b0e195 | 2016-12-25 12:30:41 +0100 | [diff] [blame] | 740 | DCE_VIRTUAL_VBLANK_PERIOD, HRTIMER_MODE_REL); |
Emily Deng | 0f66356 | 2016-09-30 13:02:18 -0400 | [diff] [blame] | 741 | } else if (!state && adev->mode_info.crtcs[crtc]->vsync_timer_enabled) { |
Emily Deng | 46ac362 | 2016-08-08 11:35:39 +0800 | [diff] [blame] | 742 | DRM_DEBUG("Disable software vsync timer\n"); |
Emily Deng | 0f66356 | 2016-09-30 13:02:18 -0400 | [diff] [blame] | 743 | hrtimer_cancel(&adev->mode_info.crtcs[crtc]->vblank_timer); |
Emily Deng | 46ac362 | 2016-08-08 11:35:39 +0800 | [diff] [blame] | 744 | } |
| 745 | |
Emily Deng | 0f66356 | 2016-09-30 13:02:18 -0400 | [diff] [blame] | 746 | adev->mode_info.crtcs[crtc]->vsync_timer_enabled = state; |
Emily Deng | 46ac362 | 2016-08-08 11:35:39 +0800 | [diff] [blame] | 747 | DRM_DEBUG("[FM]set crtc %d vblank interrupt state %d\n", crtc, state); |
Emily Deng | e13273d | 2016-08-08 11:31:37 +0800 | [diff] [blame] | 748 | } |
| 749 | |
Emily Deng | 46ac362 | 2016-08-08 11:35:39 +0800 | [diff] [blame] | 750 | |
Emily Deng | e13273d | 2016-08-08 11:31:37 +0800 | [diff] [blame] | 751 | static int dce_virtual_set_crtc_irq_state(struct amdgpu_device *adev, |
Alex Deucher | 82b9f81 | 2016-09-30 11:19:41 -0400 | [diff] [blame] | 752 | struct amdgpu_irq_src *source, |
| 753 | unsigned type, |
| 754 | enum amdgpu_interrupt_state state) |
Emily Deng | e13273d | 2016-08-08 11:31:37 +0800 | [diff] [blame] | 755 | { |
Emily Deng | 0f66356 | 2016-09-30 13:02:18 -0400 | [diff] [blame] | 756 | if (type > AMDGPU_CRTC_IRQ_VBLANK6) |
| 757 | return -EINVAL; |
| 758 | |
| 759 | dce_virtual_set_crtc_vblank_interrupt_state(adev, type, state); |
| 760 | |
Emily Deng | e13273d | 2016-08-08 11:31:37 +0800 | [diff] [blame] | 761 | return 0; |
| 762 | } |
| 763 | |
Emily Deng | c6e14f4 | 2016-08-08 11:30:50 +0800 | [diff] [blame] | 764 | static const struct amdgpu_irq_src_funcs dce_virtual_crtc_irq_funcs = { |
Emily Deng | e13273d | 2016-08-08 11:31:37 +0800 | [diff] [blame] | 765 | .set = dce_virtual_set_crtc_irq_state, |
Alex Deucher | bf2335a | 2016-09-30 11:23:30 -0400 | [diff] [blame] | 766 | .process = NULL, |
Emily Deng | c6e14f4 | 2016-08-08 11:30:50 +0800 | [diff] [blame] | 767 | }; |
| 768 | |
Emily Deng | c6e14f4 | 2016-08-08 11:30:50 +0800 | [diff] [blame] | 769 | static void dce_virtual_set_irq_funcs(struct amdgpu_device *adev) |
| 770 | { |
Emily Deng | 89a6c2e | 2017-07-25 09:51:13 +0800 | [diff] [blame] | 771 | adev->crtc_irq.num_types = AMDGPU_CRTC_IRQ_VBLANK6 + 1; |
Emily Deng | c6e14f4 | 2016-08-08 11:30:50 +0800 | [diff] [blame] | 772 | adev->crtc_irq.funcs = &dce_virtual_crtc_irq_funcs; |
Emily Deng | c6e14f4 | 2016-08-08 11:30:50 +0800 | [diff] [blame] | 773 | } |
| 774 | |
Alex Deucher | a125510 | 2016-10-13 17:41:13 -0400 | [diff] [blame] | 775 | const struct amdgpu_ip_block_version dce_virtual_ip_block = |
| 776 | { |
| 777 | .type = AMD_IP_BLOCK_TYPE_DCE, |
| 778 | .major = 1, |
| 779 | .minor = 0, |
| 780 | .rev = 0, |
| 781 | .funcs = &dce_virtual_ip_funcs, |
| 782 | }; |