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 | */ |
| 23 | #include "drmP.h" |
| 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" |
Emily Deng | 83c9b02 | 2016-08-08 11:33:11 +0800 | [diff] [blame] | 30 | #ifdef CONFIG_DRM_AMDGPU_CIK |
| 31 | #include "dce_v8_0.h" |
| 32 | #endif |
| 33 | #include "dce_v10_0.h" |
| 34 | #include "dce_v11_0.h" |
Emily Deng | 46ac362 | 2016-08-08 11:35:39 +0800 | [diff] [blame] | 35 | #include "dce_virtual.h" |
Emily Deng | c6e14f4 | 2016-08-08 11:30:50 +0800 | [diff] [blame] | 36 | |
| 37 | static void dce_virtual_set_display_funcs(struct amdgpu_device *adev); |
| 38 | static void dce_virtual_set_irq_funcs(struct amdgpu_device *adev); |
Emily Deng | 6b5084c | 2016-08-08 11:36:07 +0800 | [diff] [blame] | 39 | static int dce_virtual_pageflip_irq(struct amdgpu_device *adev, |
| 40 | struct amdgpu_irq_src *source, |
| 41 | struct amdgpu_iv_entry *entry); |
Emily Deng | c6e14f4 | 2016-08-08 11:30:50 +0800 | [diff] [blame] | 42 | |
Emily Deng | 8e6de75 | 2016-08-08 11:31:13 +0800 | [diff] [blame] | 43 | /** |
| 44 | * dce_virtual_vblank_wait - vblank wait asic callback. |
| 45 | * |
| 46 | * @adev: amdgpu_device pointer |
| 47 | * @crtc: crtc to wait for vblank on |
| 48 | * |
| 49 | * Wait for vblank on the requested crtc (evergreen+). |
| 50 | */ |
| 51 | static void dce_virtual_vblank_wait(struct amdgpu_device *adev, int crtc) |
| 52 | { |
| 53 | return; |
| 54 | } |
| 55 | |
| 56 | static u32 dce_virtual_vblank_get_counter(struct amdgpu_device *adev, int crtc) |
| 57 | { |
| 58 | if (crtc >= adev->mode_info.num_crtc) |
| 59 | return 0; |
| 60 | else |
| 61 | return adev->ddev->vblank[crtc].count; |
| 62 | } |
| 63 | |
| 64 | static void dce_virtual_page_flip(struct amdgpu_device *adev, |
| 65 | int crtc_id, u64 crtc_base, bool async) |
| 66 | { |
| 67 | return; |
| 68 | } |
| 69 | |
| 70 | static int dce_virtual_crtc_get_scanoutpos(struct amdgpu_device *adev, int crtc, |
| 71 | u32 *vbl, u32 *position) |
| 72 | { |
| 73 | if ((crtc < 0) || (crtc >= adev->mode_info.num_crtc)) |
| 74 | return -EINVAL; |
| 75 | |
| 76 | *vbl = 0; |
| 77 | *position = 0; |
| 78 | |
| 79 | return 0; |
| 80 | } |
| 81 | |
| 82 | static bool dce_virtual_hpd_sense(struct amdgpu_device *adev, |
| 83 | enum amdgpu_hpd_id hpd) |
| 84 | { |
| 85 | return true; |
| 86 | } |
| 87 | |
| 88 | static void dce_virtual_hpd_set_polarity(struct amdgpu_device *adev, |
| 89 | enum amdgpu_hpd_id hpd) |
| 90 | { |
| 91 | return; |
| 92 | } |
| 93 | |
| 94 | static u32 dce_virtual_hpd_get_gpio_reg(struct amdgpu_device *adev) |
| 95 | { |
| 96 | return 0; |
| 97 | } |
| 98 | |
| 99 | static bool dce_virtual_is_display_hung(struct amdgpu_device *adev) |
| 100 | { |
| 101 | return false; |
| 102 | } |
| 103 | |
| 104 | void dce_virtual_stop_mc_access(struct amdgpu_device *adev, |
| 105 | struct amdgpu_mode_mc_save *save) |
| 106 | { |
Emily Deng | 83c9b02 | 2016-08-08 11:33:11 +0800 | [diff] [blame] | 107 | switch (adev->asic_type) { |
| 108 | case CHIP_BONAIRE: |
| 109 | case CHIP_HAWAII: |
| 110 | case CHIP_KAVERI: |
| 111 | case CHIP_KABINI: |
| 112 | case CHIP_MULLINS: |
| 113 | #ifdef CONFIG_DRM_AMDGPU_CIK |
| 114 | dce_v8_0_disable_dce(adev); |
| 115 | #endif |
| 116 | break; |
| 117 | case CHIP_FIJI: |
| 118 | case CHIP_TONGA: |
| 119 | dce_v10_0_disable_dce(adev); |
| 120 | break; |
| 121 | case CHIP_CARRIZO: |
| 122 | case CHIP_STONEY: |
| 123 | case CHIP_POLARIS11: |
| 124 | case CHIP_POLARIS10: |
| 125 | dce_v11_0_disable_dce(adev); |
| 126 | break; |
| 127 | default: |
| 128 | DRM_ERROR("Usupported ASIC type: 0x%X\n", adev->asic_type); |
| 129 | } |
| 130 | |
Emily Deng | 8e6de75 | 2016-08-08 11:31:13 +0800 | [diff] [blame] | 131 | return; |
| 132 | } |
| 133 | void dce_virtual_resume_mc_access(struct amdgpu_device *adev, |
| 134 | struct amdgpu_mode_mc_save *save) |
| 135 | { |
| 136 | return; |
| 137 | } |
| 138 | |
| 139 | void dce_virtual_set_vga_render_state(struct amdgpu_device *adev, |
| 140 | bool render) |
| 141 | { |
| 142 | return; |
| 143 | } |
| 144 | |
| 145 | /** |
| 146 | * dce_virtual_bandwidth_update - program display watermarks |
| 147 | * |
| 148 | * @adev: amdgpu_device pointer |
| 149 | * |
| 150 | * Calculate and program the display watermarks and line |
| 151 | * buffer allocation (CIK). |
| 152 | */ |
| 153 | static void dce_virtual_bandwidth_update(struct amdgpu_device *adev) |
| 154 | { |
| 155 | return; |
| 156 | } |
| 157 | |
Emily Deng | 0d43f3b | 2016-08-08 11:32:22 +0800 | [diff] [blame] | 158 | static int dce_virtual_crtc_gamma_set(struct drm_crtc *crtc, u16 *red, |
| 159 | u16 *green, u16 *blue, uint32_t size) |
| 160 | { |
| 161 | struct amdgpu_crtc *amdgpu_crtc = to_amdgpu_crtc(crtc); |
| 162 | int i; |
| 163 | |
| 164 | /* userspace palettes are always correct as is */ |
| 165 | for (i = 0; i < size; i++) { |
| 166 | amdgpu_crtc->lut_r[i] = red[i] >> 6; |
| 167 | amdgpu_crtc->lut_g[i] = green[i] >> 6; |
| 168 | amdgpu_crtc->lut_b[i] = blue[i] >> 6; |
| 169 | } |
| 170 | |
| 171 | return 0; |
| 172 | } |
| 173 | |
| 174 | static void dce_virtual_crtc_destroy(struct drm_crtc *crtc) |
| 175 | { |
| 176 | struct amdgpu_crtc *amdgpu_crtc = to_amdgpu_crtc(crtc); |
| 177 | |
| 178 | drm_crtc_cleanup(crtc); |
| 179 | kfree(amdgpu_crtc); |
| 180 | } |
| 181 | |
Emily Deng | c6e14f4 | 2016-08-08 11:30:50 +0800 | [diff] [blame] | 182 | static const struct drm_crtc_funcs dce_virtual_crtc_funcs = { |
| 183 | .cursor_set2 = NULL, |
| 184 | .cursor_move = NULL, |
Emily Deng | 0d43f3b | 2016-08-08 11:32:22 +0800 | [diff] [blame] | 185 | .gamma_set = dce_virtual_crtc_gamma_set, |
| 186 | .set_config = amdgpu_crtc_set_config, |
| 187 | .destroy = dce_virtual_crtc_destroy, |
| 188 | .page_flip = amdgpu_crtc_page_flip, |
Emily Deng | c6e14f4 | 2016-08-08 11:30:50 +0800 | [diff] [blame] | 189 | }; |
| 190 | |
Emily Deng | f1f5ef926 | 2016-08-08 11:32:00 +0800 | [diff] [blame] | 191 | static void dce_virtual_crtc_dpms(struct drm_crtc *crtc, int mode) |
| 192 | { |
| 193 | struct drm_device *dev = crtc->dev; |
| 194 | struct amdgpu_device *adev = dev->dev_private; |
| 195 | struct amdgpu_crtc *amdgpu_crtc = to_amdgpu_crtc(crtc); |
| 196 | unsigned type; |
| 197 | |
| 198 | switch (mode) { |
| 199 | case DRM_MODE_DPMS_ON: |
| 200 | amdgpu_crtc->enabled = true; |
| 201 | /* Make sure VBLANK and PFLIP interrupts are still enabled */ |
| 202 | type = amdgpu_crtc_idx_to_irq_type(adev, amdgpu_crtc->crtc_id); |
| 203 | amdgpu_irq_update(adev, &adev->crtc_irq, type); |
| 204 | amdgpu_irq_update(adev, &adev->pageflip_irq, type); |
| 205 | drm_vblank_on(dev, amdgpu_crtc->crtc_id); |
| 206 | break; |
| 207 | case DRM_MODE_DPMS_STANDBY: |
| 208 | case DRM_MODE_DPMS_SUSPEND: |
| 209 | case DRM_MODE_DPMS_OFF: |
| 210 | drm_vblank_off(dev, amdgpu_crtc->crtc_id); |
| 211 | amdgpu_crtc->enabled = false; |
| 212 | break; |
| 213 | } |
| 214 | } |
| 215 | |
| 216 | |
| 217 | static void dce_virtual_crtc_prepare(struct drm_crtc *crtc) |
| 218 | { |
| 219 | dce_virtual_crtc_dpms(crtc, DRM_MODE_DPMS_OFF); |
| 220 | } |
| 221 | |
| 222 | static void dce_virtual_crtc_commit(struct drm_crtc *crtc) |
| 223 | { |
| 224 | dce_virtual_crtc_dpms(crtc, DRM_MODE_DPMS_ON); |
| 225 | } |
| 226 | |
| 227 | static void dce_virtual_crtc_disable(struct drm_crtc *crtc) |
| 228 | { |
| 229 | struct amdgpu_crtc *amdgpu_crtc = to_amdgpu_crtc(crtc); |
| 230 | |
| 231 | dce_virtual_crtc_dpms(crtc, DRM_MODE_DPMS_OFF); |
| 232 | if (crtc->primary->fb) { |
| 233 | int r; |
| 234 | struct amdgpu_framebuffer *amdgpu_fb; |
| 235 | struct amdgpu_bo *rbo; |
| 236 | |
| 237 | amdgpu_fb = to_amdgpu_framebuffer(crtc->primary->fb); |
| 238 | rbo = gem_to_amdgpu_bo(amdgpu_fb->obj); |
| 239 | r = amdgpu_bo_reserve(rbo, false); |
| 240 | if (unlikely(r)) |
| 241 | DRM_ERROR("failed to reserve rbo before unpin\n"); |
| 242 | else { |
| 243 | amdgpu_bo_unpin(rbo); |
| 244 | amdgpu_bo_unreserve(rbo); |
| 245 | } |
| 246 | } |
| 247 | |
| 248 | amdgpu_crtc->pll_id = ATOM_PPLL_INVALID; |
| 249 | amdgpu_crtc->encoder = NULL; |
| 250 | amdgpu_crtc->connector = NULL; |
| 251 | } |
| 252 | |
| 253 | static int dce_virtual_crtc_mode_set(struct drm_crtc *crtc, |
| 254 | struct drm_display_mode *mode, |
| 255 | struct drm_display_mode *adjusted_mode, |
| 256 | int x, int y, struct drm_framebuffer *old_fb) |
| 257 | { |
| 258 | struct amdgpu_crtc *amdgpu_crtc = to_amdgpu_crtc(crtc); |
| 259 | |
| 260 | /* update the hw version fpr dpm */ |
| 261 | amdgpu_crtc->hw_mode = *adjusted_mode; |
| 262 | |
| 263 | return 0; |
| 264 | } |
| 265 | |
| 266 | static bool dce_virtual_crtc_mode_fixup(struct drm_crtc *crtc, |
| 267 | const struct drm_display_mode *mode, |
| 268 | struct drm_display_mode *adjusted_mode) |
| 269 | { |
| 270 | struct amdgpu_crtc *amdgpu_crtc = to_amdgpu_crtc(crtc); |
| 271 | struct drm_device *dev = crtc->dev; |
| 272 | struct drm_encoder *encoder; |
| 273 | |
| 274 | /* assign the encoder to the amdgpu crtc to avoid repeated lookups later */ |
| 275 | list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) { |
| 276 | if (encoder->crtc == crtc) { |
| 277 | amdgpu_crtc->encoder = encoder; |
| 278 | amdgpu_crtc->connector = amdgpu_get_connector_for_encoder(encoder); |
| 279 | break; |
| 280 | } |
| 281 | } |
| 282 | if ((amdgpu_crtc->encoder == NULL) || (amdgpu_crtc->connector == NULL)) { |
| 283 | amdgpu_crtc->encoder = NULL; |
| 284 | amdgpu_crtc->connector = NULL; |
| 285 | return false; |
| 286 | } |
| 287 | |
| 288 | return true; |
| 289 | } |
| 290 | |
| 291 | |
| 292 | static int dce_virtual_crtc_set_base(struct drm_crtc *crtc, int x, int y, |
| 293 | struct drm_framebuffer *old_fb) |
| 294 | { |
| 295 | return 0; |
| 296 | } |
| 297 | |
| 298 | static void dce_virtual_crtc_load_lut(struct drm_crtc *crtc) |
| 299 | { |
| 300 | return; |
| 301 | } |
| 302 | |
| 303 | static int dce_virtual_crtc_set_base_atomic(struct drm_crtc *crtc, |
| 304 | struct drm_framebuffer *fb, |
| 305 | int x, int y, enum mode_set_atomic state) |
| 306 | { |
| 307 | return 0; |
| 308 | } |
| 309 | |
Emily Deng | c6e14f4 | 2016-08-08 11:30:50 +0800 | [diff] [blame] | 310 | static const struct drm_crtc_helper_funcs dce_virtual_crtc_helper_funcs = { |
Emily Deng | f1f5ef926 | 2016-08-08 11:32:00 +0800 | [diff] [blame] | 311 | .dpms = dce_virtual_crtc_dpms, |
| 312 | .mode_fixup = dce_virtual_crtc_mode_fixup, |
| 313 | .mode_set = dce_virtual_crtc_mode_set, |
| 314 | .mode_set_base = dce_virtual_crtc_set_base, |
| 315 | .mode_set_base_atomic = dce_virtual_crtc_set_base_atomic, |
| 316 | .prepare = dce_virtual_crtc_prepare, |
| 317 | .commit = dce_virtual_crtc_commit, |
| 318 | .load_lut = dce_virtual_crtc_load_lut, |
| 319 | .disable = dce_virtual_crtc_disable, |
Emily Deng | c6e14f4 | 2016-08-08 11:30:50 +0800 | [diff] [blame] | 320 | }; |
| 321 | |
| 322 | static int dce_virtual_crtc_init(struct amdgpu_device *adev, int index) |
| 323 | { |
| 324 | struct amdgpu_crtc *amdgpu_crtc; |
| 325 | int i; |
| 326 | |
| 327 | amdgpu_crtc = kzalloc(sizeof(struct amdgpu_crtc) + |
| 328 | (AMDGPUFB_CONN_LIMIT * sizeof(struct drm_connector *)), GFP_KERNEL); |
| 329 | if (amdgpu_crtc == NULL) |
| 330 | return -ENOMEM; |
| 331 | |
| 332 | drm_crtc_init(adev->ddev, &amdgpu_crtc->base, &dce_virtual_crtc_funcs); |
| 333 | |
| 334 | drm_mode_crtc_set_gamma_size(&amdgpu_crtc->base, 256); |
| 335 | amdgpu_crtc->crtc_id = index; |
| 336 | adev->mode_info.crtcs[index] = amdgpu_crtc; |
| 337 | |
| 338 | for (i = 0; i < 256; i++) { |
| 339 | amdgpu_crtc->lut_r[i] = i << 2; |
| 340 | amdgpu_crtc->lut_g[i] = i << 2; |
| 341 | amdgpu_crtc->lut_b[i] = i << 2; |
| 342 | } |
| 343 | |
| 344 | amdgpu_crtc->pll_id = ATOM_PPLL_INVALID; |
| 345 | amdgpu_crtc->encoder = NULL; |
| 346 | amdgpu_crtc->connector = NULL; |
| 347 | drm_crtc_helper_add(&amdgpu_crtc->base, &dce_virtual_crtc_helper_funcs); |
| 348 | |
| 349 | return 0; |
| 350 | } |
| 351 | |
| 352 | static int dce_virtual_early_init(void *handle) |
| 353 | { |
| 354 | struct amdgpu_device *adev = (struct amdgpu_device *)handle; |
| 355 | |
Alex Deucher | d06b7e1 | 2016-08-08 14:35:55 -0400 | [diff] [blame^] | 356 | adev->mode_info.vsync_timer_enabled = AMDGPU_IRQ_STATE_DISABLE; |
Emily Deng | c6e14f4 | 2016-08-08 11:30:50 +0800 | [diff] [blame] | 357 | dce_virtual_set_display_funcs(adev); |
| 358 | dce_virtual_set_irq_funcs(adev); |
| 359 | |
| 360 | adev->mode_info.num_crtc = 1; |
| 361 | adev->mode_info.num_hpd = 1; |
| 362 | adev->mode_info.num_dig = 1; |
| 363 | return 0; |
| 364 | } |
| 365 | |
| 366 | static bool dce_virtual_get_connector_info(struct amdgpu_device *adev) |
| 367 | { |
| 368 | struct amdgpu_i2c_bus_rec ddc_bus; |
| 369 | struct amdgpu_router router; |
| 370 | struct amdgpu_hpd hpd; |
| 371 | |
| 372 | /* look up gpio for ddc, hpd */ |
| 373 | ddc_bus.valid = false; |
| 374 | hpd.hpd = AMDGPU_HPD_NONE; |
| 375 | /* needed for aux chan transactions */ |
| 376 | ddc_bus.hpd = hpd.hpd; |
| 377 | |
| 378 | memset(&router, 0, sizeof(router)); |
| 379 | router.ddc_valid = false; |
| 380 | router.cd_valid = false; |
| 381 | amdgpu_display_add_connector(adev, |
| 382 | 0, |
| 383 | ATOM_DEVICE_CRT1_SUPPORT, |
| 384 | DRM_MODE_CONNECTOR_VIRTUAL, &ddc_bus, |
| 385 | CONNECTOR_OBJECT_ID_VIRTUAL, |
| 386 | &hpd, |
| 387 | &router); |
| 388 | |
| 389 | amdgpu_display_add_encoder(adev, ENCODER_VIRTUAL_ENUM_VIRTUAL, |
| 390 | ATOM_DEVICE_CRT1_SUPPORT, |
| 391 | 0); |
| 392 | |
| 393 | amdgpu_link_encoder_connector(adev->ddev); |
| 394 | |
| 395 | return true; |
| 396 | } |
| 397 | |
| 398 | static int dce_virtual_sw_init(void *handle) |
| 399 | { |
| 400 | int r, i; |
| 401 | struct amdgpu_device *adev = (struct amdgpu_device *)handle; |
| 402 | |
| 403 | r = amdgpu_irq_add_id(adev, 229, &adev->crtc_irq); |
| 404 | if (r) |
| 405 | return r; |
| 406 | |
| 407 | adev->ddev->mode_config.funcs = &amdgpu_mode_funcs; |
| 408 | |
| 409 | adev->ddev->mode_config.max_width = 16384; |
| 410 | adev->ddev->mode_config.max_height = 16384; |
| 411 | |
| 412 | adev->ddev->mode_config.preferred_depth = 24; |
| 413 | adev->ddev->mode_config.prefer_shadow = 1; |
| 414 | |
| 415 | adev->ddev->mode_config.fb_base = adev->mc.aper_base; |
| 416 | |
| 417 | r = amdgpu_modeset_create_props(adev); |
| 418 | if (r) |
| 419 | return r; |
| 420 | |
| 421 | adev->ddev->mode_config.max_width = 16384; |
| 422 | adev->ddev->mode_config.max_height = 16384; |
| 423 | |
| 424 | /* allocate crtcs */ |
| 425 | for (i = 0; i < adev->mode_info.num_crtc; i++) { |
| 426 | r = dce_virtual_crtc_init(adev, i); |
| 427 | if (r) |
| 428 | return r; |
| 429 | } |
| 430 | |
| 431 | dce_virtual_get_connector_info(adev); |
| 432 | amdgpu_print_display_setup(adev->ddev); |
| 433 | |
| 434 | drm_kms_helper_poll_init(adev->ddev); |
| 435 | |
| 436 | adev->mode_info.mode_config_initialized = true; |
| 437 | return 0; |
| 438 | } |
| 439 | |
| 440 | static int dce_virtual_sw_fini(void *handle) |
| 441 | { |
| 442 | struct amdgpu_device *adev = (struct amdgpu_device *)handle; |
| 443 | |
| 444 | kfree(adev->mode_info.bios_hardcoded_edid); |
| 445 | |
| 446 | drm_kms_helper_poll_fini(adev->ddev); |
| 447 | |
| 448 | drm_mode_config_cleanup(adev->ddev); |
| 449 | adev->mode_info.mode_config_initialized = false; |
| 450 | return 0; |
| 451 | } |
| 452 | |
| 453 | static int dce_virtual_hw_init(void *handle) |
| 454 | { |
| 455 | return 0; |
| 456 | } |
| 457 | |
| 458 | static int dce_virtual_hw_fini(void *handle) |
| 459 | { |
| 460 | return 0; |
| 461 | } |
| 462 | |
| 463 | static int dce_virtual_suspend(void *handle) |
| 464 | { |
| 465 | return dce_virtual_hw_fini(handle); |
| 466 | } |
| 467 | |
| 468 | static int dce_virtual_resume(void *handle) |
| 469 | { |
| 470 | int ret; |
| 471 | |
| 472 | ret = dce_virtual_hw_init(handle); |
| 473 | |
| 474 | return ret; |
| 475 | } |
| 476 | |
| 477 | static bool dce_virtual_is_idle(void *handle) |
| 478 | { |
| 479 | return true; |
| 480 | } |
| 481 | |
| 482 | static int dce_virtual_wait_for_idle(void *handle) |
| 483 | { |
| 484 | return 0; |
| 485 | } |
| 486 | |
| 487 | static int dce_virtual_soft_reset(void *handle) |
| 488 | { |
| 489 | return 0; |
| 490 | } |
| 491 | |
| 492 | static int dce_virtual_set_clockgating_state(void *handle, |
| 493 | enum amd_clockgating_state state) |
| 494 | { |
| 495 | return 0; |
| 496 | } |
| 497 | |
| 498 | static int dce_virtual_set_powergating_state(void *handle, |
| 499 | enum amd_powergating_state state) |
| 500 | { |
| 501 | return 0; |
| 502 | } |
| 503 | |
| 504 | const struct amd_ip_funcs dce_virtual_ip_funcs = { |
| 505 | .name = "dce_virtual", |
| 506 | .early_init = dce_virtual_early_init, |
| 507 | .late_init = NULL, |
| 508 | .sw_init = dce_virtual_sw_init, |
| 509 | .sw_fini = dce_virtual_sw_fini, |
| 510 | .hw_init = dce_virtual_hw_init, |
| 511 | .hw_fini = dce_virtual_hw_fini, |
| 512 | .suspend = dce_virtual_suspend, |
| 513 | .resume = dce_virtual_resume, |
| 514 | .is_idle = dce_virtual_is_idle, |
| 515 | .wait_for_idle = dce_virtual_wait_for_idle, |
| 516 | .soft_reset = dce_virtual_soft_reset, |
| 517 | .set_clockgating_state = dce_virtual_set_clockgating_state, |
| 518 | .set_powergating_state = dce_virtual_set_powergating_state, |
| 519 | }; |
| 520 | |
Emily Deng | 8e6de75 | 2016-08-08 11:31:13 +0800 | [diff] [blame] | 521 | /* these are handled by the primary encoders */ |
| 522 | static void dce_virtual_encoder_prepare(struct drm_encoder *encoder) |
| 523 | { |
| 524 | return; |
| 525 | } |
| 526 | |
| 527 | static void dce_virtual_encoder_commit(struct drm_encoder *encoder) |
| 528 | { |
| 529 | return; |
| 530 | } |
| 531 | |
| 532 | static void |
| 533 | dce_virtual_encoder_mode_set(struct drm_encoder *encoder, |
| 534 | struct drm_display_mode *mode, |
| 535 | struct drm_display_mode *adjusted_mode) |
| 536 | { |
| 537 | return; |
| 538 | } |
| 539 | |
| 540 | static void dce_virtual_encoder_disable(struct drm_encoder *encoder) |
| 541 | { |
| 542 | return; |
| 543 | } |
| 544 | |
| 545 | static void |
| 546 | dce_virtual_encoder_dpms(struct drm_encoder *encoder, int mode) |
| 547 | { |
| 548 | return; |
| 549 | } |
| 550 | |
| 551 | static bool dce_virtual_encoder_mode_fixup(struct drm_encoder *encoder, |
| 552 | const struct drm_display_mode *mode, |
| 553 | struct drm_display_mode *adjusted_mode) |
| 554 | { |
| 555 | |
| 556 | /* set the active encoder to connector routing */ |
| 557 | amdgpu_encoder_set_active_device(encoder); |
| 558 | |
| 559 | return true; |
| 560 | } |
| 561 | |
| 562 | static const struct drm_encoder_helper_funcs dce_virtual_encoder_helper_funcs = { |
| 563 | .dpms = dce_virtual_encoder_dpms, |
| 564 | .mode_fixup = dce_virtual_encoder_mode_fixup, |
| 565 | .prepare = dce_virtual_encoder_prepare, |
| 566 | .mode_set = dce_virtual_encoder_mode_set, |
| 567 | .commit = dce_virtual_encoder_commit, |
| 568 | .disable = dce_virtual_encoder_disable, |
| 569 | }; |
| 570 | |
| 571 | static void dce_virtual_encoder_destroy(struct drm_encoder *encoder) |
| 572 | { |
| 573 | struct amdgpu_encoder *amdgpu_encoder = to_amdgpu_encoder(encoder); |
| 574 | |
| 575 | kfree(amdgpu_encoder->enc_priv); |
| 576 | drm_encoder_cleanup(encoder); |
| 577 | kfree(amdgpu_encoder); |
| 578 | } |
| 579 | |
| 580 | static const struct drm_encoder_funcs dce_virtual_encoder_funcs = { |
| 581 | .destroy = dce_virtual_encoder_destroy, |
| 582 | }; |
| 583 | |
| 584 | static void dce_virtual_encoder_add(struct amdgpu_device *adev, |
| 585 | uint32_t encoder_enum, |
| 586 | uint32_t supported_device, |
| 587 | u16 caps) |
| 588 | { |
| 589 | struct drm_device *dev = adev->ddev; |
| 590 | struct drm_encoder *encoder; |
| 591 | struct amdgpu_encoder *amdgpu_encoder; |
| 592 | |
| 593 | /* see if we already added it */ |
| 594 | list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) { |
| 595 | amdgpu_encoder = to_amdgpu_encoder(encoder); |
| 596 | if (amdgpu_encoder->encoder_enum == encoder_enum) { |
| 597 | amdgpu_encoder->devices |= supported_device; |
| 598 | return; |
| 599 | } |
| 600 | |
| 601 | } |
| 602 | |
| 603 | /* add a new one */ |
| 604 | amdgpu_encoder = kzalloc(sizeof(struct amdgpu_encoder), GFP_KERNEL); |
| 605 | if (!amdgpu_encoder) |
| 606 | return; |
| 607 | |
| 608 | encoder = &amdgpu_encoder->base; |
| 609 | encoder->possible_crtcs = 0x1; |
| 610 | amdgpu_encoder->enc_priv = NULL; |
| 611 | amdgpu_encoder->encoder_enum = encoder_enum; |
| 612 | amdgpu_encoder->encoder_id = (encoder_enum & OBJECT_ID_MASK) >> OBJECT_ID_SHIFT; |
| 613 | amdgpu_encoder->devices = supported_device; |
| 614 | amdgpu_encoder->rmx_type = RMX_OFF; |
| 615 | amdgpu_encoder->underscan_type = UNDERSCAN_OFF; |
| 616 | amdgpu_encoder->is_ext_encoder = false; |
| 617 | amdgpu_encoder->caps = caps; |
| 618 | |
| 619 | drm_encoder_init(dev, encoder, &dce_virtual_encoder_funcs, |
| 620 | DRM_MODE_ENCODER_VIRTUAL, NULL); |
| 621 | drm_encoder_helper_add(encoder, &dce_virtual_encoder_helper_funcs); |
| 622 | DRM_INFO("[FM]encoder: %d is VIRTUAL\n", amdgpu_encoder->encoder_id); |
| 623 | } |
| 624 | |
Emily Deng | c6e14f4 | 2016-08-08 11:30:50 +0800 | [diff] [blame] | 625 | static const struct amdgpu_display_funcs dce_virtual_display_funcs = { |
Emily Deng | 8e6de75 | 2016-08-08 11:31:13 +0800 | [diff] [blame] | 626 | .set_vga_render_state = &dce_virtual_set_vga_render_state, |
| 627 | .bandwidth_update = &dce_virtual_bandwidth_update, |
| 628 | .vblank_get_counter = &dce_virtual_vblank_get_counter, |
| 629 | .vblank_wait = &dce_virtual_vblank_wait, |
| 630 | .is_display_hung = &dce_virtual_is_display_hung, |
Emily Deng | c6e14f4 | 2016-08-08 11:30:50 +0800 | [diff] [blame] | 631 | .backlight_set_level = NULL, |
| 632 | .backlight_get_level = NULL, |
Emily Deng | 8e6de75 | 2016-08-08 11:31:13 +0800 | [diff] [blame] | 633 | .hpd_sense = &dce_virtual_hpd_sense, |
| 634 | .hpd_set_polarity = &dce_virtual_hpd_set_polarity, |
| 635 | .hpd_get_gpio_reg = &dce_virtual_hpd_get_gpio_reg, |
| 636 | .page_flip = &dce_virtual_page_flip, |
| 637 | .page_flip_get_scanoutpos = &dce_virtual_crtc_get_scanoutpos, |
| 638 | .add_encoder = &dce_virtual_encoder_add, |
Emily Deng | c6e14f4 | 2016-08-08 11:30:50 +0800 | [diff] [blame] | 639 | .add_connector = &amdgpu_connector_add, |
Emily Deng | 8e6de75 | 2016-08-08 11:31:13 +0800 | [diff] [blame] | 640 | .stop_mc_access = &dce_virtual_stop_mc_access, |
| 641 | .resume_mc_access = &dce_virtual_resume_mc_access, |
Emily Deng | c6e14f4 | 2016-08-08 11:30:50 +0800 | [diff] [blame] | 642 | }; |
| 643 | |
| 644 | static void dce_virtual_set_display_funcs(struct amdgpu_device *adev) |
| 645 | { |
| 646 | if (adev->mode_info.funcs == NULL) |
| 647 | adev->mode_info.funcs = &dce_virtual_display_funcs; |
| 648 | } |
| 649 | |
Emily Deng | 46ac362 | 2016-08-08 11:35:39 +0800 | [diff] [blame] | 650 | static enum hrtimer_restart dce_virtual_vblank_timer_handle(struct hrtimer *vblank_timer) |
| 651 | { |
| 652 | struct amdgpu_mode_info *mode_info = container_of(vblank_timer, struct amdgpu_mode_info ,vblank_timer); |
| 653 | struct amdgpu_device *adev = container_of(mode_info, struct amdgpu_device ,mode_info); |
| 654 | unsigned crtc = 0; |
| 655 | adev->ddev->vblank[0].count++; |
| 656 | drm_handle_vblank(adev->ddev, crtc); |
Emily Deng | 6b5084c | 2016-08-08 11:36:07 +0800 | [diff] [blame] | 657 | dce_virtual_pageflip_irq(adev, NULL, NULL); |
Emily Deng | 46ac362 | 2016-08-08 11:35:39 +0800 | [diff] [blame] | 658 | hrtimer_start(vblank_timer, ktime_set(0, DCE_VIRTUAL_VBLANK_PERIOD), HRTIMER_MODE_REL); |
| 659 | return HRTIMER_NORESTART; |
| 660 | } |
| 661 | |
Emily Deng | e13273d | 2016-08-08 11:31:37 +0800 | [diff] [blame] | 662 | static void dce_virtual_set_crtc_vblank_interrupt_state(struct amdgpu_device *adev, |
Emily Deng | 46ac362 | 2016-08-08 11:35:39 +0800 | [diff] [blame] | 663 | int crtc, |
| 664 | enum amdgpu_interrupt_state state) |
Emily Deng | e13273d | 2016-08-08 11:31:37 +0800 | [diff] [blame] | 665 | { |
| 666 | if (crtc >= adev->mode_info.num_crtc) { |
| 667 | DRM_DEBUG("invalid crtc %d\n", crtc); |
| 668 | return; |
| 669 | } |
Emily Deng | 46ac362 | 2016-08-08 11:35:39 +0800 | [diff] [blame] | 670 | |
| 671 | if (state && !adev->mode_info.vsync_timer_enabled) { |
| 672 | DRM_DEBUG("Enable software vsync timer\n"); |
| 673 | hrtimer_init(&adev->mode_info.vblank_timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL); |
| 674 | hrtimer_set_expires(&adev->mode_info.vblank_timer, ktime_set(0, DCE_VIRTUAL_VBLANK_PERIOD)); |
| 675 | adev->mode_info.vblank_timer.function = dce_virtual_vblank_timer_handle; |
| 676 | hrtimer_start(&adev->mode_info.vblank_timer, ktime_set(0, DCE_VIRTUAL_VBLANK_PERIOD), HRTIMER_MODE_REL); |
| 677 | } else if (!state && adev->mode_info.vsync_timer_enabled) { |
| 678 | DRM_DEBUG("Disable software vsync timer\n"); |
| 679 | hrtimer_cancel(&adev->mode_info.vblank_timer); |
| 680 | } |
| 681 | |
| 682 | if (!state || (state && !adev->mode_info.vsync_timer_enabled)) |
| 683 | adev->ddev->vblank[0].count = 0; |
| 684 | adev->mode_info.vsync_timer_enabled = state; |
| 685 | 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] | 686 | } |
| 687 | |
Emily Deng | 46ac362 | 2016-08-08 11:35:39 +0800 | [diff] [blame] | 688 | |
Emily Deng | e13273d | 2016-08-08 11:31:37 +0800 | [diff] [blame] | 689 | static int dce_virtual_set_crtc_irq_state(struct amdgpu_device *adev, |
| 690 | struct amdgpu_irq_src *source, |
| 691 | unsigned type, |
| 692 | enum amdgpu_interrupt_state state) |
| 693 | { |
| 694 | switch (type) { |
| 695 | case AMDGPU_CRTC_IRQ_VBLANK1: |
| 696 | dce_virtual_set_crtc_vblank_interrupt_state(adev, 0, state); |
| 697 | break; |
| 698 | default: |
| 699 | break; |
| 700 | } |
| 701 | return 0; |
| 702 | } |
| 703 | |
| 704 | static void dce_virtual_crtc_vblank_int_ack(struct amdgpu_device *adev, |
| 705 | int crtc) |
| 706 | { |
| 707 | if (crtc >= adev->mode_info.num_crtc) { |
| 708 | DRM_DEBUG("invalid crtc %d\n", crtc); |
| 709 | return; |
| 710 | } |
| 711 | } |
| 712 | |
| 713 | static int dce_virtual_crtc_irq(struct amdgpu_device *adev, |
Emily Deng | 6b5084c | 2016-08-08 11:36:07 +0800 | [diff] [blame] | 714 | struct amdgpu_irq_src *source, |
| 715 | struct amdgpu_iv_entry *entry) |
Emily Deng | e13273d | 2016-08-08 11:31:37 +0800 | [diff] [blame] | 716 | { |
| 717 | unsigned crtc = 0; |
| 718 | unsigned irq_type = AMDGPU_CRTC_IRQ_VBLANK1; |
| 719 | |
| 720 | adev->ddev->vblank[crtc].count++; |
| 721 | dce_virtual_crtc_vblank_int_ack(adev, crtc); |
| 722 | |
| 723 | if (amdgpu_irq_enabled(adev, source, irq_type)) { |
| 724 | drm_handle_vblank(adev->ddev, crtc); |
| 725 | } |
Emily Deng | 6b5084c | 2016-08-08 11:36:07 +0800 | [diff] [blame] | 726 | dce_virtual_pageflip_irq(adev, NULL, NULL); |
Emily Deng | e13273d | 2016-08-08 11:31:37 +0800 | [diff] [blame] | 727 | DRM_DEBUG("IH: D%d vblank\n", crtc + 1); |
| 728 | return 0; |
| 729 | } |
| 730 | |
| 731 | static int dce_virtual_set_pageflip_irq_state(struct amdgpu_device *adev, |
| 732 | struct amdgpu_irq_src *src, |
| 733 | unsigned type, |
| 734 | enum amdgpu_interrupt_state state) |
| 735 | { |
| 736 | if (type >= adev->mode_info.num_crtc) { |
| 737 | DRM_ERROR("invalid pageflip crtc %d\n", type); |
| 738 | return -EINVAL; |
| 739 | } |
| 740 | DRM_DEBUG("[FM]set pageflip irq type %d state %d\n", type, state); |
| 741 | |
| 742 | return 0; |
| 743 | } |
| 744 | |
| 745 | static int dce_virtual_pageflip_irq(struct amdgpu_device *adev, |
| 746 | struct amdgpu_irq_src *source, |
| 747 | struct amdgpu_iv_entry *entry) |
| 748 | { |
| 749 | unsigned long flags; |
| 750 | unsigned crtc_id = 0; |
| 751 | struct amdgpu_crtc *amdgpu_crtc; |
| 752 | struct amdgpu_flip_work *works; |
| 753 | |
| 754 | crtc_id = 0; |
| 755 | amdgpu_crtc = adev->mode_info.crtcs[crtc_id]; |
| 756 | |
| 757 | if (crtc_id >= adev->mode_info.num_crtc) { |
| 758 | DRM_ERROR("invalid pageflip crtc %d\n", crtc_id); |
| 759 | return -EINVAL; |
| 760 | } |
| 761 | |
| 762 | /* IRQ could occur when in initial stage */ |
| 763 | if (amdgpu_crtc == NULL) |
| 764 | return 0; |
| 765 | |
| 766 | spin_lock_irqsave(&adev->ddev->event_lock, flags); |
| 767 | works = amdgpu_crtc->pflip_works; |
| 768 | if (amdgpu_crtc->pflip_status != AMDGPU_FLIP_SUBMITTED) { |
| 769 | DRM_DEBUG_DRIVER("amdgpu_crtc->pflip_status = %d != " |
| 770 | "AMDGPU_FLIP_SUBMITTED(%d)\n", |
| 771 | amdgpu_crtc->pflip_status, |
| 772 | AMDGPU_FLIP_SUBMITTED); |
| 773 | spin_unlock_irqrestore(&adev->ddev->event_lock, flags); |
| 774 | return 0; |
| 775 | } |
| 776 | |
| 777 | /* page flip completed. clean up */ |
| 778 | amdgpu_crtc->pflip_status = AMDGPU_FLIP_NONE; |
| 779 | amdgpu_crtc->pflip_works = NULL; |
| 780 | |
| 781 | /* wakeup usersapce */ |
| 782 | if (works->event) |
| 783 | drm_crtc_send_vblank_event(&amdgpu_crtc->base, works->event); |
| 784 | |
| 785 | spin_unlock_irqrestore(&adev->ddev->event_lock, flags); |
| 786 | |
| 787 | drm_crtc_vblank_put(&amdgpu_crtc->base); |
| 788 | schedule_work(&works->unpin_work); |
| 789 | |
| 790 | return 0; |
| 791 | } |
| 792 | |
Emily Deng | c6e14f4 | 2016-08-08 11:30:50 +0800 | [diff] [blame] | 793 | static const struct amdgpu_irq_src_funcs dce_virtual_crtc_irq_funcs = { |
Emily Deng | e13273d | 2016-08-08 11:31:37 +0800 | [diff] [blame] | 794 | .set = dce_virtual_set_crtc_irq_state, |
| 795 | .process = dce_virtual_crtc_irq, |
Emily Deng | c6e14f4 | 2016-08-08 11:30:50 +0800 | [diff] [blame] | 796 | }; |
| 797 | |
| 798 | static const struct amdgpu_irq_src_funcs dce_virtual_pageflip_irq_funcs = { |
Emily Deng | e13273d | 2016-08-08 11:31:37 +0800 | [diff] [blame] | 799 | .set = dce_virtual_set_pageflip_irq_state, |
| 800 | .process = dce_virtual_pageflip_irq, |
Emily Deng | c6e14f4 | 2016-08-08 11:30:50 +0800 | [diff] [blame] | 801 | }; |
| 802 | |
| 803 | static void dce_virtual_set_irq_funcs(struct amdgpu_device *adev) |
| 804 | { |
| 805 | adev->crtc_irq.num_types = AMDGPU_CRTC_IRQ_LAST; |
| 806 | adev->crtc_irq.funcs = &dce_virtual_crtc_irq_funcs; |
| 807 | |
| 808 | adev->pageflip_irq.num_types = AMDGPU_PAGEFLIP_IRQ_LAST; |
| 809 | adev->pageflip_irq.funcs = &dce_virtual_pageflip_irq_funcs; |
Emily Deng | c6e14f4 | 2016-08-08 11:30:50 +0800 | [diff] [blame] | 810 | } |
| 811 | |