Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge tag 'drm-misc-next-2017-06-02' of git://anongit.freedesktop.org/git/drm-misc into drm-next

Core Changes:
- Stop proliferation of drm_vblank_cleanup by adding to the docs and deleting
boilerplate (Daniel)
- Roll out and use mode_valid hooks across crtc/encoder/bridge (Jose)
- Add drm_vblank.[hc] to isolate vblank code from optional irq helpers (Daniel)

Driver Changes:
- Replace drm_for_each_connector with drm_for_each_connector_iter (Gustavo)
- A couple misc driver fixes

Cc: Gustavo Padovan <gustavo.padovan@collabora.com>
Cc: Jose Abreu <Jose.Abreu@synopsys.com>
Cc: Daniel Vetter <daniel.vetter@intel.com>

* tag 'drm-misc-next-2017-06-02' of git://anongit.freedesktop.org/git/drm-misc: (34 commits)
drm/vc4: Mark the device as active when enabling runtime PM.
drm: remove writeq/readq function definitions
drm/atmel-hlcdc: Use crtc->mode_valid() callback
drm/exynos: Drop drm_vblank_cleanup
drm/hdlcd|mali: Drop drm_vblank_cleanup
drm/doc: Polish irq helper documentation
drm: Extract drm_vblank.[hc]
drm/vc4: Fix comment in vc4_drv.h
drm/pl111: fix warnings without CONFIG_ARM_AMBA
drm/atomic: Consitfy mode parameter to drm_atomic_set_mode_for_crtc()
drm/arcgpu: Drop drm_vblank_cleanup
drm/atmel: Drop drm_vblank_cleanup
drm/imx: Drop drm_vblank_cleanup
drm/meson: Drop drm_vblank_cleanup
drm/stm: Drop drm_vblank_cleanup
drm/sun4i: Drop drm_vblank_cleanup
drm: better document how to send out the crtc disable event
drm: Use vsnprintf extension %ph
drm/doc: move printf helpers out of drmP.h
drm/pl111: select DRM_PANEL
...

+2275 -1984
+6 -51
Documentation/gpu/drm-internals.rst
··· 149 149 Driver Load 150 150 ----------- 151 151 152 - IRQ Registration 153 - ~~~~~~~~~~~~~~~~ 154 152 155 - The DRM core tries to facilitate IRQ handler registration and 156 - unregistration by providing :c:func:`drm_irq_install()` and 157 - :c:func:`drm_irq_uninstall()` functions. Those functions only 158 - support a single interrupt per device, devices that use more than one 159 - IRQs need to be handled manually. 153 + IRQ Helper Library 154 + ~~~~~~~~~~~~~~~~~~ 160 155 161 - Managed IRQ Registration 162 - '''''''''''''''''''''''' 156 + .. kernel-doc:: drivers/gpu/drm/drm_irq.c 157 + :doc: irq helpers 163 158 164 - :c:func:`drm_irq_install()` starts by calling the irq_preinstall 165 - driver operation. The operation is optional and must make sure that the 166 - interrupt will not get fired by clearing all pending interrupt flags or 167 - disabling the interrupt. 168 - 169 - The passed-in IRQ will then be requested by a call to 170 - :c:func:`request_irq()`. If the DRIVER_IRQ_SHARED driver feature 171 - flag is set, a shared (IRQF_SHARED) IRQ handler will be requested. 172 - 173 - The IRQ handler function must be provided as the mandatory irq_handler 174 - driver operation. It will get passed directly to 175 - :c:func:`request_irq()` and thus has the same prototype as all IRQ 176 - handlers. It will get called with a pointer to the DRM device as the 177 - second argument. 178 - 179 - Finally the function calls the optional irq_postinstall driver 180 - operation. The operation usually enables interrupts (excluding the 181 - vblank interrupt, which is enabled separately), but drivers may choose 182 - to enable/disable interrupts at a different time. 183 - 184 - :c:func:`drm_irq_uninstall()` is similarly used to uninstall an 185 - IRQ handler. It starts by waking up all processes waiting on a vblank 186 - interrupt to make sure they don't hang, and then calls the optional 187 - irq_uninstall driver operation. The operation must disable all hardware 188 - interrupts. Finally the function frees the IRQ by calling 189 - :c:func:`free_irq()`. 190 - 191 - Manual IRQ Registration 192 - ''''''''''''''''''''''' 193 - 194 - Drivers that require multiple interrupt handlers can't use the managed 195 - IRQ registration functions. In that case IRQs must be registered and 196 - unregistered manually (usually with the :c:func:`request_irq()` and 197 - :c:func:`free_irq()` functions, or their :c:func:`devm_request_irq()` and 198 - :c:func:`devm_free_irq()` equivalents). 199 - 200 - When manually registering IRQs, drivers must not set the 201 - DRIVER_HAVE_IRQ driver feature flag, and must not provide the 202 - irq_handler driver operation. They must set the :c:type:`struct 203 - drm_device <drm_device>` irq_enabled field to 1 upon 204 - registration of the IRQs, and clear it to 0 after unregistering the 205 - IRQs. 159 + .. kernel-doc:: drivers/gpu/drm/drm_irq.c 160 + :export: 206 161 207 162 Memory Manager Initialization 208 163 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+2 -2
Documentation/gpu/drm-kms.rst
··· 612 612 Vertical Blanking and Interrupt Handling Functions Reference 613 613 ------------------------------------------------------------ 614 614 615 - .. kernel-doc:: include/drm/drm_irq.h 615 + .. kernel-doc:: include/drm/drm_vblank.h 616 616 :internal: 617 617 618 - .. kernel-doc:: drivers/gpu/drm/drm_irq.c 618 + .. kernel-doc:: drivers/gpu/drm/drm_vblank.c 619 619 :export:
-13
Documentation/gpu/todo.rst
··· 177 177 178 178 Contact: Daniel Vetter, respective driver maintainers 179 179 180 - Switch to drm_connector_list_iter for any connector_list walking 181 - ---------------------------------------------------------------- 182 - 183 - Connectors can be hotplugged, and we now have a special list of helpers to walk 184 - the connector_list in a race-free fashion, without incurring deadlocks on 185 - mutexes and other fun stuff. 186 - 187 - Unfortunately most drivers are not converted yet. At least all those supporting 188 - DP MST hotplug should be converted, since for those drivers the difference 189 - matters. See drm_for_each_connector_iter() vs. drm_for_each_connector(). 190 - 191 - Contact: Daniel Vetter 192 - 193 180 Core refactorings 194 181 ================= 195 182
+1 -1
drivers/gpu/drm/Makefile
··· 16 16 drm_framebuffer.o drm_connector.o drm_blend.o \ 17 17 drm_encoder.o drm_mode_object.o drm_property.o \ 18 18 drm_plane.o drm_color_mgmt.o drm_print.o \ 19 - drm_dumb_buffers.o drm_mode_config.o 19 + drm_dumb_buffers.o drm_mode_config.o drm_vblank.o 20 20 21 21 drm-$(CONFIG_DRM_LIB_RANDOM) += lib/drm_random.o 22 22 drm-$(CONFIG_DRM_VM) += drm_vm.o
-1
drivers/gpu/drm/arc/arcpgu_drv.c
··· 155 155 arcpgu->fbdev = NULL; 156 156 } 157 157 drm_kms_helper_poll_fini(drm); 158 - drm_vblank_cleanup(drm); 159 158 drm_mode_config_cleanup(drm); 160 159 161 160 return 0;
-2
drivers/gpu/drm/arm/hdlcd_drv.c
··· 340 340 } 341 341 err_fbdev: 342 342 drm_kms_helper_poll_fini(drm); 343 - drm_vblank_cleanup(drm); 344 343 err_vblank: 345 344 pm_runtime_disable(drm->dev); 346 345 err_pm_active: ··· 367 368 } 368 369 drm_kms_helper_poll_fini(drm); 369 370 component_unbind_all(dev, drm); 370 - drm_vblank_cleanup(drm); 371 371 pm_runtime_get_sync(drm->dev); 372 372 drm_irq_uninstall(drm); 373 373 pm_runtime_put_sync(drm->dev);
-2
drivers/gpu/drm/arm/malidp_drv.c
··· 652 652 drm_kms_helper_poll_fini(drm); 653 653 fbdev_fail: 654 654 pm_runtime_get_sync(dev); 655 - drm_vblank_cleanup(drm); 656 655 vblank_fail: 657 656 malidp_se_irq_fini(drm); 658 657 malidp_de_irq_fini(drm); ··· 691 692 } 692 693 drm_kms_helper_poll_fini(drm); 693 694 pm_runtime_get_sync(dev); 694 - drm_vblank_cleanup(drm); 695 695 malidp_se_irq_fini(drm); 696 696 malidp_de_irq_fini(drm); 697 697 component_unbind_all(dev, drm);
+5 -5
drivers/gpu/drm/atmel-hlcdc/atmel_hlcdc_crtc.c
··· 140 140 cfg); 141 141 } 142 142 143 - static bool atmel_hlcdc_crtc_mode_fixup(struct drm_crtc *c, 144 - const struct drm_display_mode *mode, 145 - struct drm_display_mode *adjusted_mode) 143 + static enum drm_mode_status 144 + atmel_hlcdc_crtc_mode_valid(struct drm_crtc *c, 145 + const struct drm_display_mode *mode) 146 146 { 147 147 struct atmel_hlcdc_crtc *crtc = drm_crtc_to_atmel_hlcdc_crtc(c); 148 148 149 - return atmel_hlcdc_dc_mode_valid(crtc->dc, adjusted_mode) == MODE_OK; 149 + return atmel_hlcdc_dc_mode_valid(crtc->dc, mode); 150 150 } 151 151 152 152 static void atmel_hlcdc_crtc_disable(struct drm_crtc *c) ··· 315 315 } 316 316 317 317 static const struct drm_crtc_helper_funcs lcdc_crtc_helper_funcs = { 318 - .mode_fixup = atmel_hlcdc_crtc_mode_fixup, 318 + .mode_valid = atmel_hlcdc_crtc_mode_valid, 319 319 .mode_set = drm_helper_crtc_mode_set, 320 320 .mode_set_nofb = atmel_hlcdc_crtc_mode_set_nofb, 321 321 .mode_set_base = drm_helper_crtc_mode_set_base,
+3 -3
drivers/gpu/drm/atmel-hlcdc/atmel_hlcdc_dc.c
··· 375 375 }; 376 376 MODULE_DEVICE_TABLE(of, atmel_hlcdc_of_match); 377 377 378 - int atmel_hlcdc_dc_mode_valid(struct atmel_hlcdc_dc *dc, 379 - struct drm_display_mode *mode) 378 + enum drm_mode_status 379 + atmel_hlcdc_dc_mode_valid(struct atmel_hlcdc_dc *dc, 380 + const struct drm_display_mode *mode) 380 381 { 381 382 int vfront_porch = mode->vsync_start - mode->vdisplay; 382 383 int vback_porch = mode->vtotal - mode->vsync_end; ··· 679 678 flush_workqueue(dc->wq); 680 679 drm_kms_helper_poll_fini(dev); 681 680 drm_mode_config_cleanup(dev); 682 - drm_vblank_cleanup(dev); 683 681 684 682 pm_runtime_get_sync(dev->dev); 685 683 drm_irq_uninstall(dev);
+3 -2
drivers/gpu/drm/atmel-hlcdc/atmel_hlcdc_dc.h
··· 422 422 layer->regmap = regmap; 423 423 } 424 424 425 - int atmel_hlcdc_dc_mode_valid(struct atmel_hlcdc_dc *dc, 426 - struct drm_display_mode *mode); 425 + enum drm_mode_status 426 + atmel_hlcdc_dc_mode_valid(struct atmel_hlcdc_dc *dc, 427 + const struct drm_display_mode *mode); 427 428 428 429 int atmel_hlcdc_create_planes(struct drm_device *dev); 429 430 void atmel_hlcdc_plane_irq(struct atmel_hlcdc_plane *plane);
+7 -7
drivers/gpu/drm/bridge/analogix-anx78xx.c
··· 1061 1061 return 0; 1062 1062 } 1063 1063 1064 - static bool anx78xx_bridge_mode_fixup(struct drm_bridge *bridge, 1065 - const struct drm_display_mode *mode, 1066 - struct drm_display_mode *adjusted_mode) 1064 + static enum drm_mode_status 1065 + anx78xx_bridge_mode_valid(struct drm_bridge *bridge, 1066 + const struct drm_display_mode *mode) 1067 1067 { 1068 1068 if (mode->flags & DRM_MODE_FLAG_INTERLACE) 1069 - return false; 1069 + return MODE_NO_INTERLACE; 1070 1070 1071 1071 /* Max 1200p at 5.4 Ghz, one lane */ 1072 1072 if (mode->clock > 154000) 1073 - return false; 1073 + return MODE_CLOCK_HIGH; 1074 1074 1075 - return true; 1075 + return MODE_OK; 1076 1076 } 1077 1077 1078 1078 static void anx78xx_bridge_disable(struct drm_bridge *bridge) ··· 1129 1129 1130 1130 static const struct drm_bridge_funcs anx78xx_bridge_funcs = { 1131 1131 .attach = anx78xx_bridge_attach, 1132 - .mode_fixup = anx78xx_bridge_mode_fixup, 1132 + .mode_valid = anx78xx_bridge_mode_valid, 1133 1133 .disable = anx78xx_bridge_disable, 1134 1134 .mode_set = anx78xx_bridge_mode_set, 1135 1135 .enable = anx78xx_bridge_enable,
+1 -1
drivers/gpu/drm/drm_atomic.c
··· 328 328 * Zero on success, error code on failure. Cannot return -EDEADLK. 329 329 */ 330 330 int drm_atomic_set_mode_for_crtc(struct drm_crtc_state *state, 331 - struct drm_display_mode *mode) 331 + const struct drm_display_mode *mode) 332 332 { 333 333 struct drm_mode_modeinfo umode; 334 334
+73 -3
drivers/gpu/drm/drm_atomic_helper.c
··· 32 32 #include <drm/drm_atomic_helper.h> 33 33 #include <linux/dma-fence.h> 34 34 35 + #include "drm_crtc_helper_internal.h" 35 36 #include "drm_crtc_internal.h" 36 37 37 38 /** ··· 453 452 return 0; 454 453 } 455 454 455 + static enum drm_mode_status mode_valid_path(struct drm_connector *connector, 456 + struct drm_encoder *encoder, 457 + struct drm_crtc *crtc, 458 + struct drm_display_mode *mode) 459 + { 460 + enum drm_mode_status ret; 461 + 462 + ret = drm_encoder_mode_valid(encoder, mode); 463 + if (ret != MODE_OK) { 464 + DRM_DEBUG_ATOMIC("[ENCODER:%d:%s] mode_valid() failed\n", 465 + encoder->base.id, encoder->name); 466 + return ret; 467 + } 468 + 469 + ret = drm_bridge_mode_valid(encoder->bridge, mode); 470 + if (ret != MODE_OK) { 471 + DRM_DEBUG_ATOMIC("[BRIDGE] mode_valid() failed\n"); 472 + return ret; 473 + } 474 + 475 + ret = drm_crtc_mode_valid(crtc, mode); 476 + if (ret != MODE_OK) { 477 + DRM_DEBUG_ATOMIC("[CRTC:%d:%s] mode_valid() failed\n", 478 + crtc->base.id, crtc->name); 479 + return ret; 480 + } 481 + 482 + return ret; 483 + } 484 + 485 + static int 486 + mode_valid(struct drm_atomic_state *state) 487 + { 488 + struct drm_connector_state *conn_state; 489 + struct drm_connector *connector; 490 + int i; 491 + 492 + for_each_new_connector_in_state(state, connector, conn_state, i) { 493 + struct drm_encoder *encoder = conn_state->best_encoder; 494 + struct drm_crtc *crtc = conn_state->crtc; 495 + struct drm_crtc_state *crtc_state; 496 + enum drm_mode_status mode_status; 497 + struct drm_display_mode *mode; 498 + 499 + if (!crtc || !encoder) 500 + continue; 501 + 502 + crtc_state = drm_atomic_get_new_crtc_state(state, crtc); 503 + if (!crtc_state) 504 + continue; 505 + if (!crtc_state->mode_changed && !crtc_state->connectors_changed) 506 + continue; 507 + 508 + mode = &crtc_state->mode; 509 + 510 + mode_status = mode_valid_path(connector, encoder, crtc, mode); 511 + if (mode_status != MODE_OK) 512 + return -EINVAL; 513 + } 514 + 515 + return 0; 516 + } 517 + 456 518 /** 457 519 * drm_atomic_helper_check_modeset - validate state object for modeset changes 458 520 * @dev: DRM device ··· 530 466 * 2. &drm_connector_helper_funcs.atomic_check to validate the connector state. 531 467 * 3. If it's determined a modeset is needed then all connectors on the affected crtc 532 468 * crtc are added and &drm_connector_helper_funcs.atomic_check is run on them. 533 - * 4. &drm_bridge_funcs.mode_fixup is called on all encoder bridges. 534 - * 5. &drm_encoder_helper_funcs.atomic_check is called to validate any encoder state. 469 + * 4. &drm_encoder_helper_funcs.mode_valid, &drm_bridge_funcs.mode_valid and 470 + * &drm_crtc_helper_funcs.mode_valid are called on the affected components. 471 + * 5. &drm_bridge_funcs.mode_fixup is called on all encoder bridges. 472 + * 6. &drm_encoder_helper_funcs.atomic_check is called to validate any encoder state. 535 473 * This function is only called when the encoder will be part of a configured crtc, 536 474 * it must not be used for implementing connector property validation. 537 475 * If this function is NULL, &drm_atomic_encoder_helper_funcs.mode_fixup is called 538 476 * instead. 539 - * 6. &drm_crtc_helper_funcs.mode_fixup is called last, to fix up the mode with crtc constraints. 477 + * 7. &drm_crtc_helper_funcs.mode_fixup is called last, to fix up the mode with crtc constraints. 540 478 * 541 479 * &drm_crtc_state.mode_changed is set when the input mode is changed. 542 480 * &drm_crtc_state.connectors_changed is set when a connector is added or ··· 682 616 if (ret) 683 617 return ret; 684 618 } 619 + 620 + ret = mode_valid(state); 621 + if (ret) 622 + return ret; 685 623 686 624 return mode_fixup(state); 687 625 }
+33
drivers/gpu/drm/drm_bridge.c
··· 206 206 EXPORT_SYMBOL(drm_bridge_mode_fixup); 207 207 208 208 /** 209 + * drm_bridge_mode_valid - validate the mode against all bridges in the 210 + * encoder chain. 211 + * @bridge: bridge control structure 212 + * @mode: desired mode to be validated 213 + * 214 + * Calls &drm_bridge_funcs.mode_valid for all the bridges in the encoder 215 + * chain, starting from the first bridge to the last. If at least one bridge 216 + * does not accept the mode the function returns the error code. 217 + * 218 + * Note: the bridge passed should be the one closest to the encoder. 219 + * 220 + * RETURNS: 221 + * MODE_OK on success, drm_mode_status Enum error code on failure 222 + */ 223 + enum drm_mode_status drm_bridge_mode_valid(struct drm_bridge *bridge, 224 + const struct drm_display_mode *mode) 225 + { 226 + enum drm_mode_status ret = MODE_OK; 227 + 228 + if (!bridge) 229 + return ret; 230 + 231 + if (bridge->funcs->mode_valid) 232 + ret = bridge->funcs->mode_valid(bridge, mode); 233 + 234 + if (ret != MODE_OK) 235 + return ret; 236 + 237 + return drm_bridge_mode_valid(bridge->next, mode); 238 + } 239 + EXPORT_SYMBOL(drm_bridge_mode_valid); 240 + 241 + /** 209 242 * drm_bridge_disable - disables all bridges in the encoder chain 210 243 * @bridge: bridge control structure 211 244 *
+12
drivers/gpu/drm/drm_crtc_helper_internal.h
··· 26 26 * implementation details and are not exported to drivers. 27 27 */ 28 28 29 + #include <drm/drm_connector.h> 30 + #include <drm/drm_crtc.h> 29 31 #include <drm/drm_dp_helper.h> 32 + #include <drm/drm_encoder.h> 33 + #include <drm/drm_modes.h> 30 34 31 35 /* drm_fb_helper.c */ 32 36 #ifdef CONFIG_DRM_FBDEV_EMULATION ··· 67 63 { 68 64 } 69 65 #endif 66 + 67 + /* drm_probe_helper.c */ 68 + enum drm_mode_status drm_crtc_mode_valid(struct drm_crtc *crtc, 69 + const struct drm_display_mode *mode); 70 + enum drm_mode_status drm_encoder_mode_valid(struct drm_encoder *encoder, 71 + const struct drm_display_mode *mode); 72 + enum drm_mode_status drm_connector_mode_valid(struct drm_connector *connector, 73 + struct drm_display_mode *mode);
+16 -35
drivers/gpu/drm/drm_dp_mst_topology.c
··· 2836 2836 static bool dump_dp_payload_table(struct drm_dp_mst_topology_mgr *mgr, 2837 2837 char *buf) 2838 2838 { 2839 - int ret; 2840 2839 int i; 2841 - for (i = 0; i < 4; i++) { 2842 - ret = drm_dp_dpcd_read(mgr->aux, DP_PAYLOAD_TABLE_UPDATE_STATUS + (i * 16), &buf[i * 16], 16); 2843 - if (ret != 16) 2844 - break; 2840 + 2841 + for (i = 0; i < 64; i += 16) { 2842 + if (drm_dp_dpcd_read(mgr->aux, 2843 + DP_PAYLOAD_TABLE_UPDATE_STATUS + i, 2844 + &buf[i], 16) != 16) 2845 + return false; 2845 2846 } 2846 - if (i == 4) 2847 - return true; 2848 - return false; 2847 + return true; 2849 2848 } 2850 2849 2851 2850 static void fetch_monitor_name(struct drm_dp_mst_topology_mgr *mgr, ··· 2908 2909 mutex_lock(&mgr->lock); 2909 2910 if (mgr->mst_primary) { 2910 2911 u8 buf[64]; 2911 - bool bret; 2912 2912 int ret; 2913 + 2913 2914 ret = drm_dp_dpcd_read(mgr->aux, DP_DPCD_REV, buf, DP_RECEIVER_CAP_SIZE); 2914 - seq_printf(m, "dpcd: "); 2915 - for (i = 0; i < DP_RECEIVER_CAP_SIZE; i++) 2916 - seq_printf(m, "%02x ", buf[i]); 2917 - seq_printf(m, "\n"); 2915 + seq_printf(m, "dpcd: %*ph\n", DP_RECEIVER_CAP_SIZE, buf); 2918 2916 ret = drm_dp_dpcd_read(mgr->aux, DP_FAUX_CAP, buf, 2); 2919 - seq_printf(m, "faux/mst: "); 2920 - for (i = 0; i < 2; i++) 2921 - seq_printf(m, "%02x ", buf[i]); 2922 - seq_printf(m, "\n"); 2917 + seq_printf(m, "faux/mst: %*ph\n", 2, buf); 2923 2918 ret = drm_dp_dpcd_read(mgr->aux, DP_MSTM_CTRL, buf, 1); 2924 - seq_printf(m, "mst ctrl: "); 2925 - for (i = 0; i < 1; i++) 2926 - seq_printf(m, "%02x ", buf[i]); 2927 - seq_printf(m, "\n"); 2919 + seq_printf(m, "mst ctrl: %*ph\n", 1, buf); 2928 2920 2929 2921 /* dump the standard OUI branch header */ 2930 2922 ret = drm_dp_dpcd_read(mgr->aux, DP_BRANCH_OUI, buf, DP_BRANCH_OUI_HEADER_SIZE); 2931 - seq_printf(m, "branch oui: "); 2932 - for (i = 0; i < 0x3; i++) 2933 - seq_printf(m, "%02x", buf[i]); 2934 - seq_printf(m, " devid: "); 2923 + seq_printf(m, "branch oui: %*phN devid: ", 3, buf); 2935 2924 for (i = 0x3; i < 0x8 && buf[i]; i++) 2936 2925 seq_printf(m, "%c", buf[i]); 2937 - 2938 - seq_printf(m, " revision: hw: %x.%x sw: %x.%x", buf[0x9] >> 4, buf[0x9] & 0xf, buf[0xa], buf[0xb]); 2939 - seq_printf(m, "\n"); 2940 - bret = dump_dp_payload_table(mgr, buf); 2941 - if (bret == true) { 2942 - seq_printf(m, "payload table: "); 2943 - for (i = 0; i < 63; i++) 2944 - seq_printf(m, "%02x ", buf[i]); 2945 - seq_printf(m, "\n"); 2946 - } 2926 + seq_printf(m, " revision: hw: %x.%x sw: %x.%x\n", 2927 + buf[0x9] >> 4, buf[0x9] & 0xf, buf[0xa], buf[0xb]); 2928 + if (dump_dp_payload_table(mgr, buf)) 2929 + seq_printf(m, "payload table: %*ph\n", 63, buf); 2947 2930 2948 2931 } 2949 2932
+2 -1
drivers/gpu/drm/drm_internal.h
··· 53 53 int drm_clients_info(struct seq_file *m, void* data); 54 54 int drm_gem_name_info(struct seq_file *m, void *data); 55 55 56 - /* drm_irq.c */ 56 + /* drm_vblank.c */ 57 57 extern unsigned int drm_timestamp_monotonic; 58 + void drm_vblank_disable_and_save(struct drm_device *dev, unsigned int pipe); 58 59 59 60 /* IOCTLS */ 60 61 int drm_wait_vblank(struct drm_device *dev, void *data,
+42 -1601
drivers/gpu/drm/drm_irq.c
··· 3 3 * 4 4 * \author Rickard E. (Rik) Faith <faith@valinux.com> 5 5 * \author Gareth Hughes <gareth@valinux.com> 6 + * 7 + * Permission is hereby granted, free of charge, to any person obtaining a 8 + * copy of this software and associated documentation files (the "Software"), 9 + * to deal in the Software without restriction, including without limitation 10 + * the rights to use, copy, modify, merge, publish, distribute, sublicense, 11 + * and/or sell copies of the Software, and to permit persons to whom the 12 + * Software is furnished to do so, subject to the following conditions: 13 + * 14 + * The above copyright notice and this permission notice (including the next 15 + * paragraph) shall be included in all copies or substantial portions of the 16 + * Software. 17 + * 18 + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 21 + * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR 22 + * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 23 + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 24 + * OTHER DEALINGS IN THE SOFTWARE. 6 25 */ 7 26 8 27 /* ··· 51 32 * OTHER DEALINGS IN THE SOFTWARE. 52 33 */ 53 34 35 + #include <drm/drm_irq.h> 54 36 #include <drm/drmP.h> 55 - #include "drm_trace.h" 56 - #include "drm_internal.h" 57 37 58 38 #include <linux/interrupt.h> /* For task queue support */ 59 - #include <linux/slab.h> 60 39 61 40 #include <linux/vgaarb.h> 62 41 #include <linux/export.h> 63 42 64 - /* Retry timestamp calculation up to 3 times to satisfy 65 - * drm_timestamp_precision before giving up. 66 - */ 67 - #define DRM_TIMESTAMP_MAXRETRIES 3 68 - 69 - /* Threshold in nanoseconds for detection of redundant 70 - * vblank irq in drm_handle_vblank(). 1 msec should be ok. 71 - */ 72 - #define DRM_REDUNDANT_VBLIRQ_THRESH_NS 1000000 73 - 74 - static bool 75 - drm_get_last_vbltimestamp(struct drm_device *dev, unsigned int pipe, 76 - struct timeval *tvblank, bool in_vblank_irq); 77 - 78 - static unsigned int drm_timestamp_precision = 20; /* Default to 20 usecs. */ 79 - 80 - /* 81 - * Default to use monotonic timestamps for wait-for-vblank and page-flip 82 - * complete events. 83 - */ 84 - unsigned int drm_timestamp_monotonic = 1; 85 - 86 - static int drm_vblank_offdelay = 5000; /* Default to 5000 msecs. */ 87 - 88 - module_param_named(vblankoffdelay, drm_vblank_offdelay, int, 0600); 89 - module_param_named(timestamp_precision_usec, drm_timestamp_precision, int, 0600); 90 - module_param_named(timestamp_monotonic, drm_timestamp_monotonic, int, 0600); 91 - MODULE_PARM_DESC(vblankoffdelay, "Delay until vblank irq auto-disable [msecs] (0: never disable, <0: disable immediately)"); 92 - MODULE_PARM_DESC(timestamp_precision_usec, "Max. error on timestamps [usecs]"); 93 - MODULE_PARM_DESC(timestamp_monotonic, "Use monotonic timestamps"); 94 - 95 - static void store_vblank(struct drm_device *dev, unsigned int pipe, 96 - u32 vblank_count_inc, 97 - struct timeval *t_vblank, u32 last) 98 - { 99 - struct drm_vblank_crtc *vblank = &dev->vblank[pipe]; 100 - 101 - assert_spin_locked(&dev->vblank_time_lock); 102 - 103 - vblank->last = last; 104 - 105 - write_seqlock(&vblank->seqlock); 106 - vblank->time = *t_vblank; 107 - vblank->count += vblank_count_inc; 108 - write_sequnlock(&vblank->seqlock); 109 - } 110 - 111 - /* 112 - * "No hw counter" fallback implementation of .get_vblank_counter() hook, 113 - * if there is no useable hardware frame counter available. 114 - */ 115 - static u32 drm_vblank_no_hw_counter(struct drm_device *dev, unsigned int pipe) 116 - { 117 - WARN_ON_ONCE(dev->max_vblank_count != 0); 118 - return 0; 119 - } 120 - 121 - static u32 __get_vblank_counter(struct drm_device *dev, unsigned int pipe) 122 - { 123 - if (drm_core_check_feature(dev, DRIVER_MODESET)) { 124 - struct drm_crtc *crtc = drm_crtc_from_index(dev, pipe); 125 - 126 - if (crtc->funcs->get_vblank_counter) 127 - return crtc->funcs->get_vblank_counter(crtc); 128 - } 129 - 130 - if (dev->driver->get_vblank_counter) 131 - return dev->driver->get_vblank_counter(dev, pipe); 132 - 133 - return drm_vblank_no_hw_counter(dev, pipe); 134 - } 135 - 136 - /* 137 - * Reset the stored timestamp for the current vblank count to correspond 138 - * to the last vblank occurred. 139 - * 140 - * Only to be called from drm_crtc_vblank_on(). 141 - * 142 - * Note: caller must hold &drm_device.vbl_lock since this reads & writes 143 - * device vblank fields. 144 - */ 145 - static void drm_reset_vblank_timestamp(struct drm_device *dev, unsigned int pipe) 146 - { 147 - u32 cur_vblank; 148 - bool rc; 149 - struct timeval t_vblank; 150 - int count = DRM_TIMESTAMP_MAXRETRIES; 151 - 152 - spin_lock(&dev->vblank_time_lock); 153 - 154 - /* 155 - * sample the current counter to avoid random jumps 156 - * when drm_vblank_enable() applies the diff 157 - */ 158 - do { 159 - cur_vblank = __get_vblank_counter(dev, pipe); 160 - rc = drm_get_last_vbltimestamp(dev, pipe, &t_vblank, false); 161 - } while (cur_vblank != __get_vblank_counter(dev, pipe) && --count > 0); 162 - 163 - /* 164 - * Only reinitialize corresponding vblank timestamp if high-precision query 165 - * available and didn't fail. Otherwise reinitialize delayed at next vblank 166 - * interrupt and assign 0 for now, to mark the vblanktimestamp as invalid. 167 - */ 168 - if (!rc) 169 - t_vblank = (struct timeval) {0, 0}; 170 - 171 - /* 172 - * +1 to make sure user will never see the same 173 - * vblank counter value before and after a modeset 174 - */ 175 - store_vblank(dev, pipe, 1, &t_vblank, cur_vblank); 176 - 177 - spin_unlock(&dev->vblank_time_lock); 178 - } 179 - 180 - /* 181 - * Call back into the driver to update the appropriate vblank counter 182 - * (specified by @pipe). Deal with wraparound, if it occurred, and 183 - * update the last read value so we can deal with wraparound on the next 184 - * call if necessary. 185 - * 186 - * Only necessary when going from off->on, to account for frames we 187 - * didn't get an interrupt for. 188 - * 189 - * Note: caller must hold &drm_device.vbl_lock since this reads & writes 190 - * device vblank fields. 191 - */ 192 - static void drm_update_vblank_count(struct drm_device *dev, unsigned int pipe, 193 - bool in_vblank_irq) 194 - { 195 - struct drm_vblank_crtc *vblank = &dev->vblank[pipe]; 196 - u32 cur_vblank, diff; 197 - bool rc; 198 - struct timeval t_vblank; 199 - int count = DRM_TIMESTAMP_MAXRETRIES; 200 - int framedur_ns = vblank->framedur_ns; 201 - 202 - /* 203 - * Interrupts were disabled prior to this call, so deal with counter 204 - * wrap if needed. 205 - * NOTE! It's possible we lost a full dev->max_vblank_count + 1 events 206 - * here if the register is small or we had vblank interrupts off for 207 - * a long time. 208 - * 209 - * We repeat the hardware vblank counter & timestamp query until 210 - * we get consistent results. This to prevent races between gpu 211 - * updating its hardware counter while we are retrieving the 212 - * corresponding vblank timestamp. 213 - */ 214 - do { 215 - cur_vblank = __get_vblank_counter(dev, pipe); 216 - rc = drm_get_last_vbltimestamp(dev, pipe, &t_vblank, in_vblank_irq); 217 - } while (cur_vblank != __get_vblank_counter(dev, pipe) && --count > 0); 218 - 219 - if (dev->max_vblank_count != 0) { 220 - /* trust the hw counter when it's around */ 221 - diff = (cur_vblank - vblank->last) & dev->max_vblank_count; 222 - } else if (rc && framedur_ns) { 223 - const struct timeval *t_old; 224 - u64 diff_ns; 225 - 226 - t_old = &vblank->time; 227 - diff_ns = timeval_to_ns(&t_vblank) - timeval_to_ns(t_old); 228 - 229 - /* 230 - * Figure out how many vblanks we've missed based 231 - * on the difference in the timestamps and the 232 - * frame/field duration. 233 - */ 234 - diff = DIV_ROUND_CLOSEST_ULL(diff_ns, framedur_ns); 235 - 236 - if (diff == 0 && in_vblank_irq) 237 - DRM_DEBUG_VBL("crtc %u: Redundant vblirq ignored." 238 - " diff_ns = %lld, framedur_ns = %d)\n", 239 - pipe, (long long) diff_ns, framedur_ns); 240 - } else { 241 - /* some kind of default for drivers w/o accurate vbl timestamping */ 242 - diff = in_vblank_irq ? 1 : 0; 243 - } 244 - 245 - /* 246 - * Within a drm_vblank_pre_modeset - drm_vblank_post_modeset 247 - * interval? If so then vblank irqs keep running and it will likely 248 - * happen that the hardware vblank counter is not trustworthy as it 249 - * might reset at some point in that interval and vblank timestamps 250 - * are not trustworthy either in that interval. Iow. this can result 251 - * in a bogus diff >> 1 which must be avoided as it would cause 252 - * random large forward jumps of the software vblank counter. 253 - */ 254 - if (diff > 1 && (vblank->inmodeset & 0x2)) { 255 - DRM_DEBUG_VBL("clamping vblank bump to 1 on crtc %u: diffr=%u" 256 - " due to pre-modeset.\n", pipe, diff); 257 - diff = 1; 258 - } 259 - 260 - DRM_DEBUG_VBL("updating vblank count on crtc %u:" 261 - " current=%u, diff=%u, hw=%u hw_last=%u\n", 262 - pipe, vblank->count, diff, cur_vblank, vblank->last); 263 - 264 - if (diff == 0) { 265 - WARN_ON_ONCE(cur_vblank != vblank->last); 266 - return; 267 - } 268 - 269 - /* 270 - * Only reinitialize corresponding vblank timestamp if high-precision query 271 - * available and didn't fail, or we were called from the vblank interrupt. 272 - * Otherwise reinitialize delayed at next vblank interrupt and assign 0 273 - * for now, to mark the vblanktimestamp as invalid. 274 - */ 275 - if (!rc && in_vblank_irq) 276 - t_vblank = (struct timeval) {0, 0}; 277 - 278 - store_vblank(dev, pipe, diff, &t_vblank, cur_vblank); 279 - } 280 - 281 - static u32 drm_vblank_count(struct drm_device *dev, unsigned int pipe) 282 - { 283 - struct drm_vblank_crtc *vblank = &dev->vblank[pipe]; 284 - 285 - if (WARN_ON(pipe >= dev->num_crtcs)) 286 - return 0; 287 - 288 - return vblank->count; 289 - } 43 + #include "drm_internal.h" 290 44 291 45 /** 292 - * drm_accurate_vblank_count - retrieve the master vblank counter 293 - * @crtc: which counter to retrieve 46 + * DOC: irq helpers 294 47 * 295 - * This function is similar to @drm_crtc_vblank_count but this 296 - * function interpolates to handle a race with vblank irq's. 48 + * The DRM core provides very simple support helpers to enable IRQ handling on a 49 + * device through the drm_irq_install() and drm_irq_uninstall() functions. This 50 + * only supports devices with a single interrupt on the main device stored in 51 + * &drm_device.dev and set as the device paramter in drm_dev_alloc(). 297 52 * 298 - * This is mostly useful for hardware that can obtain the scanout 299 - * position, but doesn't have a frame counter. 53 + * These IRQ helpers are strictly optional. Drivers which roll their own only 54 + * need to set &drm_device.irq_enabled to signal the DRM core that vblank 55 + * interrupts are working. Since these helpers don't automatically clean up the 56 + * requested interrupt like e.g. devm_request_irq() they're not really 57 + * recommended. 300 58 */ 301 - u32 drm_accurate_vblank_count(struct drm_crtc *crtc) 302 - { 303 - struct drm_device *dev = crtc->dev; 304 - unsigned int pipe = drm_crtc_index(crtc); 305 - u32 vblank; 306 - unsigned long flags; 307 - 308 - WARN(!dev->driver->get_vblank_timestamp, 309 - "This function requires support for accurate vblank timestamps."); 310 - 311 - spin_lock_irqsave(&dev->vblank_time_lock, flags); 312 - 313 - drm_update_vblank_count(dev, pipe, false); 314 - vblank = drm_vblank_count(dev, pipe); 315 - 316 - spin_unlock_irqrestore(&dev->vblank_time_lock, flags); 317 - 318 - return vblank; 319 - } 320 - EXPORT_SYMBOL(drm_accurate_vblank_count); 321 - 322 - static void __disable_vblank(struct drm_device *dev, unsigned int pipe) 323 - { 324 - if (drm_core_check_feature(dev, DRIVER_MODESET)) { 325 - struct drm_crtc *crtc = drm_crtc_from_index(dev, pipe); 326 - 327 - if (crtc->funcs->disable_vblank) { 328 - crtc->funcs->disable_vblank(crtc); 329 - return; 330 - } 331 - } 332 - 333 - dev->driver->disable_vblank(dev, pipe); 334 - } 335 - 336 - /* 337 - * Disable vblank irq's on crtc, make sure that last vblank count 338 - * of hardware and corresponding consistent software vblank counter 339 - * are preserved, even if there are any spurious vblank irq's after 340 - * disable. 341 - */ 342 - static void vblank_disable_and_save(struct drm_device *dev, unsigned int pipe) 343 - { 344 - struct drm_vblank_crtc *vblank = &dev->vblank[pipe]; 345 - unsigned long irqflags; 346 - 347 - assert_spin_locked(&dev->vbl_lock); 348 - 349 - /* Prevent vblank irq processing while disabling vblank irqs, 350 - * so no updates of timestamps or count can happen after we've 351 - * disabled. Needed to prevent races in case of delayed irq's. 352 - */ 353 - spin_lock_irqsave(&dev->vblank_time_lock, irqflags); 354 - 355 - /* 356 - * Only disable vblank interrupts if they're enabled. This avoids 357 - * calling the ->disable_vblank() operation in atomic context with the 358 - * hardware potentially runtime suspended. 359 - */ 360 - if (vblank->enabled) { 361 - __disable_vblank(dev, pipe); 362 - vblank->enabled = false; 363 - } 364 - 365 - /* 366 - * Always update the count and timestamp to maintain the 367 - * appearance that the counter has been ticking all along until 368 - * this time. This makes the count account for the entire time 369 - * between drm_crtc_vblank_on() and drm_crtc_vblank_off(). 370 - */ 371 - drm_update_vblank_count(dev, pipe, false); 372 - 373 - spin_unlock_irqrestore(&dev->vblank_time_lock, irqflags); 374 - } 375 - 376 - static void vblank_disable_fn(unsigned long arg) 377 - { 378 - struct drm_vblank_crtc *vblank = (void *)arg; 379 - struct drm_device *dev = vblank->dev; 380 - unsigned int pipe = vblank->pipe; 381 - unsigned long irqflags; 382 - 383 - spin_lock_irqsave(&dev->vbl_lock, irqflags); 384 - if (atomic_read(&vblank->refcount) == 0 && vblank->enabled) { 385 - DRM_DEBUG("disabling vblank on crtc %u\n", pipe); 386 - vblank_disable_and_save(dev, pipe); 387 - } 388 - spin_unlock_irqrestore(&dev->vbl_lock, irqflags); 389 - } 390 - 391 - /** 392 - * drm_vblank_cleanup - cleanup vblank support 393 - * @dev: DRM device 394 - * 395 - * This function cleans up any resources allocated in drm_vblank_init. 396 - */ 397 - void drm_vblank_cleanup(struct drm_device *dev) 398 - { 399 - unsigned int pipe; 400 - 401 - /* Bail if the driver didn't call drm_vblank_init() */ 402 - if (dev->num_crtcs == 0) 403 - return; 404 - 405 - for (pipe = 0; pipe < dev->num_crtcs; pipe++) { 406 - struct drm_vblank_crtc *vblank = &dev->vblank[pipe]; 407 - 408 - WARN_ON(READ_ONCE(vblank->enabled) && 409 - drm_core_check_feature(dev, DRIVER_MODESET)); 410 - 411 - del_timer_sync(&vblank->disable_timer); 412 - } 413 - 414 - kfree(dev->vblank); 415 - 416 - dev->num_crtcs = 0; 417 - } 418 - EXPORT_SYMBOL(drm_vblank_cleanup); 419 - 420 - /** 421 - * drm_vblank_init - initialize vblank support 422 - * @dev: DRM device 423 - * @num_crtcs: number of CRTCs supported by @dev 424 - * 425 - * This function initializes vblank support for @num_crtcs display pipelines. 426 - * 427 - * Returns: 428 - * Zero on success or a negative error code on failure. 429 - */ 430 - int drm_vblank_init(struct drm_device *dev, unsigned int num_crtcs) 431 - { 432 - int ret = -ENOMEM; 433 - unsigned int i; 434 - 435 - spin_lock_init(&dev->vbl_lock); 436 - spin_lock_init(&dev->vblank_time_lock); 437 - 438 - dev->num_crtcs = num_crtcs; 439 - 440 - dev->vblank = kcalloc(num_crtcs, sizeof(*dev->vblank), GFP_KERNEL); 441 - if (!dev->vblank) 442 - goto err; 443 - 444 - for (i = 0; i < num_crtcs; i++) { 445 - struct drm_vblank_crtc *vblank = &dev->vblank[i]; 446 - 447 - vblank->dev = dev; 448 - vblank->pipe = i; 449 - init_waitqueue_head(&vblank->queue); 450 - setup_timer(&vblank->disable_timer, vblank_disable_fn, 451 - (unsigned long)vblank); 452 - seqlock_init(&vblank->seqlock); 453 - } 454 - 455 - DRM_INFO("Supports vblank timestamp caching Rev 2 (21.10.2013).\n"); 456 - 457 - /* Driver specific high-precision vblank timestamping supported? */ 458 - if (dev->driver->get_vblank_timestamp) 459 - DRM_INFO("Driver supports precise vblank timestamp query.\n"); 460 - else 461 - DRM_INFO("No driver support for vblank timestamp query.\n"); 462 - 463 - /* Must have precise timestamping for reliable vblank instant disable */ 464 - if (dev->vblank_disable_immediate && !dev->driver->get_vblank_timestamp) { 465 - dev->vblank_disable_immediate = false; 466 - DRM_INFO("Setting vblank_disable_immediate to false because " 467 - "get_vblank_timestamp == NULL\n"); 468 - } 469 - 470 - return 0; 471 - 472 - err: 473 - dev->num_crtcs = 0; 474 - return ret; 475 - } 476 - EXPORT_SYMBOL(drm_vblank_init); 477 59 478 60 /** 479 61 * drm_irq_install - install IRQ handler ··· 82 462 * @irq: IRQ number to install the handler for 83 463 * 84 464 * Initializes the IRQ related data. Installs the handler, calling the driver 85 - * irq_preinstall() and irq_postinstall() functions before and after the 86 - * installation. 465 + * &drm_driver.irq_preinstall and &drm_driver.irq_postinstall functions before 466 + * and after the installation. 87 467 * 88 468 * This is the simplified helper interface provided for drivers with no special 89 469 * needs. Drivers which need to install interrupt handlers for multiple 90 470 * interrupts must instead set &drm_device.irq_enabled to signal the DRM core 91 471 * that vblank interrupts are available. 472 + * 473 + * @irq must match the interrupt number that would be passed to request_irq(), 474 + * if called directly instead of using this helper function. 475 + * 476 + * &drm_driver.irq_handler is called to handle the registered interrupt. 92 477 * 93 478 * Returns: 94 479 * Zero on success or a negative error code on failure. ··· 156 531 * drm_irq_uninstall - uninstall the IRQ handler 157 532 * @dev: DRM device 158 533 * 159 - * Calls the driver's irq_uninstall() function and unregisters the IRQ handler. 160 - * This should only be called by drivers which used drm_irq_install() to set up 161 - * their interrupt handler. Other drivers must only reset 534 + * Calls the driver's &drm_driver.irq_uninstall function and unregisters the IRQ 535 + * handler. This should only be called by drivers which used drm_irq_install() 536 + * to set up their interrupt handler. Other drivers must only reset 162 537 * &drm_device.irq_enabled to false. 163 538 * 164 539 * Note that for kernel modesetting drivers it is a bug if this function fails. ··· 196 571 197 572 WARN_ON(drm_core_check_feature(dev, DRIVER_MODESET)); 198 573 199 - vblank_disable_and_save(dev, i); 574 + drm_vblank_disable_and_save(dev, i); 200 575 wake_up(&vblank->queue); 201 576 } 202 577 spin_unlock_irqrestore(&dev->vbl_lock, irqflags); ··· 259 634 return -EINVAL; 260 635 } 261 636 } 262 - 263 - /** 264 - * drm_calc_timestamping_constants - calculate vblank timestamp constants 265 - * @crtc: drm_crtc whose timestamp constants should be updated. 266 - * @mode: display mode containing the scanout timings 267 - * 268 - * Calculate and store various constants which are later 269 - * needed by vblank and swap-completion timestamping, e.g, 270 - * by drm_calc_vbltimestamp_from_scanoutpos(). They are 271 - * derived from CRTC's true scanout timing, so they take 272 - * things like panel scaling or other adjustments into account. 273 - */ 274 - void drm_calc_timestamping_constants(struct drm_crtc *crtc, 275 - const struct drm_display_mode *mode) 276 - { 277 - struct drm_device *dev = crtc->dev; 278 - unsigned int pipe = drm_crtc_index(crtc); 279 - struct drm_vblank_crtc *vblank = &dev->vblank[pipe]; 280 - int linedur_ns = 0, framedur_ns = 0; 281 - int dotclock = mode->crtc_clock; 282 - 283 - if (!dev->num_crtcs) 284 - return; 285 - 286 - if (WARN_ON(pipe >= dev->num_crtcs)) 287 - return; 288 - 289 - /* Valid dotclock? */ 290 - if (dotclock > 0) { 291 - int frame_size = mode->crtc_htotal * mode->crtc_vtotal; 292 - 293 - /* 294 - * Convert scanline length in pixels and video 295 - * dot clock to line duration and frame duration 296 - * in nanoseconds: 297 - */ 298 - linedur_ns = div_u64((u64) mode->crtc_htotal * 1000000, dotclock); 299 - framedur_ns = div_u64((u64) frame_size * 1000000, dotclock); 300 - 301 - /* 302 - * Fields of interlaced scanout modes are only half a frame duration. 303 - */ 304 - if (mode->flags & DRM_MODE_FLAG_INTERLACE) 305 - framedur_ns /= 2; 306 - } else 307 - DRM_ERROR("crtc %u: Can't calculate constants, dotclock = 0!\n", 308 - crtc->base.id); 309 - 310 - vblank->linedur_ns = linedur_ns; 311 - vblank->framedur_ns = framedur_ns; 312 - vblank->hwmode = *mode; 313 - 314 - DRM_DEBUG("crtc %u: hwmode: htotal %d, vtotal %d, vdisplay %d\n", 315 - crtc->base.id, mode->crtc_htotal, 316 - mode->crtc_vtotal, mode->crtc_vdisplay); 317 - DRM_DEBUG("crtc %u: clock %d kHz framedur %d linedur %d\n", 318 - crtc->base.id, dotclock, framedur_ns, linedur_ns); 319 - } 320 - EXPORT_SYMBOL(drm_calc_timestamping_constants); 321 - 322 - /** 323 - * drm_calc_vbltimestamp_from_scanoutpos - precise vblank timestamp helper 324 - * @dev: DRM device 325 - * @pipe: index of CRTC whose vblank timestamp to retrieve 326 - * @max_error: Desired maximum allowable error in timestamps (nanosecs) 327 - * On return contains true maximum error of timestamp 328 - * @vblank_time: Pointer to struct timeval which should receive the timestamp 329 - * @in_vblank_irq: 330 - * True when called from drm_crtc_handle_vblank(). Some drivers 331 - * need to apply some workarounds for gpu-specific vblank irq quirks 332 - * if flag is set. 333 - * 334 - * Implements calculation of exact vblank timestamps from given drm_display_mode 335 - * timings and current video scanout position of a CRTC. This can be called from 336 - * within get_vblank_timestamp() implementation of a kms driver to implement the 337 - * actual timestamping. 338 - * 339 - * Should return timestamps conforming to the OML_sync_control OpenML 340 - * extension specification. The timestamp corresponds to the end of 341 - * the vblank interval, aka start of scanout of topmost-leftmost display 342 - * pixel in the following video frame. 343 - * 344 - * Requires support for optional dev->driver->get_scanout_position() 345 - * in kms driver, plus a bit of setup code to provide a drm_display_mode 346 - * that corresponds to the true scanout timing. 347 - * 348 - * The current implementation only handles standard video modes. It 349 - * returns as no operation if a doublescan or interlaced video mode is 350 - * active. Higher level code is expected to handle this. 351 - * 352 - * This function can be used to implement the &drm_driver.get_vblank_timestamp 353 - * directly, if the driver implements the &drm_driver.get_scanout_position hook. 354 - * 355 - * Note that atomic drivers must call drm_calc_timestamping_constants() before 356 - * enabling a CRTC. The atomic helpers already take care of that in 357 - * drm_atomic_helper_update_legacy_modeset_state(). 358 - * 359 - * Returns: 360 - * 361 - * Returns true on success, and false on failure, i.e. when no accurate 362 - * timestamp could be acquired. 363 - */ 364 - bool drm_calc_vbltimestamp_from_scanoutpos(struct drm_device *dev, 365 - unsigned int pipe, 366 - int *max_error, 367 - struct timeval *vblank_time, 368 - bool in_vblank_irq) 369 - { 370 - struct timeval tv_etime; 371 - ktime_t stime, etime; 372 - bool vbl_status; 373 - struct drm_crtc *crtc; 374 - const struct drm_display_mode *mode; 375 - struct drm_vblank_crtc *vblank = &dev->vblank[pipe]; 376 - int vpos, hpos, i; 377 - int delta_ns, duration_ns; 378 - 379 - if (!drm_core_check_feature(dev, DRIVER_MODESET)) 380 - return false; 381 - 382 - crtc = drm_crtc_from_index(dev, pipe); 383 - 384 - if (pipe >= dev->num_crtcs || !crtc) { 385 - DRM_ERROR("Invalid crtc %u\n", pipe); 386 - return false; 387 - } 388 - 389 - /* Scanout position query not supported? Should not happen. */ 390 - if (!dev->driver->get_scanout_position) { 391 - DRM_ERROR("Called from driver w/o get_scanout_position()!?\n"); 392 - return false; 393 - } 394 - 395 - if (drm_drv_uses_atomic_modeset(dev)) 396 - mode = &vblank->hwmode; 397 - else 398 - mode = &crtc->hwmode; 399 - 400 - /* If mode timing undefined, just return as no-op: 401 - * Happens during initial modesetting of a crtc. 402 - */ 403 - if (mode->crtc_clock == 0) { 404 - DRM_DEBUG("crtc %u: Noop due to uninitialized mode.\n", pipe); 405 - WARN_ON_ONCE(drm_drv_uses_atomic_modeset(dev)); 406 - 407 - return false; 408 - } 409 - 410 - /* Get current scanout position with system timestamp. 411 - * Repeat query up to DRM_TIMESTAMP_MAXRETRIES times 412 - * if single query takes longer than max_error nanoseconds. 413 - * 414 - * This guarantees a tight bound on maximum error if 415 - * code gets preempted or delayed for some reason. 416 - */ 417 - for (i = 0; i < DRM_TIMESTAMP_MAXRETRIES; i++) { 418 - /* 419 - * Get vertical and horizontal scanout position vpos, hpos, 420 - * and bounding timestamps stime, etime, pre/post query. 421 - */ 422 - vbl_status = dev->driver->get_scanout_position(dev, pipe, 423 - in_vblank_irq, 424 - &vpos, &hpos, 425 - &stime, &etime, 426 - mode); 427 - 428 - /* Return as no-op if scanout query unsupported or failed. */ 429 - if (!vbl_status) { 430 - DRM_DEBUG("crtc %u : scanoutpos query failed.\n", 431 - pipe); 432 - return false; 433 - } 434 - 435 - /* Compute uncertainty in timestamp of scanout position query. */ 436 - duration_ns = ktime_to_ns(etime) - ktime_to_ns(stime); 437 - 438 - /* Accept result with < max_error nsecs timing uncertainty. */ 439 - if (duration_ns <= *max_error) 440 - break; 441 - } 442 - 443 - /* Noisy system timing? */ 444 - if (i == DRM_TIMESTAMP_MAXRETRIES) { 445 - DRM_DEBUG("crtc %u: Noisy timestamp %d us > %d us [%d reps].\n", 446 - pipe, duration_ns/1000, *max_error/1000, i); 447 - } 448 - 449 - /* Return upper bound of timestamp precision error. */ 450 - *max_error = duration_ns; 451 - 452 - /* Convert scanout position into elapsed time at raw_time query 453 - * since start of scanout at first display scanline. delta_ns 454 - * can be negative if start of scanout hasn't happened yet. 455 - */ 456 - delta_ns = div_s64(1000000LL * (vpos * mode->crtc_htotal + hpos), 457 - mode->crtc_clock); 458 - 459 - if (!drm_timestamp_monotonic) 460 - etime = ktime_mono_to_real(etime); 461 - 462 - /* save this only for debugging purposes */ 463 - tv_etime = ktime_to_timeval(etime); 464 - /* Subtract time delta from raw timestamp to get final 465 - * vblank_time timestamp for end of vblank. 466 - */ 467 - etime = ktime_sub_ns(etime, delta_ns); 468 - *vblank_time = ktime_to_timeval(etime); 469 - 470 - DRM_DEBUG_VBL("crtc %u : v p(%d,%d)@ %ld.%ld -> %ld.%ld [e %d us, %d rep]\n", 471 - pipe, hpos, vpos, 472 - (long)tv_etime.tv_sec, (long)tv_etime.tv_usec, 473 - (long)vblank_time->tv_sec, (long)vblank_time->tv_usec, 474 - duration_ns/1000, i); 475 - 476 - return true; 477 - } 478 - EXPORT_SYMBOL(drm_calc_vbltimestamp_from_scanoutpos); 479 - 480 - static struct timeval get_drm_timestamp(void) 481 - { 482 - ktime_t now; 483 - 484 - now = drm_timestamp_monotonic ? ktime_get() : ktime_get_real(); 485 - return ktime_to_timeval(now); 486 - } 487 - 488 - /** 489 - * drm_get_last_vbltimestamp - retrieve raw timestamp for the most recent 490 - * vblank interval 491 - * @dev: DRM device 492 - * @pipe: index of CRTC whose vblank timestamp to retrieve 493 - * @tvblank: Pointer to target struct timeval which should receive the timestamp 494 - * @in_vblank_irq: 495 - * True when called from drm_crtc_handle_vblank(). Some drivers 496 - * need to apply some workarounds for gpu-specific vblank irq quirks 497 - * if flag is set. 498 - * 499 - * Fetches the system timestamp corresponding to the time of the most recent 500 - * vblank interval on specified CRTC. May call into kms-driver to 501 - * compute the timestamp with a high-precision GPU specific method. 502 - * 503 - * Returns zero if timestamp originates from uncorrected do_gettimeofday() 504 - * call, i.e., it isn't very precisely locked to the true vblank. 505 - * 506 - * Returns: 507 - * True if timestamp is considered to be very precise, false otherwise. 508 - */ 509 - static bool 510 - drm_get_last_vbltimestamp(struct drm_device *dev, unsigned int pipe, 511 - struct timeval *tvblank, bool in_vblank_irq) 512 - { 513 - bool ret = false; 514 - 515 - /* Define requested maximum error on timestamps (nanoseconds). */ 516 - int max_error = (int) drm_timestamp_precision * 1000; 517 - 518 - /* Query driver if possible and precision timestamping enabled. */ 519 - if (dev->driver->get_vblank_timestamp && (max_error > 0)) 520 - ret = dev->driver->get_vblank_timestamp(dev, pipe, &max_error, 521 - tvblank, in_vblank_irq); 522 - 523 - /* GPU high precision timestamp query unsupported or failed. 524 - * Return current monotonic/gettimeofday timestamp as best estimate. 525 - */ 526 - if (!ret) 527 - *tvblank = get_drm_timestamp(); 528 - 529 - return ret; 530 - } 531 - 532 - /** 533 - * drm_crtc_vblank_count - retrieve "cooked" vblank counter value 534 - * @crtc: which counter to retrieve 535 - * 536 - * Fetches the "cooked" vblank count value that represents the number of 537 - * vblank events since the system was booted, including lost events due to 538 - * modesetting activity. 539 - * 540 - * Returns: 541 - * The software vblank counter. 542 - */ 543 - u32 drm_crtc_vblank_count(struct drm_crtc *crtc) 544 - { 545 - return drm_vblank_count(crtc->dev, drm_crtc_index(crtc)); 546 - } 547 - EXPORT_SYMBOL(drm_crtc_vblank_count); 548 - 549 - /** 550 - * drm_vblank_count_and_time - retrieve "cooked" vblank counter value and the 551 - * system timestamp corresponding to that vblank counter value. 552 - * @dev: DRM device 553 - * @pipe: index of CRTC whose counter to retrieve 554 - * @vblanktime: Pointer to struct timeval to receive the vblank timestamp. 555 - * 556 - * Fetches the "cooked" vblank count value that represents the number of 557 - * vblank events since the system was booted, including lost events due to 558 - * modesetting activity. Returns corresponding system timestamp of the time 559 - * of the vblank interval that corresponds to the current vblank counter value. 560 - * 561 - * This is the legacy version of drm_crtc_vblank_count_and_time(). 562 - */ 563 - static u32 drm_vblank_count_and_time(struct drm_device *dev, unsigned int pipe, 564 - struct timeval *vblanktime) 565 - { 566 - struct drm_vblank_crtc *vblank = &dev->vblank[pipe]; 567 - u32 vblank_count; 568 - unsigned int seq; 569 - 570 - if (WARN_ON(pipe >= dev->num_crtcs)) { 571 - *vblanktime = (struct timeval) { 0 }; 572 - return 0; 573 - } 574 - 575 - do { 576 - seq = read_seqbegin(&vblank->seqlock); 577 - vblank_count = vblank->count; 578 - *vblanktime = vblank->time; 579 - } while (read_seqretry(&vblank->seqlock, seq)); 580 - 581 - return vblank_count; 582 - } 583 - 584 - /** 585 - * drm_crtc_vblank_count_and_time - retrieve "cooked" vblank counter value 586 - * and the system timestamp corresponding to that vblank counter value 587 - * @crtc: which counter to retrieve 588 - * @vblanktime: Pointer to struct timeval to receive the vblank timestamp. 589 - * 590 - * Fetches the "cooked" vblank count value that represents the number of 591 - * vblank events since the system was booted, including lost events due to 592 - * modesetting activity. Returns corresponding system timestamp of the time 593 - * of the vblank interval that corresponds to the current vblank counter value. 594 - */ 595 - u32 drm_crtc_vblank_count_and_time(struct drm_crtc *crtc, 596 - struct timeval *vblanktime) 597 - { 598 - return drm_vblank_count_and_time(crtc->dev, drm_crtc_index(crtc), 599 - vblanktime); 600 - } 601 - EXPORT_SYMBOL(drm_crtc_vblank_count_and_time); 602 - 603 - static void send_vblank_event(struct drm_device *dev, 604 - struct drm_pending_vblank_event *e, 605 - unsigned long seq, struct timeval *now) 606 - { 607 - e->event.sequence = seq; 608 - e->event.tv_sec = now->tv_sec; 609 - e->event.tv_usec = now->tv_usec; 610 - 611 - trace_drm_vblank_event_delivered(e->base.file_priv, e->pipe, 612 - e->event.sequence); 613 - 614 - drm_send_event_locked(dev, &e->base); 615 - } 616 - 617 - /** 618 - * drm_crtc_arm_vblank_event - arm vblank event after pageflip 619 - * @crtc: the source CRTC of the vblank event 620 - * @e: the event to send 621 - * 622 - * A lot of drivers need to generate vblank events for the very next vblank 623 - * interrupt. For example when the page flip interrupt happens when the page 624 - * flip gets armed, but not when it actually executes within the next vblank 625 - * period. This helper function implements exactly the required vblank arming 626 - * behaviour. 627 - * 628 - * NOTE: Drivers using this to send out the &drm_crtc_state.event as part of an 629 - * atomic commit must ensure that the next vblank happens at exactly the same 630 - * time as the atomic commit is committed to the hardware. This function itself 631 - * does **not** protect again the next vblank interrupt racing with either this 632 - * function call or the atomic commit operation. A possible sequence could be: 633 - * 634 - * 1. Driver commits new hardware state into vblank-synchronized registers. 635 - * 2. A vblank happens, committing the hardware state. Also the corresponding 636 - * vblank interrupt is fired off and fully processed by the interrupt 637 - * handler. 638 - * 3. The atomic commit operation proceeds to call drm_crtc_arm_vblank_event(). 639 - * 4. The event is only send out for the next vblank, which is wrong. 640 - * 641 - * An equivalent race can happen when the driver calls 642 - * drm_crtc_arm_vblank_event() before writing out the new hardware state. 643 - * 644 - * The only way to make this work safely is to prevent the vblank from firing 645 - * (and the hardware from committing anything else) until the entire atomic 646 - * commit sequence has run to completion. If the hardware does not have such a 647 - * feature (e.g. using a "go" bit), then it is unsafe to use this functions. 648 - * Instead drivers need to manually send out the event from their interrupt 649 - * handler by calling drm_crtc_send_vblank_event() and make sure that there's no 650 - * possible race with the hardware committing the atomic update. 651 - * 652 - * Caller must hold event lock. Caller must also hold a vblank reference for 653 - * the event @e, which will be dropped when the next vblank arrives. 654 - */ 655 - void drm_crtc_arm_vblank_event(struct drm_crtc *crtc, 656 - struct drm_pending_vblank_event *e) 657 - { 658 - struct drm_device *dev = crtc->dev; 659 - unsigned int pipe = drm_crtc_index(crtc); 660 - 661 - assert_spin_locked(&dev->event_lock); 662 - 663 - e->pipe = pipe; 664 - e->event.sequence = drm_vblank_count(dev, pipe); 665 - e->event.crtc_id = crtc->base.id; 666 - list_add_tail(&e->base.link, &dev->vblank_event_list); 667 - } 668 - EXPORT_SYMBOL(drm_crtc_arm_vblank_event); 669 - 670 - /** 671 - * drm_crtc_send_vblank_event - helper to send vblank event after pageflip 672 - * @crtc: the source CRTC of the vblank event 673 - * @e: the event to send 674 - * 675 - * Updates sequence # and timestamp on event for the most recently processed 676 - * vblank, and sends it to userspace. Caller must hold event lock. 677 - * 678 - * See drm_crtc_arm_vblank_event() for a helper which can be used in certain 679 - * situation, especially to send out events for atomic commit operations. 680 - */ 681 - void drm_crtc_send_vblank_event(struct drm_crtc *crtc, 682 - struct drm_pending_vblank_event *e) 683 - { 684 - struct drm_device *dev = crtc->dev; 685 - unsigned int seq, pipe = drm_crtc_index(crtc); 686 - struct timeval now; 687 - 688 - if (dev->num_crtcs > 0) { 689 - seq = drm_vblank_count_and_time(dev, pipe, &now); 690 - } else { 691 - seq = 0; 692 - 693 - now = get_drm_timestamp(); 694 - } 695 - e->pipe = pipe; 696 - e->event.crtc_id = crtc->base.id; 697 - send_vblank_event(dev, e, seq, &now); 698 - } 699 - EXPORT_SYMBOL(drm_crtc_send_vblank_event); 700 - 701 - static int __enable_vblank(struct drm_device *dev, unsigned int pipe) 702 - { 703 - if (drm_core_check_feature(dev, DRIVER_MODESET)) { 704 - struct drm_crtc *crtc = drm_crtc_from_index(dev, pipe); 705 - 706 - if (crtc->funcs->enable_vblank) 707 - return crtc->funcs->enable_vblank(crtc); 708 - } 709 - 710 - return dev->driver->enable_vblank(dev, pipe); 711 - } 712 - 713 - /** 714 - * drm_vblank_enable - enable the vblank interrupt on a CRTC 715 - * @dev: DRM device 716 - * @pipe: CRTC index 717 - * 718 - * Returns: 719 - * Zero on success or a negative error code on failure. 720 - */ 721 - static int drm_vblank_enable(struct drm_device *dev, unsigned int pipe) 722 - { 723 - struct drm_vblank_crtc *vblank = &dev->vblank[pipe]; 724 - int ret = 0; 725 - 726 - assert_spin_locked(&dev->vbl_lock); 727 - 728 - spin_lock(&dev->vblank_time_lock); 729 - 730 - if (!vblank->enabled) { 731 - /* 732 - * Enable vblank irqs under vblank_time_lock protection. 733 - * All vblank count & timestamp updates are held off 734 - * until we are done reinitializing master counter and 735 - * timestamps. Filtercode in drm_handle_vblank() will 736 - * prevent double-accounting of same vblank interval. 737 - */ 738 - ret = __enable_vblank(dev, pipe); 739 - DRM_DEBUG("enabling vblank on crtc %u, ret: %d\n", pipe, ret); 740 - if (ret) { 741 - atomic_dec(&vblank->refcount); 742 - } else { 743 - drm_update_vblank_count(dev, pipe, 0); 744 - /* drm_update_vblank_count() includes a wmb so we just 745 - * need to ensure that the compiler emits the write 746 - * to mark the vblank as enabled after the call 747 - * to drm_update_vblank_count(). 748 - */ 749 - WRITE_ONCE(vblank->enabled, true); 750 - } 751 - } 752 - 753 - spin_unlock(&dev->vblank_time_lock); 754 - 755 - return ret; 756 - } 757 - 758 - /** 759 - * drm_vblank_get - get a reference count on vblank events 760 - * @dev: DRM device 761 - * @pipe: index of CRTC to own 762 - * 763 - * Acquire a reference count on vblank events to avoid having them disabled 764 - * while in use. 765 - * 766 - * This is the legacy version of drm_crtc_vblank_get(). 767 - * 768 - * Returns: 769 - * Zero on success or a negative error code on failure. 770 - */ 771 - static int drm_vblank_get(struct drm_device *dev, unsigned int pipe) 772 - { 773 - struct drm_vblank_crtc *vblank = &dev->vblank[pipe]; 774 - unsigned long irqflags; 775 - int ret = 0; 776 - 777 - if (!dev->num_crtcs) 778 - return -EINVAL; 779 - 780 - if (WARN_ON(pipe >= dev->num_crtcs)) 781 - return -EINVAL; 782 - 783 - spin_lock_irqsave(&dev->vbl_lock, irqflags); 784 - /* Going from 0->1 means we have to enable interrupts again */ 785 - if (atomic_add_return(1, &vblank->refcount) == 1) { 786 - ret = drm_vblank_enable(dev, pipe); 787 - } else { 788 - if (!vblank->enabled) { 789 - atomic_dec(&vblank->refcount); 790 - ret = -EINVAL; 791 - } 792 - } 793 - spin_unlock_irqrestore(&dev->vbl_lock, irqflags); 794 - 795 - return ret; 796 - } 797 - 798 - /** 799 - * drm_crtc_vblank_get - get a reference count on vblank events 800 - * @crtc: which CRTC to own 801 - * 802 - * Acquire a reference count on vblank events to avoid having them disabled 803 - * while in use. 804 - * 805 - * Returns: 806 - * Zero on success or a negative error code on failure. 807 - */ 808 - int drm_crtc_vblank_get(struct drm_crtc *crtc) 809 - { 810 - return drm_vblank_get(crtc->dev, drm_crtc_index(crtc)); 811 - } 812 - EXPORT_SYMBOL(drm_crtc_vblank_get); 813 - 814 - /** 815 - * drm_vblank_put - release ownership of vblank events 816 - * @dev: DRM device 817 - * @pipe: index of CRTC to release 818 - * 819 - * Release ownership of a given vblank counter, turning off interrupts 820 - * if possible. Disable interrupts after drm_vblank_offdelay milliseconds. 821 - * 822 - * This is the legacy version of drm_crtc_vblank_put(). 823 - */ 824 - static void drm_vblank_put(struct drm_device *dev, unsigned int pipe) 825 - { 826 - struct drm_vblank_crtc *vblank = &dev->vblank[pipe]; 827 - 828 - if (WARN_ON(pipe >= dev->num_crtcs)) 829 - return; 830 - 831 - if (WARN_ON(atomic_read(&vblank->refcount) == 0)) 832 - return; 833 - 834 - /* Last user schedules interrupt disable */ 835 - if (atomic_dec_and_test(&vblank->refcount)) { 836 - if (drm_vblank_offdelay == 0) 837 - return; 838 - else if (drm_vblank_offdelay < 0) 839 - vblank_disable_fn((unsigned long)vblank); 840 - else if (!dev->vblank_disable_immediate) 841 - mod_timer(&vblank->disable_timer, 842 - jiffies + ((drm_vblank_offdelay * HZ)/1000)); 843 - } 844 - } 845 - 846 - /** 847 - * drm_crtc_vblank_put - give up ownership of vblank events 848 - * @crtc: which counter to give up 849 - * 850 - * Release ownership of a given vblank counter, turning off interrupts 851 - * if possible. Disable interrupts after drm_vblank_offdelay milliseconds. 852 - */ 853 - void drm_crtc_vblank_put(struct drm_crtc *crtc) 854 - { 855 - drm_vblank_put(crtc->dev, drm_crtc_index(crtc)); 856 - } 857 - EXPORT_SYMBOL(drm_crtc_vblank_put); 858 - 859 - /** 860 - * drm_wait_one_vblank - wait for one vblank 861 - * @dev: DRM device 862 - * @pipe: CRTC index 863 - * 864 - * This waits for one vblank to pass on @pipe, using the irq driver interfaces. 865 - * It is a failure to call this when the vblank irq for @pipe is disabled, e.g. 866 - * due to lack of driver support or because the crtc is off. 867 - */ 868 - void drm_wait_one_vblank(struct drm_device *dev, unsigned int pipe) 869 - { 870 - struct drm_vblank_crtc *vblank = &dev->vblank[pipe]; 871 - int ret; 872 - u32 last; 873 - 874 - if (WARN_ON(pipe >= dev->num_crtcs)) 875 - return; 876 - 877 - ret = drm_vblank_get(dev, pipe); 878 - if (WARN(ret, "vblank not available on crtc %i, ret=%i\n", pipe, ret)) 879 - return; 880 - 881 - last = drm_vblank_count(dev, pipe); 882 - 883 - ret = wait_event_timeout(vblank->queue, 884 - last != drm_vblank_count(dev, pipe), 885 - msecs_to_jiffies(100)); 886 - 887 - WARN(ret == 0, "vblank wait timed out on crtc %i\n", pipe); 888 - 889 - drm_vblank_put(dev, pipe); 890 - } 891 - EXPORT_SYMBOL(drm_wait_one_vblank); 892 - 893 - /** 894 - * drm_crtc_wait_one_vblank - wait for one vblank 895 - * @crtc: DRM crtc 896 - * 897 - * This waits for one vblank to pass on @crtc, using the irq driver interfaces. 898 - * It is a failure to call this when the vblank irq for @crtc is disabled, e.g. 899 - * due to lack of driver support or because the crtc is off. 900 - */ 901 - void drm_crtc_wait_one_vblank(struct drm_crtc *crtc) 902 - { 903 - drm_wait_one_vblank(crtc->dev, drm_crtc_index(crtc)); 904 - } 905 - EXPORT_SYMBOL(drm_crtc_wait_one_vblank); 906 - 907 - /** 908 - * drm_crtc_vblank_off - disable vblank events on a CRTC 909 - * @crtc: CRTC in question 910 - * 911 - * Drivers can use this function to shut down the vblank interrupt handling when 912 - * disabling a crtc. This function ensures that the latest vblank frame count is 913 - * stored so that drm_vblank_on can restore it again. 914 - * 915 - * Drivers must use this function when the hardware vblank counter can get 916 - * reset, e.g. when suspending. 917 - */ 918 - void drm_crtc_vblank_off(struct drm_crtc *crtc) 919 - { 920 - struct drm_device *dev = crtc->dev; 921 - unsigned int pipe = drm_crtc_index(crtc); 922 - struct drm_vblank_crtc *vblank = &dev->vblank[pipe]; 923 - struct drm_pending_vblank_event *e, *t; 924 - struct timeval now; 925 - unsigned long irqflags; 926 - unsigned int seq; 927 - 928 - if (WARN_ON(pipe >= dev->num_crtcs)) 929 - return; 930 - 931 - spin_lock_irqsave(&dev->event_lock, irqflags); 932 - 933 - spin_lock(&dev->vbl_lock); 934 - DRM_DEBUG_VBL("crtc %d, vblank enabled %d, inmodeset %d\n", 935 - pipe, vblank->enabled, vblank->inmodeset); 936 - 937 - /* Avoid redundant vblank disables without previous 938 - * drm_crtc_vblank_on(). */ 939 - if (drm_core_check_feature(dev, DRIVER_ATOMIC) || !vblank->inmodeset) 940 - vblank_disable_and_save(dev, pipe); 941 - 942 - wake_up(&vblank->queue); 943 - 944 - /* 945 - * Prevent subsequent drm_vblank_get() from re-enabling 946 - * the vblank interrupt by bumping the refcount. 947 - */ 948 - if (!vblank->inmodeset) { 949 - atomic_inc(&vblank->refcount); 950 - vblank->inmodeset = 1; 951 - } 952 - spin_unlock(&dev->vbl_lock); 953 - 954 - /* Send any queued vblank events, lest the natives grow disquiet */ 955 - seq = drm_vblank_count_and_time(dev, pipe, &now); 956 - 957 - list_for_each_entry_safe(e, t, &dev->vblank_event_list, base.link) { 958 - if (e->pipe != pipe) 959 - continue; 960 - DRM_DEBUG("Sending premature vblank event on disable: " 961 - "wanted %u, current %u\n", 962 - e->event.sequence, seq); 963 - list_del(&e->base.link); 964 - drm_vblank_put(dev, pipe); 965 - send_vblank_event(dev, e, seq, &now); 966 - } 967 - spin_unlock_irqrestore(&dev->event_lock, irqflags); 968 - 969 - /* Will be reset by the modeset helpers when re-enabling the crtc by 970 - * calling drm_calc_timestamping_constants(). */ 971 - vblank->hwmode.crtc_clock = 0; 972 - } 973 - EXPORT_SYMBOL(drm_crtc_vblank_off); 974 - 975 - /** 976 - * drm_crtc_vblank_reset - reset vblank state to off on a CRTC 977 - * @crtc: CRTC in question 978 - * 979 - * Drivers can use this function to reset the vblank state to off at load time. 980 - * Drivers should use this together with the drm_crtc_vblank_off() and 981 - * drm_crtc_vblank_on() functions. The difference compared to 982 - * drm_crtc_vblank_off() is that this function doesn't save the vblank counter 983 - * and hence doesn't need to call any driver hooks. 984 - */ 985 - void drm_crtc_vblank_reset(struct drm_crtc *crtc) 986 - { 987 - struct drm_device *dev = crtc->dev; 988 - unsigned long irqflags; 989 - unsigned int pipe = drm_crtc_index(crtc); 990 - struct drm_vblank_crtc *vblank = &dev->vblank[pipe]; 991 - 992 - spin_lock_irqsave(&dev->vbl_lock, irqflags); 993 - /* 994 - * Prevent subsequent drm_vblank_get() from enabling the vblank 995 - * interrupt by bumping the refcount. 996 - */ 997 - if (!vblank->inmodeset) { 998 - atomic_inc(&vblank->refcount); 999 - vblank->inmodeset = 1; 1000 - } 1001 - spin_unlock_irqrestore(&dev->vbl_lock, irqflags); 1002 - 1003 - WARN_ON(!list_empty(&dev->vblank_event_list)); 1004 - } 1005 - EXPORT_SYMBOL(drm_crtc_vblank_reset); 1006 - 1007 - /** 1008 - * drm_crtc_vblank_on - enable vblank events on a CRTC 1009 - * @crtc: CRTC in question 1010 - * 1011 - * This functions restores the vblank interrupt state captured with 1012 - * drm_crtc_vblank_off() again. Note that calls to drm_crtc_vblank_on() and 1013 - * drm_crtc_vblank_off() can be unbalanced and so can also be unconditionally called 1014 - * in driver load code to reflect the current hardware state of the crtc. 1015 - */ 1016 - void drm_crtc_vblank_on(struct drm_crtc *crtc) 1017 - { 1018 - struct drm_device *dev = crtc->dev; 1019 - unsigned int pipe = drm_crtc_index(crtc); 1020 - struct drm_vblank_crtc *vblank = &dev->vblank[pipe]; 1021 - unsigned long irqflags; 1022 - 1023 - if (WARN_ON(pipe >= dev->num_crtcs)) 1024 - return; 1025 - 1026 - spin_lock_irqsave(&dev->vbl_lock, irqflags); 1027 - DRM_DEBUG_VBL("crtc %d, vblank enabled %d, inmodeset %d\n", 1028 - pipe, vblank->enabled, vblank->inmodeset); 1029 - 1030 - /* Drop our private "prevent drm_vblank_get" refcount */ 1031 - if (vblank->inmodeset) { 1032 - atomic_dec(&vblank->refcount); 1033 - vblank->inmodeset = 0; 1034 - } 1035 - 1036 - drm_reset_vblank_timestamp(dev, pipe); 1037 - 1038 - /* 1039 - * re-enable interrupts if there are users left, or the 1040 - * user wishes vblank interrupts to be enabled all the time. 1041 - */ 1042 - if (atomic_read(&vblank->refcount) != 0 || drm_vblank_offdelay == 0) 1043 - WARN_ON(drm_vblank_enable(dev, pipe)); 1044 - spin_unlock_irqrestore(&dev->vbl_lock, irqflags); 1045 - } 1046 - EXPORT_SYMBOL(drm_crtc_vblank_on); 1047 - 1048 - static void drm_legacy_vblank_pre_modeset(struct drm_device *dev, 1049 - unsigned int pipe) 1050 - { 1051 - struct drm_vblank_crtc *vblank = &dev->vblank[pipe]; 1052 - 1053 - /* vblank is not initialized (IRQ not installed ?), or has been freed */ 1054 - if (!dev->num_crtcs) 1055 - return; 1056 - 1057 - if (WARN_ON(pipe >= dev->num_crtcs)) 1058 - return; 1059 - 1060 - /* 1061 - * To avoid all the problems that might happen if interrupts 1062 - * were enabled/disabled around or between these calls, we just 1063 - * have the kernel take a reference on the CRTC (just once though 1064 - * to avoid corrupting the count if multiple, mismatch calls occur), 1065 - * so that interrupts remain enabled in the interim. 1066 - */ 1067 - if (!vblank->inmodeset) { 1068 - vblank->inmodeset = 0x1; 1069 - if (drm_vblank_get(dev, pipe) == 0) 1070 - vblank->inmodeset |= 0x2; 1071 - } 1072 - } 1073 - 1074 - static void drm_legacy_vblank_post_modeset(struct drm_device *dev, 1075 - unsigned int pipe) 1076 - { 1077 - struct drm_vblank_crtc *vblank = &dev->vblank[pipe]; 1078 - unsigned long irqflags; 1079 - 1080 - /* vblank is not initialized (IRQ not installed ?), or has been freed */ 1081 - if (!dev->num_crtcs) 1082 - return; 1083 - 1084 - if (WARN_ON(pipe >= dev->num_crtcs)) 1085 - return; 1086 - 1087 - if (vblank->inmodeset) { 1088 - spin_lock_irqsave(&dev->vbl_lock, irqflags); 1089 - drm_reset_vblank_timestamp(dev, pipe); 1090 - spin_unlock_irqrestore(&dev->vbl_lock, irqflags); 1091 - 1092 - if (vblank->inmodeset & 0x2) 1093 - drm_vblank_put(dev, pipe); 1094 - 1095 - vblank->inmodeset = 0; 1096 - } 1097 - } 1098 - 1099 - int drm_legacy_modeset_ctl(struct drm_device *dev, void *data, 1100 - struct drm_file *file_priv) 1101 - { 1102 - struct drm_modeset_ctl *modeset = data; 1103 - unsigned int pipe; 1104 - 1105 - /* If drm_vblank_init() hasn't been called yet, just no-op */ 1106 - if (!dev->num_crtcs) 1107 - return 0; 1108 - 1109 - /* KMS drivers handle this internally */ 1110 - if (!drm_core_check_feature(dev, DRIVER_LEGACY)) 1111 - return 0; 1112 - 1113 - pipe = modeset->crtc; 1114 - if (pipe >= dev->num_crtcs) 1115 - return -EINVAL; 1116 - 1117 - switch (modeset->cmd) { 1118 - case _DRM_PRE_MODESET: 1119 - drm_legacy_vblank_pre_modeset(dev, pipe); 1120 - break; 1121 - case _DRM_POST_MODESET: 1122 - drm_legacy_vblank_post_modeset(dev, pipe); 1123 - break; 1124 - default: 1125 - return -EINVAL; 1126 - } 1127 - 1128 - return 0; 1129 - } 1130 - 1131 - static inline bool vblank_passed(u32 seq, u32 ref) 1132 - { 1133 - return (seq - ref) <= (1 << 23); 1134 - } 1135 - 1136 - static int drm_queue_vblank_event(struct drm_device *dev, unsigned int pipe, 1137 - union drm_wait_vblank *vblwait, 1138 - struct drm_file *file_priv) 1139 - { 1140 - struct drm_vblank_crtc *vblank = &dev->vblank[pipe]; 1141 - struct drm_pending_vblank_event *e; 1142 - struct timeval now; 1143 - unsigned long flags; 1144 - unsigned int seq; 1145 - int ret; 1146 - 1147 - e = kzalloc(sizeof(*e), GFP_KERNEL); 1148 - if (e == NULL) { 1149 - ret = -ENOMEM; 1150 - goto err_put; 1151 - } 1152 - 1153 - e->pipe = pipe; 1154 - e->event.base.type = DRM_EVENT_VBLANK; 1155 - e->event.base.length = sizeof(e->event); 1156 - e->event.user_data = vblwait->request.signal; 1157 - 1158 - spin_lock_irqsave(&dev->event_lock, flags); 1159 - 1160 - /* 1161 - * drm_crtc_vblank_off() might have been called after we called 1162 - * drm_vblank_get(). drm_crtc_vblank_off() holds event_lock around the 1163 - * vblank disable, so no need for further locking. The reference from 1164 - * drm_vblank_get() protects against vblank disable from another source. 1165 - */ 1166 - if (!READ_ONCE(vblank->enabled)) { 1167 - ret = -EINVAL; 1168 - goto err_unlock; 1169 - } 1170 - 1171 - ret = drm_event_reserve_init_locked(dev, file_priv, &e->base, 1172 - &e->event.base); 1173 - 1174 - if (ret) 1175 - goto err_unlock; 1176 - 1177 - seq = drm_vblank_count_and_time(dev, pipe, &now); 1178 - 1179 - DRM_DEBUG("event on vblank count %u, current %u, crtc %u\n", 1180 - vblwait->request.sequence, seq, pipe); 1181 - 1182 - trace_drm_vblank_event_queued(file_priv, pipe, 1183 - vblwait->request.sequence); 1184 - 1185 - e->event.sequence = vblwait->request.sequence; 1186 - if (vblank_passed(seq, vblwait->request.sequence)) { 1187 - drm_vblank_put(dev, pipe); 1188 - send_vblank_event(dev, e, seq, &now); 1189 - vblwait->reply.sequence = seq; 1190 - } else { 1191 - /* drm_handle_vblank_events will call drm_vblank_put */ 1192 - list_add_tail(&e->base.link, &dev->vblank_event_list); 1193 - vblwait->reply.sequence = vblwait->request.sequence; 1194 - } 1195 - 1196 - spin_unlock_irqrestore(&dev->event_lock, flags); 1197 - 1198 - return 0; 1199 - 1200 - err_unlock: 1201 - spin_unlock_irqrestore(&dev->event_lock, flags); 1202 - kfree(e); 1203 - err_put: 1204 - drm_vblank_put(dev, pipe); 1205 - return ret; 1206 - } 1207 - 1208 - static bool drm_wait_vblank_is_query(union drm_wait_vblank *vblwait) 1209 - { 1210 - if (vblwait->request.sequence) 1211 - return false; 1212 - 1213 - return _DRM_VBLANK_RELATIVE == 1214 - (vblwait->request.type & (_DRM_VBLANK_TYPES_MASK | 1215 - _DRM_VBLANK_EVENT | 1216 - _DRM_VBLANK_NEXTONMISS)); 1217 - } 1218 - 1219 - /* 1220 - * Wait for VBLANK. 1221 - * 1222 - * \param inode device inode. 1223 - * \param file_priv DRM file private. 1224 - * \param cmd command. 1225 - * \param data user argument, pointing to a drm_wait_vblank structure. 1226 - * \return zero on success or a negative number on failure. 1227 - * 1228 - * This function enables the vblank interrupt on the pipe requested, then 1229 - * sleeps waiting for the requested sequence number to occur, and drops 1230 - * the vblank interrupt refcount afterwards. (vblank IRQ disable follows that 1231 - * after a timeout with no further vblank waits scheduled). 1232 - */ 1233 - int drm_wait_vblank(struct drm_device *dev, void *data, 1234 - struct drm_file *file_priv) 1235 - { 1236 - struct drm_vblank_crtc *vblank; 1237 - union drm_wait_vblank *vblwait = data; 1238 - int ret; 1239 - unsigned int flags, seq, pipe, high_pipe; 1240 - 1241 - if (!dev->irq_enabled) 1242 - return -EINVAL; 1243 - 1244 - if (vblwait->request.type & _DRM_VBLANK_SIGNAL) 1245 - return -EINVAL; 1246 - 1247 - if (vblwait->request.type & 1248 - ~(_DRM_VBLANK_TYPES_MASK | _DRM_VBLANK_FLAGS_MASK | 1249 - _DRM_VBLANK_HIGH_CRTC_MASK)) { 1250 - DRM_ERROR("Unsupported type value 0x%x, supported mask 0x%x\n", 1251 - vblwait->request.type, 1252 - (_DRM_VBLANK_TYPES_MASK | _DRM_VBLANK_FLAGS_MASK | 1253 - _DRM_VBLANK_HIGH_CRTC_MASK)); 1254 - return -EINVAL; 1255 - } 1256 - 1257 - flags = vblwait->request.type & _DRM_VBLANK_FLAGS_MASK; 1258 - high_pipe = (vblwait->request.type & _DRM_VBLANK_HIGH_CRTC_MASK); 1259 - if (high_pipe) 1260 - pipe = high_pipe >> _DRM_VBLANK_HIGH_CRTC_SHIFT; 1261 - else 1262 - pipe = flags & _DRM_VBLANK_SECONDARY ? 1 : 0; 1263 - if (pipe >= dev->num_crtcs) 1264 - return -EINVAL; 1265 - 1266 - vblank = &dev->vblank[pipe]; 1267 - 1268 - /* If the counter is currently enabled and accurate, short-circuit 1269 - * queries to return the cached timestamp of the last vblank. 1270 - */ 1271 - if (dev->vblank_disable_immediate && 1272 - drm_wait_vblank_is_query(vblwait) && 1273 - READ_ONCE(vblank->enabled)) { 1274 - struct timeval now; 1275 - 1276 - vblwait->reply.sequence = 1277 - drm_vblank_count_and_time(dev, pipe, &now); 1278 - vblwait->reply.tval_sec = now.tv_sec; 1279 - vblwait->reply.tval_usec = now.tv_usec; 1280 - return 0; 1281 - } 1282 - 1283 - ret = drm_vblank_get(dev, pipe); 1284 - if (ret) { 1285 - DRM_DEBUG("crtc %d failed to acquire vblank counter, %d\n", pipe, ret); 1286 - return ret; 1287 - } 1288 - seq = drm_vblank_count(dev, pipe); 1289 - 1290 - switch (vblwait->request.type & _DRM_VBLANK_TYPES_MASK) { 1291 - case _DRM_VBLANK_RELATIVE: 1292 - vblwait->request.sequence += seq; 1293 - vblwait->request.type &= ~_DRM_VBLANK_RELATIVE; 1294 - case _DRM_VBLANK_ABSOLUTE: 1295 - break; 1296 - default: 1297 - ret = -EINVAL; 1298 - goto done; 1299 - } 1300 - 1301 - if ((flags & _DRM_VBLANK_NEXTONMISS) && 1302 - vblank_passed(seq, vblwait->request.sequence)) 1303 - vblwait->request.sequence = seq + 1; 1304 - 1305 - if (flags & _DRM_VBLANK_EVENT) { 1306 - /* must hold on to the vblank ref until the event fires 1307 - * drm_vblank_put will be called asynchronously 1308 - */ 1309 - return drm_queue_vblank_event(dev, pipe, vblwait, file_priv); 1310 - } 1311 - 1312 - if (vblwait->request.sequence != seq) { 1313 - DRM_DEBUG("waiting on vblank count %u, crtc %u\n", 1314 - vblwait->request.sequence, pipe); 1315 - DRM_WAIT_ON(ret, vblank->queue, 3 * HZ, 1316 - vblank_passed(drm_vblank_count(dev, pipe), 1317 - vblwait->request.sequence) || 1318 - !READ_ONCE(vblank->enabled)); 1319 - } 1320 - 1321 - if (ret != -EINTR) { 1322 - struct timeval now; 1323 - 1324 - vblwait->reply.sequence = drm_vblank_count_and_time(dev, pipe, &now); 1325 - vblwait->reply.tval_sec = now.tv_sec; 1326 - vblwait->reply.tval_usec = now.tv_usec; 1327 - 1328 - DRM_DEBUG("crtc %d returning %u to client\n", 1329 - pipe, vblwait->reply.sequence); 1330 - } else { 1331 - DRM_DEBUG("crtc %d vblank wait interrupted by signal\n", pipe); 1332 - } 1333 - 1334 - done: 1335 - drm_vblank_put(dev, pipe); 1336 - return ret; 1337 - } 1338 - 1339 - static void drm_handle_vblank_events(struct drm_device *dev, unsigned int pipe) 1340 - { 1341 - struct drm_pending_vblank_event *e, *t; 1342 - struct timeval now; 1343 - unsigned int seq; 1344 - 1345 - assert_spin_locked(&dev->event_lock); 1346 - 1347 - seq = drm_vblank_count_and_time(dev, pipe, &now); 1348 - 1349 - list_for_each_entry_safe(e, t, &dev->vblank_event_list, base.link) { 1350 - if (e->pipe != pipe) 1351 - continue; 1352 - if (!vblank_passed(seq, e->event.sequence)) 1353 - continue; 1354 - 1355 - DRM_DEBUG("vblank event on %u, current %u\n", 1356 - e->event.sequence, seq); 1357 - 1358 - list_del(&e->base.link); 1359 - drm_vblank_put(dev, pipe); 1360 - send_vblank_event(dev, e, seq, &now); 1361 - } 1362 - 1363 - trace_drm_vblank_event(pipe, seq); 1364 - } 1365 - 1366 - /** 1367 - * drm_handle_vblank - handle a vblank event 1368 - * @dev: DRM device 1369 - * @pipe: index of CRTC where this event occurred 1370 - * 1371 - * Drivers should call this routine in their vblank interrupt handlers to 1372 - * update the vblank counter and send any signals that may be pending. 1373 - * 1374 - * This is the legacy version of drm_crtc_handle_vblank(). 1375 - */ 1376 - bool drm_handle_vblank(struct drm_device *dev, unsigned int pipe) 1377 - { 1378 - struct drm_vblank_crtc *vblank = &dev->vblank[pipe]; 1379 - unsigned long irqflags; 1380 - bool disable_irq; 1381 - 1382 - if (WARN_ON_ONCE(!dev->num_crtcs)) 1383 - return false; 1384 - 1385 - if (WARN_ON(pipe >= dev->num_crtcs)) 1386 - return false; 1387 - 1388 - spin_lock_irqsave(&dev->event_lock, irqflags); 1389 - 1390 - /* Need timestamp lock to prevent concurrent execution with 1391 - * vblank enable/disable, as this would cause inconsistent 1392 - * or corrupted timestamps and vblank counts. 1393 - */ 1394 - spin_lock(&dev->vblank_time_lock); 1395 - 1396 - /* Vblank irq handling disabled. Nothing to do. */ 1397 - if (!vblank->enabled) { 1398 - spin_unlock(&dev->vblank_time_lock); 1399 - spin_unlock_irqrestore(&dev->event_lock, irqflags); 1400 - return false; 1401 - } 1402 - 1403 - drm_update_vblank_count(dev, pipe, true); 1404 - 1405 - spin_unlock(&dev->vblank_time_lock); 1406 - 1407 - wake_up(&vblank->queue); 1408 - 1409 - /* With instant-off, we defer disabling the interrupt until after 1410 - * we finish processing the following vblank after all events have 1411 - * been signaled. The disable has to be last (after 1412 - * drm_handle_vblank_events) so that the timestamp is always accurate. 1413 - */ 1414 - disable_irq = (dev->vblank_disable_immediate && 1415 - drm_vblank_offdelay > 0 && 1416 - !atomic_read(&vblank->refcount)); 1417 - 1418 - drm_handle_vblank_events(dev, pipe); 1419 - 1420 - spin_unlock_irqrestore(&dev->event_lock, irqflags); 1421 - 1422 - if (disable_irq) 1423 - vblank_disable_fn((unsigned long)vblank); 1424 - 1425 - return true; 1426 - } 1427 - EXPORT_SYMBOL(drm_handle_vblank); 1428 - 1429 - /** 1430 - * drm_crtc_handle_vblank - handle a vblank event 1431 - * @crtc: where this event occurred 1432 - * 1433 - * Drivers should call this routine in their vblank interrupt handlers to 1434 - * update the vblank counter and send any signals that may be pending. 1435 - * 1436 - * This is the native KMS version of drm_handle_vblank(). 1437 - * 1438 - * Returns: 1439 - * True if the event was successfully handled, false on failure. 1440 - */ 1441 - bool drm_crtc_handle_vblank(struct drm_crtc *crtc) 1442 - { 1443 - return drm_handle_vblank(crtc->dev, drm_crtc_index(crtc)); 1444 - } 1445 - EXPORT_SYMBOL(drm_crtc_handle_vblank);
+101 -4
drivers/gpu/drm/drm_probe_helper.c
··· 38 38 #include <drm/drm_crtc_helper.h> 39 39 #include <drm/drm_fb_helper.h> 40 40 #include <drm/drm_edid.h> 41 + #include <drm/drm_modeset_helper_vtables.h> 42 + 43 + #include "drm_crtc_helper_internal.h" 41 44 42 45 /** 43 46 * DOC: output probing helper overview ··· 83 80 return MODE_OK; 84 81 } 85 82 83 + static enum drm_mode_status 84 + drm_mode_validate_pipeline(struct drm_display_mode *mode, 85 + struct drm_connector *connector) 86 + { 87 + struct drm_device *dev = connector->dev; 88 + uint32_t *ids = connector->encoder_ids; 89 + enum drm_mode_status ret = MODE_OK; 90 + unsigned int i; 91 + 92 + /* Step 1: Validate against connector */ 93 + ret = drm_connector_mode_valid(connector, mode); 94 + if (ret != MODE_OK) 95 + return ret; 96 + 97 + /* Step 2: Validate against encoders and crtcs */ 98 + for (i = 0; i < DRM_CONNECTOR_MAX_ENCODER; i++) { 99 + struct drm_encoder *encoder = drm_encoder_find(dev, ids[i]); 100 + struct drm_crtc *crtc; 101 + 102 + if (!encoder) 103 + continue; 104 + 105 + ret = drm_encoder_mode_valid(encoder, mode); 106 + if (ret != MODE_OK) { 107 + /* No point in continuing for crtc check as this encoder 108 + * will not accept the mode anyway. If all encoders 109 + * reject the mode then, at exit, ret will not be 110 + * MODE_OK. */ 111 + continue; 112 + } 113 + 114 + ret = drm_bridge_mode_valid(encoder->bridge, mode); 115 + if (ret != MODE_OK) { 116 + /* There is also no point in continuing for crtc check 117 + * here. */ 118 + continue; 119 + } 120 + 121 + drm_for_each_crtc(crtc, dev) { 122 + if (!drm_encoder_crtc_ok(encoder, crtc)) 123 + continue; 124 + 125 + ret = drm_crtc_mode_valid(crtc, mode); 126 + if (ret == MODE_OK) { 127 + /* If we get to this point there is at least 128 + * one combination of encoder+crtc that works 129 + * for this mode. Lets return now. */ 130 + return ret; 131 + } 132 + } 133 + } 134 + 135 + return ret; 136 + } 137 + 86 138 static int drm_helper_probe_add_cmdline_mode(struct drm_connector *connector) 87 139 { 88 140 struct drm_cmdline_mode *cmdline_mode; ··· 169 111 170 112 drm_mode_probed_add(connector, mode); 171 113 return 1; 114 + } 115 + 116 + enum drm_mode_status drm_crtc_mode_valid(struct drm_crtc *crtc, 117 + const struct drm_display_mode *mode) 118 + { 119 + const struct drm_crtc_helper_funcs *crtc_funcs = crtc->helper_private; 120 + 121 + if (!crtc_funcs || !crtc_funcs->mode_valid) 122 + return MODE_OK; 123 + 124 + return crtc_funcs->mode_valid(crtc, mode); 125 + } 126 + 127 + enum drm_mode_status drm_encoder_mode_valid(struct drm_encoder *encoder, 128 + const struct drm_display_mode *mode) 129 + { 130 + const struct drm_encoder_helper_funcs *encoder_funcs = 131 + encoder->helper_private; 132 + 133 + if (!encoder_funcs || !encoder_funcs->mode_valid) 134 + return MODE_OK; 135 + 136 + return encoder_funcs->mode_valid(encoder, mode); 137 + } 138 + 139 + enum drm_mode_status drm_connector_mode_valid(struct drm_connector *connector, 140 + struct drm_display_mode *mode) 141 + { 142 + const struct drm_connector_helper_funcs *connector_funcs = 143 + connector->helper_private; 144 + 145 + if (!connector_funcs || !connector_funcs->mode_valid) 146 + return MODE_OK; 147 + 148 + return connector_funcs->mode_valid(connector, mode); 172 149 } 173 150 174 151 #define DRM_OUTPUT_POLL_PERIOD (10*HZ) ··· 377 284 * - drm_mode_validate_flag() checks the modes against basic connector 378 285 * capabilities (interlace_allowed,doublescan_allowed,stereo_allowed) 379 286 * - the optional &drm_connector_helper_funcs.mode_valid helper can perform 380 - * driver and/or hardware specific checks 287 + * driver and/or sink specific checks 288 + * - the optional &drm_crtc_helper_funcs.mode_valid, 289 + * &drm_bridge_funcs.mode_valid and &drm_encoder_helper_funcs.mode_valid 290 + * helpers can perform driver and/or source specific checks which are also 291 + * enforced by the modeset/atomic helpers 381 292 * 382 293 * 5. Any mode whose status is not OK is pruned from the connector's modes list, 383 294 * accompanied by a debug message indicating the reason for the mode's ··· 525 428 if (mode->status == MODE_OK) 526 429 mode->status = drm_mode_validate_flag(mode, mode_flags); 527 430 528 - if (mode->status == MODE_OK && connector_funcs->mode_valid) 529 - mode->status = connector_funcs->mode_valid(connector, 530 - mode); 431 + if (mode->status == MODE_OK) 432 + mode->status = drm_mode_validate_pipeline(mode, 433 + connector); 531 434 } 532 435 533 436 prune:
+1648
drivers/gpu/drm/drm_vblank.c
··· 1 + /* 2 + * drm_irq.c IRQ and vblank support 3 + * 4 + * \author Rickard E. (Rik) Faith <faith@valinux.com> 5 + * \author Gareth Hughes <gareth@valinux.com> 6 + * 7 + * Permission is hereby granted, free of charge, to any person obtaining a 8 + * copy of this software and associated documentation files (the "Software"), 9 + * to deal in the Software without restriction, including without limitation 10 + * the rights to use, copy, modify, merge, publish, distribute, sublicense, 11 + * and/or sell copies of the Software, and to permit persons to whom the 12 + * Software is furnished to do so, subject to the following conditions: 13 + * 14 + * The above copyright notice and this permission notice (including the next 15 + * paragraph) shall be included in all copies or substantial portions of the 16 + * Software. 17 + * 18 + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 21 + * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR 22 + * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 23 + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 24 + * OTHER DEALINGS IN THE SOFTWARE. 25 + */ 26 + 27 + #include <drm/drm_vblank.h> 28 + #include <drm/drmP.h> 29 + #include <linux/export.h> 30 + 31 + #include "drm_trace.h" 32 + #include "drm_internal.h" 33 + 34 + /* Retry timestamp calculation up to 3 times to satisfy 35 + * drm_timestamp_precision before giving up. 36 + */ 37 + #define DRM_TIMESTAMP_MAXRETRIES 3 38 + 39 + /* Threshold in nanoseconds for detection of redundant 40 + * vblank irq in drm_handle_vblank(). 1 msec should be ok. 41 + */ 42 + #define DRM_REDUNDANT_VBLIRQ_THRESH_NS 1000000 43 + 44 + static bool 45 + drm_get_last_vbltimestamp(struct drm_device *dev, unsigned int pipe, 46 + struct timeval *tvblank, bool in_vblank_irq); 47 + 48 + static unsigned int drm_timestamp_precision = 20; /* Default to 20 usecs. */ 49 + 50 + /* 51 + * Default to use monotonic timestamps for wait-for-vblank and page-flip 52 + * complete events. 53 + */ 54 + unsigned int drm_timestamp_monotonic = 1; 55 + 56 + static int drm_vblank_offdelay = 5000; /* Default to 5000 msecs. */ 57 + 58 + module_param_named(vblankoffdelay, drm_vblank_offdelay, int, 0600); 59 + module_param_named(timestamp_precision_usec, drm_timestamp_precision, int, 0600); 60 + module_param_named(timestamp_monotonic, drm_timestamp_monotonic, int, 0600); 61 + MODULE_PARM_DESC(vblankoffdelay, "Delay until vblank irq auto-disable [msecs] (0: never disable, <0: disable immediately)"); 62 + MODULE_PARM_DESC(timestamp_precision_usec, "Max. error on timestamps [usecs]"); 63 + MODULE_PARM_DESC(timestamp_monotonic, "Use monotonic timestamps"); 64 + 65 + static void store_vblank(struct drm_device *dev, unsigned int pipe, 66 + u32 vblank_count_inc, 67 + struct timeval *t_vblank, u32 last) 68 + { 69 + struct drm_vblank_crtc *vblank = &dev->vblank[pipe]; 70 + 71 + assert_spin_locked(&dev->vblank_time_lock); 72 + 73 + vblank->last = last; 74 + 75 + write_seqlock(&vblank->seqlock); 76 + vblank->time = *t_vblank; 77 + vblank->count += vblank_count_inc; 78 + write_sequnlock(&vblank->seqlock); 79 + } 80 + 81 + /* 82 + * "No hw counter" fallback implementation of .get_vblank_counter() hook, 83 + * if there is no useable hardware frame counter available. 84 + */ 85 + static u32 drm_vblank_no_hw_counter(struct drm_device *dev, unsigned int pipe) 86 + { 87 + WARN_ON_ONCE(dev->max_vblank_count != 0); 88 + return 0; 89 + } 90 + 91 + static u32 __get_vblank_counter(struct drm_device *dev, unsigned int pipe) 92 + { 93 + if (drm_core_check_feature(dev, DRIVER_MODESET)) { 94 + struct drm_crtc *crtc = drm_crtc_from_index(dev, pipe); 95 + 96 + if (crtc->funcs->get_vblank_counter) 97 + return crtc->funcs->get_vblank_counter(crtc); 98 + } 99 + 100 + if (dev->driver->get_vblank_counter) 101 + return dev->driver->get_vblank_counter(dev, pipe); 102 + 103 + return drm_vblank_no_hw_counter(dev, pipe); 104 + } 105 + 106 + /* 107 + * Reset the stored timestamp for the current vblank count to correspond 108 + * to the last vblank occurred. 109 + * 110 + * Only to be called from drm_crtc_vblank_on(). 111 + * 112 + * Note: caller must hold &drm_device.vbl_lock since this reads & writes 113 + * device vblank fields. 114 + */ 115 + static void drm_reset_vblank_timestamp(struct drm_device *dev, unsigned int pipe) 116 + { 117 + u32 cur_vblank; 118 + bool rc; 119 + struct timeval t_vblank; 120 + int count = DRM_TIMESTAMP_MAXRETRIES; 121 + 122 + spin_lock(&dev->vblank_time_lock); 123 + 124 + /* 125 + * sample the current counter to avoid random jumps 126 + * when drm_vblank_enable() applies the diff 127 + */ 128 + do { 129 + cur_vblank = __get_vblank_counter(dev, pipe); 130 + rc = drm_get_last_vbltimestamp(dev, pipe, &t_vblank, false); 131 + } while (cur_vblank != __get_vblank_counter(dev, pipe) && --count > 0); 132 + 133 + /* 134 + * Only reinitialize corresponding vblank timestamp if high-precision query 135 + * available and didn't fail. Otherwise reinitialize delayed at next vblank 136 + * interrupt and assign 0 for now, to mark the vblanktimestamp as invalid. 137 + */ 138 + if (!rc) 139 + t_vblank = (struct timeval) {0, 0}; 140 + 141 + /* 142 + * +1 to make sure user will never see the same 143 + * vblank counter value before and after a modeset 144 + */ 145 + store_vblank(dev, pipe, 1, &t_vblank, cur_vblank); 146 + 147 + spin_unlock(&dev->vblank_time_lock); 148 + } 149 + 150 + /* 151 + * Call back into the driver to update the appropriate vblank counter 152 + * (specified by @pipe). Deal with wraparound, if it occurred, and 153 + * update the last read value so we can deal with wraparound on the next 154 + * call if necessary. 155 + * 156 + * Only necessary when going from off->on, to account for frames we 157 + * didn't get an interrupt for. 158 + * 159 + * Note: caller must hold &drm_device.vbl_lock since this reads & writes 160 + * device vblank fields. 161 + */ 162 + static void drm_update_vblank_count(struct drm_device *dev, unsigned int pipe, 163 + bool in_vblank_irq) 164 + { 165 + struct drm_vblank_crtc *vblank = &dev->vblank[pipe]; 166 + u32 cur_vblank, diff; 167 + bool rc; 168 + struct timeval t_vblank; 169 + int count = DRM_TIMESTAMP_MAXRETRIES; 170 + int framedur_ns = vblank->framedur_ns; 171 + 172 + /* 173 + * Interrupts were disabled prior to this call, so deal with counter 174 + * wrap if needed. 175 + * NOTE! It's possible we lost a full dev->max_vblank_count + 1 events 176 + * here if the register is small or we had vblank interrupts off for 177 + * a long time. 178 + * 179 + * We repeat the hardware vblank counter & timestamp query until 180 + * we get consistent results. This to prevent races between gpu 181 + * updating its hardware counter while we are retrieving the 182 + * corresponding vblank timestamp. 183 + */ 184 + do { 185 + cur_vblank = __get_vblank_counter(dev, pipe); 186 + rc = drm_get_last_vbltimestamp(dev, pipe, &t_vblank, in_vblank_irq); 187 + } while (cur_vblank != __get_vblank_counter(dev, pipe) && --count > 0); 188 + 189 + if (dev->max_vblank_count != 0) { 190 + /* trust the hw counter when it's around */ 191 + diff = (cur_vblank - vblank->last) & dev->max_vblank_count; 192 + } else if (rc && framedur_ns) { 193 + const struct timeval *t_old; 194 + u64 diff_ns; 195 + 196 + t_old = &vblank->time; 197 + diff_ns = timeval_to_ns(&t_vblank) - timeval_to_ns(t_old); 198 + 199 + /* 200 + * Figure out how many vblanks we've missed based 201 + * on the difference in the timestamps and the 202 + * frame/field duration. 203 + */ 204 + diff = DIV_ROUND_CLOSEST_ULL(diff_ns, framedur_ns); 205 + 206 + if (diff == 0 && in_vblank_irq) 207 + DRM_DEBUG_VBL("crtc %u: Redundant vblirq ignored." 208 + " diff_ns = %lld, framedur_ns = %d)\n", 209 + pipe, (long long) diff_ns, framedur_ns); 210 + } else { 211 + /* some kind of default for drivers w/o accurate vbl timestamping */ 212 + diff = in_vblank_irq ? 1 : 0; 213 + } 214 + 215 + /* 216 + * Within a drm_vblank_pre_modeset - drm_vblank_post_modeset 217 + * interval? If so then vblank irqs keep running and it will likely 218 + * happen that the hardware vblank counter is not trustworthy as it 219 + * might reset at some point in that interval and vblank timestamps 220 + * are not trustworthy either in that interval. Iow. this can result 221 + * in a bogus diff >> 1 which must be avoided as it would cause 222 + * random large forward jumps of the software vblank counter. 223 + */ 224 + if (diff > 1 && (vblank->inmodeset & 0x2)) { 225 + DRM_DEBUG_VBL("clamping vblank bump to 1 on crtc %u: diffr=%u" 226 + " due to pre-modeset.\n", pipe, diff); 227 + diff = 1; 228 + } 229 + 230 + DRM_DEBUG_VBL("updating vblank count on crtc %u:" 231 + " current=%u, diff=%u, hw=%u hw_last=%u\n", 232 + pipe, vblank->count, diff, cur_vblank, vblank->last); 233 + 234 + if (diff == 0) { 235 + WARN_ON_ONCE(cur_vblank != vblank->last); 236 + return; 237 + } 238 + 239 + /* 240 + * Only reinitialize corresponding vblank timestamp if high-precision query 241 + * available and didn't fail, or we were called from the vblank interrupt. 242 + * Otherwise reinitialize delayed at next vblank interrupt and assign 0 243 + * for now, to mark the vblanktimestamp as invalid. 244 + */ 245 + if (!rc && in_vblank_irq) 246 + t_vblank = (struct timeval) {0, 0}; 247 + 248 + store_vblank(dev, pipe, diff, &t_vblank, cur_vblank); 249 + } 250 + 251 + static u32 drm_vblank_count(struct drm_device *dev, unsigned int pipe) 252 + { 253 + struct drm_vblank_crtc *vblank = &dev->vblank[pipe]; 254 + 255 + if (WARN_ON(pipe >= dev->num_crtcs)) 256 + return 0; 257 + 258 + return vblank->count; 259 + } 260 + 261 + /** 262 + * drm_accurate_vblank_count - retrieve the master vblank counter 263 + * @crtc: which counter to retrieve 264 + * 265 + * This function is similar to @drm_crtc_vblank_count but this 266 + * function interpolates to handle a race with vblank irq's. 267 + * 268 + * This is mostly useful for hardware that can obtain the scanout 269 + * position, but doesn't have a frame counter. 270 + */ 271 + u32 drm_accurate_vblank_count(struct drm_crtc *crtc) 272 + { 273 + struct drm_device *dev = crtc->dev; 274 + unsigned int pipe = drm_crtc_index(crtc); 275 + u32 vblank; 276 + unsigned long flags; 277 + 278 + WARN(!dev->driver->get_vblank_timestamp, 279 + "This function requires support for accurate vblank timestamps."); 280 + 281 + spin_lock_irqsave(&dev->vblank_time_lock, flags); 282 + 283 + drm_update_vblank_count(dev, pipe, false); 284 + vblank = drm_vblank_count(dev, pipe); 285 + 286 + spin_unlock_irqrestore(&dev->vblank_time_lock, flags); 287 + 288 + return vblank; 289 + } 290 + EXPORT_SYMBOL(drm_accurate_vblank_count); 291 + 292 + static void __disable_vblank(struct drm_device *dev, unsigned int pipe) 293 + { 294 + if (drm_core_check_feature(dev, DRIVER_MODESET)) { 295 + struct drm_crtc *crtc = drm_crtc_from_index(dev, pipe); 296 + 297 + if (crtc->funcs->disable_vblank) { 298 + crtc->funcs->disable_vblank(crtc); 299 + return; 300 + } 301 + } 302 + 303 + dev->driver->disable_vblank(dev, pipe); 304 + } 305 + 306 + /* 307 + * Disable vblank irq's on crtc, make sure that last vblank count 308 + * of hardware and corresponding consistent software vblank counter 309 + * are preserved, even if there are any spurious vblank irq's after 310 + * disable. 311 + */ 312 + void drm_vblank_disable_and_save(struct drm_device *dev, unsigned int pipe) 313 + { 314 + struct drm_vblank_crtc *vblank = &dev->vblank[pipe]; 315 + unsigned long irqflags; 316 + 317 + assert_spin_locked(&dev->vbl_lock); 318 + 319 + /* Prevent vblank irq processing while disabling vblank irqs, 320 + * so no updates of timestamps or count can happen after we've 321 + * disabled. Needed to prevent races in case of delayed irq's. 322 + */ 323 + spin_lock_irqsave(&dev->vblank_time_lock, irqflags); 324 + 325 + /* 326 + * Only disable vblank interrupts if they're enabled. This avoids 327 + * calling the ->disable_vblank() operation in atomic context with the 328 + * hardware potentially runtime suspended. 329 + */ 330 + if (vblank->enabled) { 331 + __disable_vblank(dev, pipe); 332 + vblank->enabled = false; 333 + } 334 + 335 + /* 336 + * Always update the count and timestamp to maintain the 337 + * appearance that the counter has been ticking all along until 338 + * this time. This makes the count account for the entire time 339 + * between drm_crtc_vblank_on() and drm_crtc_vblank_off(). 340 + */ 341 + drm_update_vblank_count(dev, pipe, false); 342 + 343 + spin_unlock_irqrestore(&dev->vblank_time_lock, irqflags); 344 + } 345 + 346 + static void vblank_disable_fn(unsigned long arg) 347 + { 348 + struct drm_vblank_crtc *vblank = (void *)arg; 349 + struct drm_device *dev = vblank->dev; 350 + unsigned int pipe = vblank->pipe; 351 + unsigned long irqflags; 352 + 353 + spin_lock_irqsave(&dev->vbl_lock, irqflags); 354 + if (atomic_read(&vblank->refcount) == 0 && vblank->enabled) { 355 + DRM_DEBUG("disabling vblank on crtc %u\n", pipe); 356 + drm_vblank_disable_and_save(dev, pipe); 357 + } 358 + spin_unlock_irqrestore(&dev->vbl_lock, irqflags); 359 + } 360 + 361 + /** 362 + * drm_vblank_cleanup - cleanup vblank support 363 + * @dev: DRM device 364 + * 365 + * This function cleans up any resources allocated in drm_vblank_init. 366 + * 367 + * Drivers which don't use drm_irq_install() need to set &drm_device.irq_enabled 368 + * themselves, to signal to the DRM core that vblank interrupts are enabled. 369 + */ 370 + void drm_vblank_cleanup(struct drm_device *dev) 371 + { 372 + unsigned int pipe; 373 + 374 + /* Bail if the driver didn't call drm_vblank_init() */ 375 + if (dev->num_crtcs == 0) 376 + return; 377 + 378 + for (pipe = 0; pipe < dev->num_crtcs; pipe++) { 379 + struct drm_vblank_crtc *vblank = &dev->vblank[pipe]; 380 + 381 + WARN_ON(READ_ONCE(vblank->enabled) && 382 + drm_core_check_feature(dev, DRIVER_MODESET)); 383 + 384 + del_timer_sync(&vblank->disable_timer); 385 + } 386 + 387 + kfree(dev->vblank); 388 + 389 + dev->num_crtcs = 0; 390 + } 391 + EXPORT_SYMBOL(drm_vblank_cleanup); 392 + 393 + /** 394 + * drm_vblank_init - initialize vblank support 395 + * @dev: DRM device 396 + * @num_crtcs: number of CRTCs supported by @dev 397 + * 398 + * This function initializes vblank support for @num_crtcs display pipelines. 399 + * 400 + * Returns: 401 + * Zero on success or a negative error code on failure. 402 + */ 403 + int drm_vblank_init(struct drm_device *dev, unsigned int num_crtcs) 404 + { 405 + int ret = -ENOMEM; 406 + unsigned int i; 407 + 408 + spin_lock_init(&dev->vbl_lock); 409 + spin_lock_init(&dev->vblank_time_lock); 410 + 411 + dev->num_crtcs = num_crtcs; 412 + 413 + dev->vblank = kcalloc(num_crtcs, sizeof(*dev->vblank), GFP_KERNEL); 414 + if (!dev->vblank) 415 + goto err; 416 + 417 + for (i = 0; i < num_crtcs; i++) { 418 + struct drm_vblank_crtc *vblank = &dev->vblank[i]; 419 + 420 + vblank->dev = dev; 421 + vblank->pipe = i; 422 + init_waitqueue_head(&vblank->queue); 423 + setup_timer(&vblank->disable_timer, vblank_disable_fn, 424 + (unsigned long)vblank); 425 + seqlock_init(&vblank->seqlock); 426 + } 427 + 428 + DRM_INFO("Supports vblank timestamp caching Rev 2 (21.10.2013).\n"); 429 + 430 + /* Driver specific high-precision vblank timestamping supported? */ 431 + if (dev->driver->get_vblank_timestamp) 432 + DRM_INFO("Driver supports precise vblank timestamp query.\n"); 433 + else 434 + DRM_INFO("No driver support for vblank timestamp query.\n"); 435 + 436 + /* Must have precise timestamping for reliable vblank instant disable */ 437 + if (dev->vblank_disable_immediate && !dev->driver->get_vblank_timestamp) { 438 + dev->vblank_disable_immediate = false; 439 + DRM_INFO("Setting vblank_disable_immediate to false because " 440 + "get_vblank_timestamp == NULL\n"); 441 + } 442 + 443 + return 0; 444 + 445 + err: 446 + dev->num_crtcs = 0; 447 + return ret; 448 + } 449 + EXPORT_SYMBOL(drm_vblank_init); 450 + 451 + /** 452 + * drm_crtc_vblank_waitqueue - get vblank waitqueue for the CRTC 453 + * @crtc: which CRTC's vblank waitqueue to retrieve 454 + * 455 + * This function returns a pointer to the vblank waitqueue for the CRTC. 456 + * Drivers can use this to implement vblank waits using wait_event() and related 457 + * functions. 458 + */ 459 + wait_queue_head_t *drm_crtc_vblank_waitqueue(struct drm_crtc *crtc) 460 + { 461 + return &crtc->dev->vblank[drm_crtc_index(crtc)].queue; 462 + } 463 + EXPORT_SYMBOL(drm_crtc_vblank_waitqueue); 464 + 465 + 466 + /** 467 + * drm_calc_timestamping_constants - calculate vblank timestamp constants 468 + * @crtc: drm_crtc whose timestamp constants should be updated. 469 + * @mode: display mode containing the scanout timings 470 + * 471 + * Calculate and store various constants which are later 472 + * needed by vblank and swap-completion timestamping, e.g, 473 + * by drm_calc_vbltimestamp_from_scanoutpos(). They are 474 + * derived from CRTC's true scanout timing, so they take 475 + * things like panel scaling or other adjustments into account. 476 + */ 477 + void drm_calc_timestamping_constants(struct drm_crtc *crtc, 478 + const struct drm_display_mode *mode) 479 + { 480 + struct drm_device *dev = crtc->dev; 481 + unsigned int pipe = drm_crtc_index(crtc); 482 + struct drm_vblank_crtc *vblank = &dev->vblank[pipe]; 483 + int linedur_ns = 0, framedur_ns = 0; 484 + int dotclock = mode->crtc_clock; 485 + 486 + if (!dev->num_crtcs) 487 + return; 488 + 489 + if (WARN_ON(pipe >= dev->num_crtcs)) 490 + return; 491 + 492 + /* Valid dotclock? */ 493 + if (dotclock > 0) { 494 + int frame_size = mode->crtc_htotal * mode->crtc_vtotal; 495 + 496 + /* 497 + * Convert scanline length in pixels and video 498 + * dot clock to line duration and frame duration 499 + * in nanoseconds: 500 + */ 501 + linedur_ns = div_u64((u64) mode->crtc_htotal * 1000000, dotclock); 502 + framedur_ns = div_u64((u64) frame_size * 1000000, dotclock); 503 + 504 + /* 505 + * Fields of interlaced scanout modes are only half a frame duration. 506 + */ 507 + if (mode->flags & DRM_MODE_FLAG_INTERLACE) 508 + framedur_ns /= 2; 509 + } else 510 + DRM_ERROR("crtc %u: Can't calculate constants, dotclock = 0!\n", 511 + crtc->base.id); 512 + 513 + vblank->linedur_ns = linedur_ns; 514 + vblank->framedur_ns = framedur_ns; 515 + vblank->hwmode = *mode; 516 + 517 + DRM_DEBUG("crtc %u: hwmode: htotal %d, vtotal %d, vdisplay %d\n", 518 + crtc->base.id, mode->crtc_htotal, 519 + mode->crtc_vtotal, mode->crtc_vdisplay); 520 + DRM_DEBUG("crtc %u: clock %d kHz framedur %d linedur %d\n", 521 + crtc->base.id, dotclock, framedur_ns, linedur_ns); 522 + } 523 + EXPORT_SYMBOL(drm_calc_timestamping_constants); 524 + 525 + /** 526 + * drm_calc_vbltimestamp_from_scanoutpos - precise vblank timestamp helper 527 + * @dev: DRM device 528 + * @pipe: index of CRTC whose vblank timestamp to retrieve 529 + * @max_error: Desired maximum allowable error in timestamps (nanosecs) 530 + * On return contains true maximum error of timestamp 531 + * @vblank_time: Pointer to struct timeval which should receive the timestamp 532 + * @in_vblank_irq: 533 + * True when called from drm_crtc_handle_vblank(). Some drivers 534 + * need to apply some workarounds for gpu-specific vblank irq quirks 535 + * if flag is set. 536 + * 537 + * Implements calculation of exact vblank timestamps from given drm_display_mode 538 + * timings and current video scanout position of a CRTC. This can be called from 539 + * within get_vblank_timestamp() implementation of a kms driver to implement the 540 + * actual timestamping. 541 + * 542 + * Should return timestamps conforming to the OML_sync_control OpenML 543 + * extension specification. The timestamp corresponds to the end of 544 + * the vblank interval, aka start of scanout of topmost-leftmost display 545 + * pixel in the following video frame. 546 + * 547 + * Requires support for optional dev->driver->get_scanout_position() 548 + * in kms driver, plus a bit of setup code to provide a drm_display_mode 549 + * that corresponds to the true scanout timing. 550 + * 551 + * The current implementation only handles standard video modes. It 552 + * returns as no operation if a doublescan or interlaced video mode is 553 + * active. Higher level code is expected to handle this. 554 + * 555 + * This function can be used to implement the &drm_driver.get_vblank_timestamp 556 + * directly, if the driver implements the &drm_driver.get_scanout_position hook. 557 + * 558 + * Note that atomic drivers must call drm_calc_timestamping_constants() before 559 + * enabling a CRTC. The atomic helpers already take care of that in 560 + * drm_atomic_helper_update_legacy_modeset_state(). 561 + * 562 + * Returns: 563 + * 564 + * Returns true on success, and false on failure, i.e. when no accurate 565 + * timestamp could be acquired. 566 + */ 567 + bool drm_calc_vbltimestamp_from_scanoutpos(struct drm_device *dev, 568 + unsigned int pipe, 569 + int *max_error, 570 + struct timeval *vblank_time, 571 + bool in_vblank_irq) 572 + { 573 + struct timeval tv_etime; 574 + ktime_t stime, etime; 575 + bool vbl_status; 576 + struct drm_crtc *crtc; 577 + const struct drm_display_mode *mode; 578 + struct drm_vblank_crtc *vblank = &dev->vblank[pipe]; 579 + int vpos, hpos, i; 580 + int delta_ns, duration_ns; 581 + 582 + if (!drm_core_check_feature(dev, DRIVER_MODESET)) 583 + return false; 584 + 585 + crtc = drm_crtc_from_index(dev, pipe); 586 + 587 + if (pipe >= dev->num_crtcs || !crtc) { 588 + DRM_ERROR("Invalid crtc %u\n", pipe); 589 + return false; 590 + } 591 + 592 + /* Scanout position query not supported? Should not happen. */ 593 + if (!dev->driver->get_scanout_position) { 594 + DRM_ERROR("Called from driver w/o get_scanout_position()!?\n"); 595 + return false; 596 + } 597 + 598 + if (drm_drv_uses_atomic_modeset(dev)) 599 + mode = &vblank->hwmode; 600 + else 601 + mode = &crtc->hwmode; 602 + 603 + /* If mode timing undefined, just return as no-op: 604 + * Happens during initial modesetting of a crtc. 605 + */ 606 + if (mode->crtc_clock == 0) { 607 + DRM_DEBUG("crtc %u: Noop due to uninitialized mode.\n", pipe); 608 + WARN_ON_ONCE(drm_drv_uses_atomic_modeset(dev)); 609 + 610 + return false; 611 + } 612 + 613 + /* Get current scanout position with system timestamp. 614 + * Repeat query up to DRM_TIMESTAMP_MAXRETRIES times 615 + * if single query takes longer than max_error nanoseconds. 616 + * 617 + * This guarantees a tight bound on maximum error if 618 + * code gets preempted or delayed for some reason. 619 + */ 620 + for (i = 0; i < DRM_TIMESTAMP_MAXRETRIES; i++) { 621 + /* 622 + * Get vertical and horizontal scanout position vpos, hpos, 623 + * and bounding timestamps stime, etime, pre/post query. 624 + */ 625 + vbl_status = dev->driver->get_scanout_position(dev, pipe, 626 + in_vblank_irq, 627 + &vpos, &hpos, 628 + &stime, &etime, 629 + mode); 630 + 631 + /* Return as no-op if scanout query unsupported or failed. */ 632 + if (!vbl_status) { 633 + DRM_DEBUG("crtc %u : scanoutpos query failed.\n", 634 + pipe); 635 + return false; 636 + } 637 + 638 + /* Compute uncertainty in timestamp of scanout position query. */ 639 + duration_ns = ktime_to_ns(etime) - ktime_to_ns(stime); 640 + 641 + /* Accept result with < max_error nsecs timing uncertainty. */ 642 + if (duration_ns <= *max_error) 643 + break; 644 + } 645 + 646 + /* Noisy system timing? */ 647 + if (i == DRM_TIMESTAMP_MAXRETRIES) { 648 + DRM_DEBUG("crtc %u: Noisy timestamp %d us > %d us [%d reps].\n", 649 + pipe, duration_ns/1000, *max_error/1000, i); 650 + } 651 + 652 + /* Return upper bound of timestamp precision error. */ 653 + *max_error = duration_ns; 654 + 655 + /* Convert scanout position into elapsed time at raw_time query 656 + * since start of scanout at first display scanline. delta_ns 657 + * can be negative if start of scanout hasn't happened yet. 658 + */ 659 + delta_ns = div_s64(1000000LL * (vpos * mode->crtc_htotal + hpos), 660 + mode->crtc_clock); 661 + 662 + if (!drm_timestamp_monotonic) 663 + etime = ktime_mono_to_real(etime); 664 + 665 + /* save this only for debugging purposes */ 666 + tv_etime = ktime_to_timeval(etime); 667 + /* Subtract time delta from raw timestamp to get final 668 + * vblank_time timestamp for end of vblank. 669 + */ 670 + etime = ktime_sub_ns(etime, delta_ns); 671 + *vblank_time = ktime_to_timeval(etime); 672 + 673 + DRM_DEBUG_VBL("crtc %u : v p(%d,%d)@ %ld.%ld -> %ld.%ld [e %d us, %d rep]\n", 674 + pipe, hpos, vpos, 675 + (long)tv_etime.tv_sec, (long)tv_etime.tv_usec, 676 + (long)vblank_time->tv_sec, (long)vblank_time->tv_usec, 677 + duration_ns/1000, i); 678 + 679 + return true; 680 + } 681 + EXPORT_SYMBOL(drm_calc_vbltimestamp_from_scanoutpos); 682 + 683 + static struct timeval get_drm_timestamp(void) 684 + { 685 + ktime_t now; 686 + 687 + now = drm_timestamp_monotonic ? ktime_get() : ktime_get_real(); 688 + return ktime_to_timeval(now); 689 + } 690 + 691 + /** 692 + * drm_get_last_vbltimestamp - retrieve raw timestamp for the most recent 693 + * vblank interval 694 + * @dev: DRM device 695 + * @pipe: index of CRTC whose vblank timestamp to retrieve 696 + * @tvblank: Pointer to target struct timeval which should receive the timestamp 697 + * @in_vblank_irq: 698 + * True when called from drm_crtc_handle_vblank(). Some drivers 699 + * need to apply some workarounds for gpu-specific vblank irq quirks 700 + * if flag is set. 701 + * 702 + * Fetches the system timestamp corresponding to the time of the most recent 703 + * vblank interval on specified CRTC. May call into kms-driver to 704 + * compute the timestamp with a high-precision GPU specific method. 705 + * 706 + * Returns zero if timestamp originates from uncorrected do_gettimeofday() 707 + * call, i.e., it isn't very precisely locked to the true vblank. 708 + * 709 + * Returns: 710 + * True if timestamp is considered to be very precise, false otherwise. 711 + */ 712 + static bool 713 + drm_get_last_vbltimestamp(struct drm_device *dev, unsigned int pipe, 714 + struct timeval *tvblank, bool in_vblank_irq) 715 + { 716 + bool ret = false; 717 + 718 + /* Define requested maximum error on timestamps (nanoseconds). */ 719 + int max_error = (int) drm_timestamp_precision * 1000; 720 + 721 + /* Query driver if possible and precision timestamping enabled. */ 722 + if (dev->driver->get_vblank_timestamp && (max_error > 0)) 723 + ret = dev->driver->get_vblank_timestamp(dev, pipe, &max_error, 724 + tvblank, in_vblank_irq); 725 + 726 + /* GPU high precision timestamp query unsupported or failed. 727 + * Return current monotonic/gettimeofday timestamp as best estimate. 728 + */ 729 + if (!ret) 730 + *tvblank = get_drm_timestamp(); 731 + 732 + return ret; 733 + } 734 + 735 + /** 736 + * drm_crtc_vblank_count - retrieve "cooked" vblank counter value 737 + * @crtc: which counter to retrieve 738 + * 739 + * Fetches the "cooked" vblank count value that represents the number of 740 + * vblank events since the system was booted, including lost events due to 741 + * modesetting activity. 742 + * 743 + * Returns: 744 + * The software vblank counter. 745 + */ 746 + u32 drm_crtc_vblank_count(struct drm_crtc *crtc) 747 + { 748 + return drm_vblank_count(crtc->dev, drm_crtc_index(crtc)); 749 + } 750 + EXPORT_SYMBOL(drm_crtc_vblank_count); 751 + 752 + /** 753 + * drm_vblank_count_and_time - retrieve "cooked" vblank counter value and the 754 + * system timestamp corresponding to that vblank counter value. 755 + * @dev: DRM device 756 + * @pipe: index of CRTC whose counter to retrieve 757 + * @vblanktime: Pointer to struct timeval to receive the vblank timestamp. 758 + * 759 + * Fetches the "cooked" vblank count value that represents the number of 760 + * vblank events since the system was booted, including lost events due to 761 + * modesetting activity. Returns corresponding system timestamp of the time 762 + * of the vblank interval that corresponds to the current vblank counter value. 763 + * 764 + * This is the legacy version of drm_crtc_vblank_count_and_time(). 765 + */ 766 + static u32 drm_vblank_count_and_time(struct drm_device *dev, unsigned int pipe, 767 + struct timeval *vblanktime) 768 + { 769 + struct drm_vblank_crtc *vblank = &dev->vblank[pipe]; 770 + u32 vblank_count; 771 + unsigned int seq; 772 + 773 + if (WARN_ON(pipe >= dev->num_crtcs)) { 774 + *vblanktime = (struct timeval) { 0 }; 775 + return 0; 776 + } 777 + 778 + do { 779 + seq = read_seqbegin(&vblank->seqlock); 780 + vblank_count = vblank->count; 781 + *vblanktime = vblank->time; 782 + } while (read_seqretry(&vblank->seqlock, seq)); 783 + 784 + return vblank_count; 785 + } 786 + 787 + /** 788 + * drm_crtc_vblank_count_and_time - retrieve "cooked" vblank counter value 789 + * and the system timestamp corresponding to that vblank counter value 790 + * @crtc: which counter to retrieve 791 + * @vblanktime: Pointer to struct timeval to receive the vblank timestamp. 792 + * 793 + * Fetches the "cooked" vblank count value that represents the number of 794 + * vblank events since the system was booted, including lost events due to 795 + * modesetting activity. Returns corresponding system timestamp of the time 796 + * of the vblank interval that corresponds to the current vblank counter value. 797 + */ 798 + u32 drm_crtc_vblank_count_and_time(struct drm_crtc *crtc, 799 + struct timeval *vblanktime) 800 + { 801 + return drm_vblank_count_and_time(crtc->dev, drm_crtc_index(crtc), 802 + vblanktime); 803 + } 804 + EXPORT_SYMBOL(drm_crtc_vblank_count_and_time); 805 + 806 + static void send_vblank_event(struct drm_device *dev, 807 + struct drm_pending_vblank_event *e, 808 + unsigned long seq, struct timeval *now) 809 + { 810 + e->event.sequence = seq; 811 + e->event.tv_sec = now->tv_sec; 812 + e->event.tv_usec = now->tv_usec; 813 + 814 + trace_drm_vblank_event_delivered(e->base.file_priv, e->pipe, 815 + e->event.sequence); 816 + 817 + drm_send_event_locked(dev, &e->base); 818 + } 819 + 820 + /** 821 + * drm_crtc_arm_vblank_event - arm vblank event after pageflip 822 + * @crtc: the source CRTC of the vblank event 823 + * @e: the event to send 824 + * 825 + * A lot of drivers need to generate vblank events for the very next vblank 826 + * interrupt. For example when the page flip interrupt happens when the page 827 + * flip gets armed, but not when it actually executes within the next vblank 828 + * period. This helper function implements exactly the required vblank arming 829 + * behaviour. 830 + * 831 + * NOTE: Drivers using this to send out the &drm_crtc_state.event as part of an 832 + * atomic commit must ensure that the next vblank happens at exactly the same 833 + * time as the atomic commit is committed to the hardware. This function itself 834 + * does **not** protect again the next vblank interrupt racing with either this 835 + * function call or the atomic commit operation. A possible sequence could be: 836 + * 837 + * 1. Driver commits new hardware state into vblank-synchronized registers. 838 + * 2. A vblank happens, committing the hardware state. Also the corresponding 839 + * vblank interrupt is fired off and fully processed by the interrupt 840 + * handler. 841 + * 3. The atomic commit operation proceeds to call drm_crtc_arm_vblank_event(). 842 + * 4. The event is only send out for the next vblank, which is wrong. 843 + * 844 + * An equivalent race can happen when the driver calls 845 + * drm_crtc_arm_vblank_event() before writing out the new hardware state. 846 + * 847 + * The only way to make this work safely is to prevent the vblank from firing 848 + * (and the hardware from committing anything else) until the entire atomic 849 + * commit sequence has run to completion. If the hardware does not have such a 850 + * feature (e.g. using a "go" bit), then it is unsafe to use this functions. 851 + * Instead drivers need to manually send out the event from their interrupt 852 + * handler by calling drm_crtc_send_vblank_event() and make sure that there's no 853 + * possible race with the hardware committing the atomic update. 854 + * 855 + * Caller must hold event lock. Caller must also hold a vblank reference for 856 + * the event @e, which will be dropped when the next vblank arrives. 857 + */ 858 + void drm_crtc_arm_vblank_event(struct drm_crtc *crtc, 859 + struct drm_pending_vblank_event *e) 860 + { 861 + struct drm_device *dev = crtc->dev; 862 + unsigned int pipe = drm_crtc_index(crtc); 863 + 864 + assert_spin_locked(&dev->event_lock); 865 + 866 + e->pipe = pipe; 867 + e->event.sequence = drm_vblank_count(dev, pipe); 868 + e->event.crtc_id = crtc->base.id; 869 + list_add_tail(&e->base.link, &dev->vblank_event_list); 870 + } 871 + EXPORT_SYMBOL(drm_crtc_arm_vblank_event); 872 + 873 + /** 874 + * drm_crtc_send_vblank_event - helper to send vblank event after pageflip 875 + * @crtc: the source CRTC of the vblank event 876 + * @e: the event to send 877 + * 878 + * Updates sequence # and timestamp on event for the most recently processed 879 + * vblank, and sends it to userspace. Caller must hold event lock. 880 + * 881 + * See drm_crtc_arm_vblank_event() for a helper which can be used in certain 882 + * situation, especially to send out events for atomic commit operations. 883 + */ 884 + void drm_crtc_send_vblank_event(struct drm_crtc *crtc, 885 + struct drm_pending_vblank_event *e) 886 + { 887 + struct drm_device *dev = crtc->dev; 888 + unsigned int seq, pipe = drm_crtc_index(crtc); 889 + struct timeval now; 890 + 891 + if (dev->num_crtcs > 0) { 892 + seq = drm_vblank_count_and_time(dev, pipe, &now); 893 + } else { 894 + seq = 0; 895 + 896 + now = get_drm_timestamp(); 897 + } 898 + e->pipe = pipe; 899 + e->event.crtc_id = crtc->base.id; 900 + send_vblank_event(dev, e, seq, &now); 901 + } 902 + EXPORT_SYMBOL(drm_crtc_send_vblank_event); 903 + 904 + static int __enable_vblank(struct drm_device *dev, unsigned int pipe) 905 + { 906 + if (drm_core_check_feature(dev, DRIVER_MODESET)) { 907 + struct drm_crtc *crtc = drm_crtc_from_index(dev, pipe); 908 + 909 + if (crtc->funcs->enable_vblank) 910 + return crtc->funcs->enable_vblank(crtc); 911 + } 912 + 913 + return dev->driver->enable_vblank(dev, pipe); 914 + } 915 + 916 + /** 917 + * drm_vblank_enable - enable the vblank interrupt on a CRTC 918 + * @dev: DRM device 919 + * @pipe: CRTC index 920 + * 921 + * Returns: 922 + * Zero on success or a negative error code on failure. 923 + */ 924 + static int drm_vblank_enable(struct drm_device *dev, unsigned int pipe) 925 + { 926 + struct drm_vblank_crtc *vblank = &dev->vblank[pipe]; 927 + int ret = 0; 928 + 929 + assert_spin_locked(&dev->vbl_lock); 930 + 931 + spin_lock(&dev->vblank_time_lock); 932 + 933 + if (!vblank->enabled) { 934 + /* 935 + * Enable vblank irqs under vblank_time_lock protection. 936 + * All vblank count & timestamp updates are held off 937 + * until we are done reinitializing master counter and 938 + * timestamps. Filtercode in drm_handle_vblank() will 939 + * prevent double-accounting of same vblank interval. 940 + */ 941 + ret = __enable_vblank(dev, pipe); 942 + DRM_DEBUG("enabling vblank on crtc %u, ret: %d\n", pipe, ret); 943 + if (ret) { 944 + atomic_dec(&vblank->refcount); 945 + } else { 946 + drm_update_vblank_count(dev, pipe, 0); 947 + /* drm_update_vblank_count() includes a wmb so we just 948 + * need to ensure that the compiler emits the write 949 + * to mark the vblank as enabled after the call 950 + * to drm_update_vblank_count(). 951 + */ 952 + WRITE_ONCE(vblank->enabled, true); 953 + } 954 + } 955 + 956 + spin_unlock(&dev->vblank_time_lock); 957 + 958 + return ret; 959 + } 960 + 961 + /** 962 + * drm_vblank_get - get a reference count on vblank events 963 + * @dev: DRM device 964 + * @pipe: index of CRTC to own 965 + * 966 + * Acquire a reference count on vblank events to avoid having them disabled 967 + * while in use. 968 + * 969 + * This is the legacy version of drm_crtc_vblank_get(). 970 + * 971 + * Returns: 972 + * Zero on success or a negative error code on failure. 973 + */ 974 + static int drm_vblank_get(struct drm_device *dev, unsigned int pipe) 975 + { 976 + struct drm_vblank_crtc *vblank = &dev->vblank[pipe]; 977 + unsigned long irqflags; 978 + int ret = 0; 979 + 980 + if (!dev->num_crtcs) 981 + return -EINVAL; 982 + 983 + if (WARN_ON(pipe >= dev->num_crtcs)) 984 + return -EINVAL; 985 + 986 + spin_lock_irqsave(&dev->vbl_lock, irqflags); 987 + /* Going from 0->1 means we have to enable interrupts again */ 988 + if (atomic_add_return(1, &vblank->refcount) == 1) { 989 + ret = drm_vblank_enable(dev, pipe); 990 + } else { 991 + if (!vblank->enabled) { 992 + atomic_dec(&vblank->refcount); 993 + ret = -EINVAL; 994 + } 995 + } 996 + spin_unlock_irqrestore(&dev->vbl_lock, irqflags); 997 + 998 + return ret; 999 + } 1000 + 1001 + /** 1002 + * drm_crtc_vblank_get - get a reference count on vblank events 1003 + * @crtc: which CRTC to own 1004 + * 1005 + * Acquire a reference count on vblank events to avoid having them disabled 1006 + * while in use. 1007 + * 1008 + * Returns: 1009 + * Zero on success or a negative error code on failure. 1010 + */ 1011 + int drm_crtc_vblank_get(struct drm_crtc *crtc) 1012 + { 1013 + return drm_vblank_get(crtc->dev, drm_crtc_index(crtc)); 1014 + } 1015 + EXPORT_SYMBOL(drm_crtc_vblank_get); 1016 + 1017 + /** 1018 + * drm_vblank_put - release ownership of vblank events 1019 + * @dev: DRM device 1020 + * @pipe: index of CRTC to release 1021 + * 1022 + * Release ownership of a given vblank counter, turning off interrupts 1023 + * if possible. Disable interrupts after drm_vblank_offdelay milliseconds. 1024 + * 1025 + * This is the legacy version of drm_crtc_vblank_put(). 1026 + */ 1027 + static void drm_vblank_put(struct drm_device *dev, unsigned int pipe) 1028 + { 1029 + struct drm_vblank_crtc *vblank = &dev->vblank[pipe]; 1030 + 1031 + if (WARN_ON(pipe >= dev->num_crtcs)) 1032 + return; 1033 + 1034 + if (WARN_ON(atomic_read(&vblank->refcount) == 0)) 1035 + return; 1036 + 1037 + /* Last user schedules interrupt disable */ 1038 + if (atomic_dec_and_test(&vblank->refcount)) { 1039 + if (drm_vblank_offdelay == 0) 1040 + return; 1041 + else if (drm_vblank_offdelay < 0) 1042 + vblank_disable_fn((unsigned long)vblank); 1043 + else if (!dev->vblank_disable_immediate) 1044 + mod_timer(&vblank->disable_timer, 1045 + jiffies + ((drm_vblank_offdelay * HZ)/1000)); 1046 + } 1047 + } 1048 + 1049 + /** 1050 + * drm_crtc_vblank_put - give up ownership of vblank events 1051 + * @crtc: which counter to give up 1052 + * 1053 + * Release ownership of a given vblank counter, turning off interrupts 1054 + * if possible. Disable interrupts after drm_vblank_offdelay milliseconds. 1055 + */ 1056 + void drm_crtc_vblank_put(struct drm_crtc *crtc) 1057 + { 1058 + drm_vblank_put(crtc->dev, drm_crtc_index(crtc)); 1059 + } 1060 + EXPORT_SYMBOL(drm_crtc_vblank_put); 1061 + 1062 + /** 1063 + * drm_wait_one_vblank - wait for one vblank 1064 + * @dev: DRM device 1065 + * @pipe: CRTC index 1066 + * 1067 + * This waits for one vblank to pass on @pipe, using the irq driver interfaces. 1068 + * It is a failure to call this when the vblank irq for @pipe is disabled, e.g. 1069 + * due to lack of driver support or because the crtc is off. 1070 + */ 1071 + void drm_wait_one_vblank(struct drm_device *dev, unsigned int pipe) 1072 + { 1073 + struct drm_vblank_crtc *vblank = &dev->vblank[pipe]; 1074 + int ret; 1075 + u32 last; 1076 + 1077 + if (WARN_ON(pipe >= dev->num_crtcs)) 1078 + return; 1079 + 1080 + ret = drm_vblank_get(dev, pipe); 1081 + if (WARN(ret, "vblank not available on crtc %i, ret=%i\n", pipe, ret)) 1082 + return; 1083 + 1084 + last = drm_vblank_count(dev, pipe); 1085 + 1086 + ret = wait_event_timeout(vblank->queue, 1087 + last != drm_vblank_count(dev, pipe), 1088 + msecs_to_jiffies(100)); 1089 + 1090 + WARN(ret == 0, "vblank wait timed out on crtc %i\n", pipe); 1091 + 1092 + drm_vblank_put(dev, pipe); 1093 + } 1094 + EXPORT_SYMBOL(drm_wait_one_vblank); 1095 + 1096 + /** 1097 + * drm_crtc_wait_one_vblank - wait for one vblank 1098 + * @crtc: DRM crtc 1099 + * 1100 + * This waits for one vblank to pass on @crtc, using the irq driver interfaces. 1101 + * It is a failure to call this when the vblank irq for @crtc is disabled, e.g. 1102 + * due to lack of driver support or because the crtc is off. 1103 + */ 1104 + void drm_crtc_wait_one_vblank(struct drm_crtc *crtc) 1105 + { 1106 + drm_wait_one_vblank(crtc->dev, drm_crtc_index(crtc)); 1107 + } 1108 + EXPORT_SYMBOL(drm_crtc_wait_one_vblank); 1109 + 1110 + /** 1111 + * drm_crtc_vblank_off - disable vblank events on a CRTC 1112 + * @crtc: CRTC in question 1113 + * 1114 + * Drivers can use this function to shut down the vblank interrupt handling when 1115 + * disabling a crtc. This function ensures that the latest vblank frame count is 1116 + * stored so that drm_vblank_on can restore it again. 1117 + * 1118 + * Drivers must use this function when the hardware vblank counter can get 1119 + * reset, e.g. when suspending. 1120 + */ 1121 + void drm_crtc_vblank_off(struct drm_crtc *crtc) 1122 + { 1123 + struct drm_device *dev = crtc->dev; 1124 + unsigned int pipe = drm_crtc_index(crtc); 1125 + struct drm_vblank_crtc *vblank = &dev->vblank[pipe]; 1126 + struct drm_pending_vblank_event *e, *t; 1127 + struct timeval now; 1128 + unsigned long irqflags; 1129 + unsigned int seq; 1130 + 1131 + if (WARN_ON(pipe >= dev->num_crtcs)) 1132 + return; 1133 + 1134 + spin_lock_irqsave(&dev->event_lock, irqflags); 1135 + 1136 + spin_lock(&dev->vbl_lock); 1137 + DRM_DEBUG_VBL("crtc %d, vblank enabled %d, inmodeset %d\n", 1138 + pipe, vblank->enabled, vblank->inmodeset); 1139 + 1140 + /* Avoid redundant vblank disables without previous 1141 + * drm_crtc_vblank_on(). */ 1142 + if (drm_core_check_feature(dev, DRIVER_ATOMIC) || !vblank->inmodeset) 1143 + drm_vblank_disable_and_save(dev, pipe); 1144 + 1145 + wake_up(&vblank->queue); 1146 + 1147 + /* 1148 + * Prevent subsequent drm_vblank_get() from re-enabling 1149 + * the vblank interrupt by bumping the refcount. 1150 + */ 1151 + if (!vblank->inmodeset) { 1152 + atomic_inc(&vblank->refcount); 1153 + vblank->inmodeset = 1; 1154 + } 1155 + spin_unlock(&dev->vbl_lock); 1156 + 1157 + /* Send any queued vblank events, lest the natives grow disquiet */ 1158 + seq = drm_vblank_count_and_time(dev, pipe, &now); 1159 + 1160 + list_for_each_entry_safe(e, t, &dev->vblank_event_list, base.link) { 1161 + if (e->pipe != pipe) 1162 + continue; 1163 + DRM_DEBUG("Sending premature vblank event on disable: " 1164 + "wanted %u, current %u\n", 1165 + e->event.sequence, seq); 1166 + list_del(&e->base.link); 1167 + drm_vblank_put(dev, pipe); 1168 + send_vblank_event(dev, e, seq, &now); 1169 + } 1170 + spin_unlock_irqrestore(&dev->event_lock, irqflags); 1171 + 1172 + /* Will be reset by the modeset helpers when re-enabling the crtc by 1173 + * calling drm_calc_timestamping_constants(). */ 1174 + vblank->hwmode.crtc_clock = 0; 1175 + } 1176 + EXPORT_SYMBOL(drm_crtc_vblank_off); 1177 + 1178 + /** 1179 + * drm_crtc_vblank_reset - reset vblank state to off on a CRTC 1180 + * @crtc: CRTC in question 1181 + * 1182 + * Drivers can use this function to reset the vblank state to off at load time. 1183 + * Drivers should use this together with the drm_crtc_vblank_off() and 1184 + * drm_crtc_vblank_on() functions. The difference compared to 1185 + * drm_crtc_vblank_off() is that this function doesn't save the vblank counter 1186 + * and hence doesn't need to call any driver hooks. 1187 + */ 1188 + void drm_crtc_vblank_reset(struct drm_crtc *crtc) 1189 + { 1190 + struct drm_device *dev = crtc->dev; 1191 + unsigned long irqflags; 1192 + unsigned int pipe = drm_crtc_index(crtc); 1193 + struct drm_vblank_crtc *vblank = &dev->vblank[pipe]; 1194 + 1195 + spin_lock_irqsave(&dev->vbl_lock, irqflags); 1196 + /* 1197 + * Prevent subsequent drm_vblank_get() from enabling the vblank 1198 + * interrupt by bumping the refcount. 1199 + */ 1200 + if (!vblank->inmodeset) { 1201 + atomic_inc(&vblank->refcount); 1202 + vblank->inmodeset = 1; 1203 + } 1204 + spin_unlock_irqrestore(&dev->vbl_lock, irqflags); 1205 + 1206 + WARN_ON(!list_empty(&dev->vblank_event_list)); 1207 + } 1208 + EXPORT_SYMBOL(drm_crtc_vblank_reset); 1209 + 1210 + /** 1211 + * drm_crtc_vblank_on - enable vblank events on a CRTC 1212 + * @crtc: CRTC in question 1213 + * 1214 + * This functions restores the vblank interrupt state captured with 1215 + * drm_crtc_vblank_off() again. Note that calls to drm_crtc_vblank_on() and 1216 + * drm_crtc_vblank_off() can be unbalanced and so can also be unconditionally called 1217 + * in driver load code to reflect the current hardware state of the crtc. 1218 + */ 1219 + void drm_crtc_vblank_on(struct drm_crtc *crtc) 1220 + { 1221 + struct drm_device *dev = crtc->dev; 1222 + unsigned int pipe = drm_crtc_index(crtc); 1223 + struct drm_vblank_crtc *vblank = &dev->vblank[pipe]; 1224 + unsigned long irqflags; 1225 + 1226 + if (WARN_ON(pipe >= dev->num_crtcs)) 1227 + return; 1228 + 1229 + spin_lock_irqsave(&dev->vbl_lock, irqflags); 1230 + DRM_DEBUG_VBL("crtc %d, vblank enabled %d, inmodeset %d\n", 1231 + pipe, vblank->enabled, vblank->inmodeset); 1232 + 1233 + /* Drop our private "prevent drm_vblank_get" refcount */ 1234 + if (vblank->inmodeset) { 1235 + atomic_dec(&vblank->refcount); 1236 + vblank->inmodeset = 0; 1237 + } 1238 + 1239 + drm_reset_vblank_timestamp(dev, pipe); 1240 + 1241 + /* 1242 + * re-enable interrupts if there are users left, or the 1243 + * user wishes vblank interrupts to be enabled all the time. 1244 + */ 1245 + if (atomic_read(&vblank->refcount) != 0 || drm_vblank_offdelay == 0) 1246 + WARN_ON(drm_vblank_enable(dev, pipe)); 1247 + spin_unlock_irqrestore(&dev->vbl_lock, irqflags); 1248 + } 1249 + EXPORT_SYMBOL(drm_crtc_vblank_on); 1250 + 1251 + static void drm_legacy_vblank_pre_modeset(struct drm_device *dev, 1252 + unsigned int pipe) 1253 + { 1254 + struct drm_vblank_crtc *vblank = &dev->vblank[pipe]; 1255 + 1256 + /* vblank is not initialized (IRQ not installed ?), or has been freed */ 1257 + if (!dev->num_crtcs) 1258 + return; 1259 + 1260 + if (WARN_ON(pipe >= dev->num_crtcs)) 1261 + return; 1262 + 1263 + /* 1264 + * To avoid all the problems that might happen if interrupts 1265 + * were enabled/disabled around or between these calls, we just 1266 + * have the kernel take a reference on the CRTC (just once though 1267 + * to avoid corrupting the count if multiple, mismatch calls occur), 1268 + * so that interrupts remain enabled in the interim. 1269 + */ 1270 + if (!vblank->inmodeset) { 1271 + vblank->inmodeset = 0x1; 1272 + if (drm_vblank_get(dev, pipe) == 0) 1273 + vblank->inmodeset |= 0x2; 1274 + } 1275 + } 1276 + 1277 + static void drm_legacy_vblank_post_modeset(struct drm_device *dev, 1278 + unsigned int pipe) 1279 + { 1280 + struct drm_vblank_crtc *vblank = &dev->vblank[pipe]; 1281 + unsigned long irqflags; 1282 + 1283 + /* vblank is not initialized (IRQ not installed ?), or has been freed */ 1284 + if (!dev->num_crtcs) 1285 + return; 1286 + 1287 + if (WARN_ON(pipe >= dev->num_crtcs)) 1288 + return; 1289 + 1290 + if (vblank->inmodeset) { 1291 + spin_lock_irqsave(&dev->vbl_lock, irqflags); 1292 + drm_reset_vblank_timestamp(dev, pipe); 1293 + spin_unlock_irqrestore(&dev->vbl_lock, irqflags); 1294 + 1295 + if (vblank->inmodeset & 0x2) 1296 + drm_vblank_put(dev, pipe); 1297 + 1298 + vblank->inmodeset = 0; 1299 + } 1300 + } 1301 + 1302 + int drm_legacy_modeset_ctl(struct drm_device *dev, void *data, 1303 + struct drm_file *file_priv) 1304 + { 1305 + struct drm_modeset_ctl *modeset = data; 1306 + unsigned int pipe; 1307 + 1308 + /* If drm_vblank_init() hasn't been called yet, just no-op */ 1309 + if (!dev->num_crtcs) 1310 + return 0; 1311 + 1312 + /* KMS drivers handle this internally */ 1313 + if (!drm_core_check_feature(dev, DRIVER_LEGACY)) 1314 + return 0; 1315 + 1316 + pipe = modeset->crtc; 1317 + if (pipe >= dev->num_crtcs) 1318 + return -EINVAL; 1319 + 1320 + switch (modeset->cmd) { 1321 + case _DRM_PRE_MODESET: 1322 + drm_legacy_vblank_pre_modeset(dev, pipe); 1323 + break; 1324 + case _DRM_POST_MODESET: 1325 + drm_legacy_vblank_post_modeset(dev, pipe); 1326 + break; 1327 + default: 1328 + return -EINVAL; 1329 + } 1330 + 1331 + return 0; 1332 + } 1333 + 1334 + static inline bool vblank_passed(u32 seq, u32 ref) 1335 + { 1336 + return (seq - ref) <= (1 << 23); 1337 + } 1338 + 1339 + static int drm_queue_vblank_event(struct drm_device *dev, unsigned int pipe, 1340 + union drm_wait_vblank *vblwait, 1341 + struct drm_file *file_priv) 1342 + { 1343 + struct drm_vblank_crtc *vblank = &dev->vblank[pipe]; 1344 + struct drm_pending_vblank_event *e; 1345 + struct timeval now; 1346 + unsigned long flags; 1347 + unsigned int seq; 1348 + int ret; 1349 + 1350 + e = kzalloc(sizeof(*e), GFP_KERNEL); 1351 + if (e == NULL) { 1352 + ret = -ENOMEM; 1353 + goto err_put; 1354 + } 1355 + 1356 + e->pipe = pipe; 1357 + e->event.base.type = DRM_EVENT_VBLANK; 1358 + e->event.base.length = sizeof(e->event); 1359 + e->event.user_data = vblwait->request.signal; 1360 + 1361 + spin_lock_irqsave(&dev->event_lock, flags); 1362 + 1363 + /* 1364 + * drm_crtc_vblank_off() might have been called after we called 1365 + * drm_vblank_get(). drm_crtc_vblank_off() holds event_lock around the 1366 + * vblank disable, so no need for further locking. The reference from 1367 + * drm_vblank_get() protects against vblank disable from another source. 1368 + */ 1369 + if (!READ_ONCE(vblank->enabled)) { 1370 + ret = -EINVAL; 1371 + goto err_unlock; 1372 + } 1373 + 1374 + ret = drm_event_reserve_init_locked(dev, file_priv, &e->base, 1375 + &e->event.base); 1376 + 1377 + if (ret) 1378 + goto err_unlock; 1379 + 1380 + seq = drm_vblank_count_and_time(dev, pipe, &now); 1381 + 1382 + DRM_DEBUG("event on vblank count %u, current %u, crtc %u\n", 1383 + vblwait->request.sequence, seq, pipe); 1384 + 1385 + trace_drm_vblank_event_queued(file_priv, pipe, 1386 + vblwait->request.sequence); 1387 + 1388 + e->event.sequence = vblwait->request.sequence; 1389 + if (vblank_passed(seq, vblwait->request.sequence)) { 1390 + drm_vblank_put(dev, pipe); 1391 + send_vblank_event(dev, e, seq, &now); 1392 + vblwait->reply.sequence = seq; 1393 + } else { 1394 + /* drm_handle_vblank_events will call drm_vblank_put */ 1395 + list_add_tail(&e->base.link, &dev->vblank_event_list); 1396 + vblwait->reply.sequence = vblwait->request.sequence; 1397 + } 1398 + 1399 + spin_unlock_irqrestore(&dev->event_lock, flags); 1400 + 1401 + return 0; 1402 + 1403 + err_unlock: 1404 + spin_unlock_irqrestore(&dev->event_lock, flags); 1405 + kfree(e); 1406 + err_put: 1407 + drm_vblank_put(dev, pipe); 1408 + return ret; 1409 + } 1410 + 1411 + static bool drm_wait_vblank_is_query(union drm_wait_vblank *vblwait) 1412 + { 1413 + if (vblwait->request.sequence) 1414 + return false; 1415 + 1416 + return _DRM_VBLANK_RELATIVE == 1417 + (vblwait->request.type & (_DRM_VBLANK_TYPES_MASK | 1418 + _DRM_VBLANK_EVENT | 1419 + _DRM_VBLANK_NEXTONMISS)); 1420 + } 1421 + 1422 + /* 1423 + * Wait for VBLANK. 1424 + * 1425 + * \param inode device inode. 1426 + * \param file_priv DRM file private. 1427 + * \param cmd command. 1428 + * \param data user argument, pointing to a drm_wait_vblank structure. 1429 + * \return zero on success or a negative number on failure. 1430 + * 1431 + * This function enables the vblank interrupt on the pipe requested, then 1432 + * sleeps waiting for the requested sequence number to occur, and drops 1433 + * the vblank interrupt refcount afterwards. (vblank IRQ disable follows that 1434 + * after a timeout with no further vblank waits scheduled). 1435 + */ 1436 + int drm_wait_vblank(struct drm_device *dev, void *data, 1437 + struct drm_file *file_priv) 1438 + { 1439 + struct drm_vblank_crtc *vblank; 1440 + union drm_wait_vblank *vblwait = data; 1441 + int ret; 1442 + unsigned int flags, seq, pipe, high_pipe; 1443 + 1444 + if (!dev->irq_enabled) 1445 + return -EINVAL; 1446 + 1447 + if (vblwait->request.type & _DRM_VBLANK_SIGNAL) 1448 + return -EINVAL; 1449 + 1450 + if (vblwait->request.type & 1451 + ~(_DRM_VBLANK_TYPES_MASK | _DRM_VBLANK_FLAGS_MASK | 1452 + _DRM_VBLANK_HIGH_CRTC_MASK)) { 1453 + DRM_ERROR("Unsupported type value 0x%x, supported mask 0x%x\n", 1454 + vblwait->request.type, 1455 + (_DRM_VBLANK_TYPES_MASK | _DRM_VBLANK_FLAGS_MASK | 1456 + _DRM_VBLANK_HIGH_CRTC_MASK)); 1457 + return -EINVAL; 1458 + } 1459 + 1460 + flags = vblwait->request.type & _DRM_VBLANK_FLAGS_MASK; 1461 + high_pipe = (vblwait->request.type & _DRM_VBLANK_HIGH_CRTC_MASK); 1462 + if (high_pipe) 1463 + pipe = high_pipe >> _DRM_VBLANK_HIGH_CRTC_SHIFT; 1464 + else 1465 + pipe = flags & _DRM_VBLANK_SECONDARY ? 1 : 0; 1466 + if (pipe >= dev->num_crtcs) 1467 + return -EINVAL; 1468 + 1469 + vblank = &dev->vblank[pipe]; 1470 + 1471 + /* If the counter is currently enabled and accurate, short-circuit 1472 + * queries to return the cached timestamp of the last vblank. 1473 + */ 1474 + if (dev->vblank_disable_immediate && 1475 + drm_wait_vblank_is_query(vblwait) && 1476 + READ_ONCE(vblank->enabled)) { 1477 + struct timeval now; 1478 + 1479 + vblwait->reply.sequence = 1480 + drm_vblank_count_and_time(dev, pipe, &now); 1481 + vblwait->reply.tval_sec = now.tv_sec; 1482 + vblwait->reply.tval_usec = now.tv_usec; 1483 + return 0; 1484 + } 1485 + 1486 + ret = drm_vblank_get(dev, pipe); 1487 + if (ret) { 1488 + DRM_DEBUG("crtc %d failed to acquire vblank counter, %d\n", pipe, ret); 1489 + return ret; 1490 + } 1491 + seq = drm_vblank_count(dev, pipe); 1492 + 1493 + switch (vblwait->request.type & _DRM_VBLANK_TYPES_MASK) { 1494 + case _DRM_VBLANK_RELATIVE: 1495 + vblwait->request.sequence += seq; 1496 + vblwait->request.type &= ~_DRM_VBLANK_RELATIVE; 1497 + case _DRM_VBLANK_ABSOLUTE: 1498 + break; 1499 + default: 1500 + ret = -EINVAL; 1501 + goto done; 1502 + } 1503 + 1504 + if ((flags & _DRM_VBLANK_NEXTONMISS) && 1505 + vblank_passed(seq, vblwait->request.sequence)) 1506 + vblwait->request.sequence = seq + 1; 1507 + 1508 + if (flags & _DRM_VBLANK_EVENT) { 1509 + /* must hold on to the vblank ref until the event fires 1510 + * drm_vblank_put will be called asynchronously 1511 + */ 1512 + return drm_queue_vblank_event(dev, pipe, vblwait, file_priv); 1513 + } 1514 + 1515 + if (vblwait->request.sequence != seq) { 1516 + DRM_DEBUG("waiting on vblank count %u, crtc %u\n", 1517 + vblwait->request.sequence, pipe); 1518 + DRM_WAIT_ON(ret, vblank->queue, 3 * HZ, 1519 + vblank_passed(drm_vblank_count(dev, pipe), 1520 + vblwait->request.sequence) || 1521 + !READ_ONCE(vblank->enabled)); 1522 + } 1523 + 1524 + if (ret != -EINTR) { 1525 + struct timeval now; 1526 + 1527 + vblwait->reply.sequence = drm_vblank_count_and_time(dev, pipe, &now); 1528 + vblwait->reply.tval_sec = now.tv_sec; 1529 + vblwait->reply.tval_usec = now.tv_usec; 1530 + 1531 + DRM_DEBUG("crtc %d returning %u to client\n", 1532 + pipe, vblwait->reply.sequence); 1533 + } else { 1534 + DRM_DEBUG("crtc %d vblank wait interrupted by signal\n", pipe); 1535 + } 1536 + 1537 + done: 1538 + drm_vblank_put(dev, pipe); 1539 + return ret; 1540 + } 1541 + 1542 + static void drm_handle_vblank_events(struct drm_device *dev, unsigned int pipe) 1543 + { 1544 + struct drm_pending_vblank_event *e, *t; 1545 + struct timeval now; 1546 + unsigned int seq; 1547 + 1548 + assert_spin_locked(&dev->event_lock); 1549 + 1550 + seq = drm_vblank_count_and_time(dev, pipe, &now); 1551 + 1552 + list_for_each_entry_safe(e, t, &dev->vblank_event_list, base.link) { 1553 + if (e->pipe != pipe) 1554 + continue; 1555 + if (!vblank_passed(seq, e->event.sequence)) 1556 + continue; 1557 + 1558 + DRM_DEBUG("vblank event on %u, current %u\n", 1559 + e->event.sequence, seq); 1560 + 1561 + list_del(&e->base.link); 1562 + drm_vblank_put(dev, pipe); 1563 + send_vblank_event(dev, e, seq, &now); 1564 + } 1565 + 1566 + trace_drm_vblank_event(pipe, seq); 1567 + } 1568 + 1569 + /** 1570 + * drm_handle_vblank - handle a vblank event 1571 + * @dev: DRM device 1572 + * @pipe: index of CRTC where this event occurred 1573 + * 1574 + * Drivers should call this routine in their vblank interrupt handlers to 1575 + * update the vblank counter and send any signals that may be pending. 1576 + * 1577 + * This is the legacy version of drm_crtc_handle_vblank(). 1578 + */ 1579 + bool drm_handle_vblank(struct drm_device *dev, unsigned int pipe) 1580 + { 1581 + struct drm_vblank_crtc *vblank = &dev->vblank[pipe]; 1582 + unsigned long irqflags; 1583 + bool disable_irq; 1584 + 1585 + if (WARN_ON_ONCE(!dev->num_crtcs)) 1586 + return false; 1587 + 1588 + if (WARN_ON(pipe >= dev->num_crtcs)) 1589 + return false; 1590 + 1591 + spin_lock_irqsave(&dev->event_lock, irqflags); 1592 + 1593 + /* Need timestamp lock to prevent concurrent execution with 1594 + * vblank enable/disable, as this would cause inconsistent 1595 + * or corrupted timestamps and vblank counts. 1596 + */ 1597 + spin_lock(&dev->vblank_time_lock); 1598 + 1599 + /* Vblank irq handling disabled. Nothing to do. */ 1600 + if (!vblank->enabled) { 1601 + spin_unlock(&dev->vblank_time_lock); 1602 + spin_unlock_irqrestore(&dev->event_lock, irqflags); 1603 + return false; 1604 + } 1605 + 1606 + drm_update_vblank_count(dev, pipe, true); 1607 + 1608 + spin_unlock(&dev->vblank_time_lock); 1609 + 1610 + wake_up(&vblank->queue); 1611 + 1612 + /* With instant-off, we defer disabling the interrupt until after 1613 + * we finish processing the following vblank after all events have 1614 + * been signaled. The disable has to be last (after 1615 + * drm_handle_vblank_events) so that the timestamp is always accurate. 1616 + */ 1617 + disable_irq = (dev->vblank_disable_immediate && 1618 + drm_vblank_offdelay > 0 && 1619 + !atomic_read(&vblank->refcount)); 1620 + 1621 + drm_handle_vblank_events(dev, pipe); 1622 + 1623 + spin_unlock_irqrestore(&dev->event_lock, irqflags); 1624 + 1625 + if (disable_irq) 1626 + vblank_disable_fn((unsigned long)vblank); 1627 + 1628 + return true; 1629 + } 1630 + EXPORT_SYMBOL(drm_handle_vblank); 1631 + 1632 + /** 1633 + * drm_crtc_handle_vblank - handle a vblank event 1634 + * @crtc: where this event occurred 1635 + * 1636 + * Drivers should call this routine in their vblank interrupt handlers to 1637 + * update the vblank counter and send any signals that may be pending. 1638 + * 1639 + * This is the native KMS version of drm_handle_vblank(). 1640 + * 1641 + * Returns: 1642 + * True if the event was successfully handled, false on failure. 1643 + */ 1644 + bool drm_crtc_handle_vblank(struct drm_crtc *crtc) 1645 + { 1646 + return drm_handle_vblank(crtc->dev, drm_crtc_index(crtc)); 1647 + } 1648 + EXPORT_SYMBOL(drm_crtc_handle_vblank);
+9 -9
drivers/gpu/drm/exynos/exynos_drm_drv.c
··· 171 171 { 172 172 struct drm_device *drm_dev = dev_get_drvdata(dev); 173 173 struct drm_connector *connector; 174 + struct drm_connector_list_iter conn_iter; 174 175 175 176 if (pm_runtime_suspended(dev) || !drm_dev) 176 177 return 0; 177 178 178 - drm_modeset_lock_all(drm_dev); 179 - drm_for_each_connector(connector, drm_dev) { 179 + drm_connector_list_iter_begin(drm_dev, &conn_iter); 180 + drm_for_each_connector_iter(connector, &conn_iter) { 180 181 int old_dpms = connector->dpms; 181 182 182 183 if (connector->funcs->dpms) ··· 186 185 /* Set the old mode back to the connector for resume */ 187 186 connector->dpms = old_dpms; 188 187 } 189 - drm_modeset_unlock_all(drm_dev); 188 + drm_connector_list_iter_end(&conn_iter); 190 189 191 190 return 0; 192 191 } ··· 195 194 { 196 195 struct drm_device *drm_dev = dev_get_drvdata(dev); 197 196 struct drm_connector *connector; 197 + struct drm_connector_list_iter conn_iter; 198 198 199 199 if (pm_runtime_suspended(dev) || !drm_dev) 200 200 return 0; 201 201 202 - drm_modeset_lock_all(drm_dev); 203 - drm_for_each_connector(connector, drm_dev) { 202 + drm_connector_list_iter_begin(drm_dev, &conn_iter); 203 + drm_for_each_connector_iter(connector, &conn_iter) { 204 204 if (connector->funcs->dpms) { 205 205 int dpms = connector->dpms; 206 206 ··· 209 207 connector->funcs->dpms(connector, dpms); 210 208 } 211 209 } 212 - drm_modeset_unlock_all(drm_dev); 210 + drm_connector_list_iter_end(&conn_iter); 213 211 214 212 return 0; 215 213 } ··· 378 376 /* Probe non kms sub drivers and virtual display driver. */ 379 377 ret = exynos_drm_device_subdrv_probe(drm); 380 378 if (ret) 381 - goto err_cleanup_vblank; 379 + goto err_unbind_all; 382 380 383 381 drm_mode_config_reset(drm); 384 382 ··· 409 407 exynos_drm_fbdev_fini(drm); 410 408 drm_kms_helper_poll_fini(drm); 411 409 exynos_drm_device_subdrv_remove(drm); 412 - err_cleanup_vblank: 413 - drm_vblank_cleanup(drm); 414 410 err_unbind_all: 415 411 component_unbind_all(drm->dev, drm); 416 412 err_mode_config_cleanup:
+4 -1
drivers/gpu/drm/i915/intel_display.c
··· 11400 11400 { 11401 11401 struct drm_device *dev = state->dev; 11402 11402 struct drm_connector *connector; 11403 + struct drm_connector_list_iter conn_iter; 11403 11404 unsigned int used_ports = 0; 11404 11405 unsigned int used_mst_ports = 0; 11405 11406 ··· 11409 11408 * list to detect the problem on ddi platforms 11410 11409 * where there's just one encoder per digital port. 11411 11410 */ 11412 - drm_for_each_connector(connector, dev) { 11411 + drm_connector_list_iter_begin(dev, &conn_iter); 11412 + drm_for_each_connector_iter(connector, &conn_iter) { 11413 11413 struct drm_connector_state *connector_state; 11414 11414 struct intel_encoder *encoder; 11415 11415 ··· 11449 11447 break; 11450 11448 } 11451 11449 } 11450 + drm_connector_list_iter_end(&conn_iter); 11452 11451 11453 11452 /* can't mix MST and SST/HDMI on the same port */ 11454 11453 if (used_ports & used_mst_ports)
+1 -3
drivers/gpu/drm/imx/imx-drm-core.c
··· 278 278 /* Now try and bind all our sub-components */ 279 279 ret = component_bind_all(dev, drm); 280 280 if (ret) 281 - goto err_vblank; 281 + goto err_kms; 282 282 283 283 drm_mode_config_reset(drm); 284 284 ··· 316 316 err_unbind: 317 317 #endif 318 318 component_unbind_all(drm->dev, drm); 319 - err_vblank: 320 - drm_vblank_cleanup(drm); 321 319 err_kms: 322 320 drm_mode_config_cleanup(drm); 323 321 err_unref:
+4 -1
drivers/gpu/drm/mediatek/mtk_drm_crtc.c
··· 221 221 struct drm_crtc *crtc = &mtk_crtc->base; 222 222 struct drm_connector *connector; 223 223 struct drm_encoder *encoder; 224 + struct drm_connector_list_iter conn_iter; 224 225 unsigned int width, height, vrefresh, bpc = MTK_MAX_BPC; 225 226 int ret; 226 227 int i; ··· 238 237 if (encoder->crtc != crtc) 239 238 continue; 240 239 241 - drm_for_each_connector(connector, crtc->dev) { 240 + drm_connector_list_iter_begin(crtc->dev, &conn_iter); 241 + drm_for_each_connector_iter(connector, &conn_iter) { 242 242 if (connector->encoder != encoder) 243 243 continue; 244 244 if (connector->display_info.bpc != 0 && 245 245 bpc > connector->display_info.bpc) 246 246 bpc = connector->display_info.bpc; 247 247 } 248 + drm_connector_list_iter_end(&conn_iter); 248 249 } 249 250 250 251 ret = pm_runtime_get_sync(crtc->dev->dev);
-1
drivers/gpu/drm/meson/meson_drv.c
··· 285 285 drm_kms_helper_poll_fini(drm); 286 286 drm_fbdev_cma_fini(priv->fbdev); 287 287 drm_mode_config_cleanup(drm); 288 - drm_vblank_cleanup(drm); 289 288 drm_dev_unref(drm); 290 289 291 290 }
+4 -1
drivers/gpu/drm/nouveau/nv50_display.c
··· 2872 2872 struct nv50_mstc *mstc = NULL; 2873 2873 struct nv50_mstm *mstm = NULL; 2874 2874 struct drm_connector *connector; 2875 + struct drm_connector_list_iter conn_iter; 2875 2876 u8 proto, depth; 2876 2877 int slots; 2877 2878 bool r; 2878 2879 2879 - drm_for_each_connector(connector, encoder->dev) { 2880 + drm_connector_list_iter_begin(encoder->dev, &conn_iter); 2881 + drm_for_each_connector_iter(connector, &conn_iter) { 2880 2882 if (connector->state->best_encoder == &msto->encoder) { 2881 2883 mstc = nv50_mstc(connector); 2882 2884 mstm = mstc->mstm; 2883 2885 break; 2884 2886 } 2885 2887 } 2888 + drm_connector_list_iter_end(&conn_iter); 2886 2889 2887 2890 if (WARN_ON(!mstc)) 2888 2891 return;
+1
drivers/gpu/drm/pl111/Kconfig
··· 6 6 select DRM_KMS_HELPER 7 7 select DRM_KMS_CMA_HELPER 8 8 select DRM_GEM_CMA_HELPER 9 + select DRM_PANEL 9 10 select VT_HW_CONSOLE_BINDING if FRAMEBUFFER_CONSOLE 10 11 help 11 12 Choose this option for DRM support for the PL111 CLCD controller.
+3 -3
drivers/gpu/drm/pl111/pl111_drv.c
··· 179 179 #endif 180 180 }; 181 181 182 - #ifdef CONFIG_ARM_AMBA 183 182 static int pl111_amba_probe(struct amba_device *amba_dev, 184 183 const struct amba_id *id) 185 184 { ··· 251 252 {0, 0}, 252 253 }; 253 254 254 - static struct amba_driver pl111_amba_driver = { 255 + static struct amba_driver pl111_amba_driver __maybe_unused = { 255 256 .drv = { 256 257 .name = "drm-clcd-pl111", 257 258 }, ··· 260 261 .id_table = pl111_id_table, 261 262 }; 262 263 264 + #ifdef CONFIG_ARM_AMBA 263 265 module_amba_driver(pl111_amba_driver); 264 - #endif /* CONFIG_ARM_AMBA */ 266 + #endif 265 267 266 268 MODULE_DESCRIPTION(DRIVER_DESC); 267 269 MODULE_AUTHOR("ARM Ltd.");
+6 -5
drivers/gpu/drm/rockchip/rockchip_drm_vop.c
··· 1118 1118 #ifdef CONFIG_DRM_ANALOGIX_DP 1119 1119 static struct drm_connector *vop_get_edp_connector(struct vop *vop) 1120 1120 { 1121 - struct drm_crtc *crtc = &vop->crtc; 1122 1121 struct drm_connector *connector; 1122 + struct drm_connector_list_iter conn_iter; 1123 1123 1124 - mutex_lock(&crtc->dev->mode_config.mutex); 1125 - drm_for_each_connector(connector, crtc->dev) 1124 + drm_connector_list_iter_begin(vop->drm_dev, &conn_iter); 1125 + drm_for_each_connector_iter(connector, &conn_iter) { 1126 1126 if (connector->connector_type == DRM_MODE_CONNECTOR_eDP) { 1127 - mutex_unlock(&crtc->dev->mode_config.mutex); 1127 + drm_connector_list_iter_end(&conn_iter); 1128 1128 return connector; 1129 1129 } 1130 - mutex_unlock(&crtc->dev->mode_config.mutex); 1130 + } 1131 + drm_connector_list_iter_end(&conn_iter); 1131 1132 1132 1133 return NULL; 1133 1134 }
-2
drivers/gpu/drm/stm/ltdc.c
··· 1144 1144 1145 1145 DRM_DEBUG_DRIVER("\n"); 1146 1146 1147 - drm_vblank_cleanup(ddev); 1148 - 1149 1147 if (ldev->panel) 1150 1148 drm_panel_detach(ldev->panel); 1151 1149
-2
drivers/gpu/drm/sun4i/sun4i_drv.c
··· 138 138 sun4i_framebuffer_free(drm); 139 139 cleanup_mode_config: 140 140 drm_mode_config_cleanup(drm); 141 - drm_vblank_cleanup(drm); 142 141 free_mem_region: 143 142 of_reserved_mem_device_release(dev); 144 143 free_drm: ··· 153 154 drm_kms_helper_poll_fini(drm); 154 155 sun4i_framebuffer_free(drm); 155 156 drm_mode_config_cleanup(drm); 156 - drm_vblank_cleanup(drm); 157 157 of_reserved_mem_device_release(dev); 158 158 drm_dev_unref(drm); 159 159 }
+2 -5
drivers/gpu/drm/tinydrm/mipi-dbi.c
··· 914 914 { 915 915 struct mipi_dbi *mipi = m->private; 916 916 u8 cmd, val[4]; 917 - size_t len, i; 917 + size_t len; 918 918 int ret; 919 919 920 920 for (cmd = 0; cmd < 255; cmd++) { ··· 943 943 seq_puts(m, "XX\n"); 944 944 continue; 945 945 } 946 - 947 - for (i = 0; i < len; i++) 948 - seq_printf(m, "%02x", val[i]); 949 - seq_puts(m, "\n"); 946 + seq_printf(m, "%*phN\n", (int)len, val); 950 947 } 951 948 952 949 return 0;
+5 -1
drivers/gpu/drm/vc4/vc4_crtc.c
··· 345 345 static struct drm_encoder *vc4_get_crtc_encoder(struct drm_crtc *crtc) 346 346 { 347 347 struct drm_connector *connector; 348 + struct drm_connector_list_iter conn_iter; 348 349 349 - drm_for_each_connector(connector, crtc->dev) { 350 + drm_connector_list_iter_begin(crtc->dev, &conn_iter); 351 + drm_for_each_connector_iter(connector, &conn_iter) { 350 352 if (connector->state->crtc == crtc) { 353 + drm_connector_list_iter_end(&conn_iter); 351 354 return connector->encoder; 352 355 } 353 356 } 357 + drm_connector_list_iter_end(&conn_iter); 354 358 355 359 return NULL; 356 360 }
+1 -1
drivers/gpu/drm/vc4/vc4_drv.h
··· 532 532 extern struct platform_driver vc4_hdmi_driver; 533 533 int vc4_hdmi_debugfs_regs(struct seq_file *m, void *unused); 534 534 535 - /* vc4_hdmi.c */ 535 + /* vc4_vec.c */ 536 536 extern struct platform_driver vc4_vec_driver; 537 537 int vc4_vec_debugfs_regs(struct seq_file *m, void *unused); 538 538
+1
drivers/gpu/drm/vc4/vc4_v3d.c
··· 401 401 return ret; 402 402 } 403 403 404 + pm_runtime_set_active(dev); 404 405 pm_runtime_use_autosuspend(dev); 405 406 pm_runtime_set_autosuspend_delay(dev, 40); /* a little over 2 frames. */ 406 407 pm_runtime_enable(dev);
-1
drivers/gpu/drm/virtio/virtgpu_drm_bus.c
··· 56 56 dev = drm_dev_alloc(driver, &vdev->dev); 57 57 if (IS_ERR(dev)) 58 58 return PTR_ERR(dev); 59 - dev->virtdev = vdev; 60 59 vdev->priv = dev; 61 60 62 61 if (strcmp(vdev->dev.parent->bus->name, "pci") == 0) {
+2 -2
drivers/gpu/drm/virtio/virtgpu_kms.c
··· 138 138 u32 num_scanouts, num_capsets; 139 139 int ret; 140 140 141 - if (!virtio_has_feature(dev->virtdev, VIRTIO_F_VERSION_1)) 141 + if (!virtio_has_feature(dev_to_virtio(dev->dev), VIRTIO_F_VERSION_1)) 142 142 return -ENODEV; 143 143 144 144 vgdev = kzalloc(sizeof(struct virtio_gpu_device), GFP_KERNEL); ··· 147 147 148 148 vgdev->ddev = dev; 149 149 dev->dev_private = vgdev; 150 - vgdev->vdev = dev->virtdev; 150 + vgdev->vdev = dev_to_virtio(dev->dev); 151 151 vgdev->dev = dev->dev; 152 152 153 153 spin_lock_init(&vgdev->display_info_lock);
+10 -23
include/drm/drmP.h
··· 80 80 #include <drm/drm_debugfs.h> 81 81 #include <drm/drm_ioctl.h> 82 82 #include <drm/drm_sysfs.h> 83 + #include <drm/drm_vblank.h> 84 + #include <drm/drm_irq.h> 85 + 83 86 84 87 struct module; 85 88 ··· 295 292 /* Format strings and argument splitters to simplify printing 296 293 * various "complex" objects 297 294 */ 298 - #define DRM_MODE_FMT "%d:\"%s\" %d %d %d %d %d %d %d %d %d %d 0x%x 0x%x" 299 - #define DRM_MODE_ARG(m) \ 300 - (m)->base.id, (m)->name, (m)->vrefresh, (m)->clock, \ 301 - (m)->hdisplay, (m)->hsync_start, (m)->hsync_end, (m)->htotal, \ 302 - (m)->vdisplay, (m)->vsync_start, (m)->vsync_end, (m)->vtotal, \ 303 - (m)->type, (m)->flags 304 - 305 - #define DRM_RECT_FMT "%dx%d%+d%+d" 306 - #define DRM_RECT_ARG(r) drm_rect_width(r), drm_rect_height(r), (r)->x1, (r)->y1 307 - 308 - /* for rect's in fixed-point format: */ 309 - #define DRM_RECT_FP_FMT "%d.%06ux%d.%06u%+d.%06u%+d.%06u" 310 - #define DRM_RECT_FP_ARG(r) \ 311 - drm_rect_width(r) >> 16, ((drm_rect_width(r) & 0xffff) * 15625) >> 10, \ 312 - drm_rect_height(r) >> 16, ((drm_rect_height(r) & 0xffff) * 15625) >> 10, \ 313 - (r)->x1 >> 16, (((r)->x1 & 0xffff) * 15625) >> 10, \ 314 - (r)->y1 >> 16, (((r)->y1 & 0xffff) * 15625) >> 10 315 295 316 296 /*@}*/ 317 297 ··· 377 391 int last_context; /**< Last current context */ 378 392 /*@} */ 379 393 380 - /** \name VBLANK IRQ support */ 381 - /*@{ */ 394 + /** 395 + * @irq_enabled: 396 + * 397 + * Indicates that interrupt handling is enabled, specifically vblank 398 + * handling. Drivers which don't use drm_irq_install() need to set this 399 + * to true manually. 400 + */ 382 401 bool irq_enabled; 383 402 int irq; 384 403 ··· 420 429 struct pci_controller *hose; 421 430 #endif 422 431 423 - struct virtio_device *virtdev; 424 - 425 432 struct drm_sg_mem *sg; /**< Scatter gather memory */ 426 433 unsigned int num_crtcs; /**< Number of CRTCs on this device */ 427 434 ··· 454 465 { 455 466 return dev->mode_config.funcs->atomic_commit != NULL; 456 467 } 457 - 458 - #include <drm/drm_irq.h> 459 468 460 469 #define DRM_SWITCH_POWER_ON 0 461 470 #define DRM_SWITCH_POWER_OFF 1
+1 -1
include/drm/drm_atomic.h
··· 520 520 521 521 int __must_check 522 522 drm_atomic_set_mode_for_crtc(struct drm_crtc_state *state, 523 - struct drm_display_mode *mode); 523 + const struct drm_display_mode *mode); 524 524 int __must_check 525 525 drm_atomic_set_mode_prop_for_crtc(struct drm_crtc_state *state, 526 526 struct drm_property_blob *blob);
+2
include/drm/drm_bridge.h
··· 253 253 bool drm_bridge_mode_fixup(struct drm_bridge *bridge, 254 254 const struct drm_display_mode *mode, 255 255 struct drm_display_mode *adjusted_mode); 256 + enum drm_mode_status drm_bridge_mode_valid(struct drm_bridge *bridge, 257 + const struct drm_display_mode *mode); 256 258 void drm_bridge_disable(struct drm_bridge *bridge); 257 259 void drm_bridge_post_disable(struct drm_bridge *bridge); 258 260 void drm_bridge_mode_set(struct drm_bridge *bridge,
-15
include/drm/drm_connector.h
··· 1010 1010 struct drm_tile_group *tg); 1011 1011 1012 1012 /** 1013 - * drm_for_each_connector - iterate over all connectors 1014 - * @connector: the loop cursor 1015 - * @dev: the DRM device 1016 - * 1017 - * Iterate over all connectors of @dev. 1018 - * 1019 - * WARNING: 1020 - * 1021 - * This iterator is not safe against hotadd/removal of connectors and is 1022 - * deprecated. Use drm_for_each_connector_iter() instead. 1023 - */ 1024 - #define drm_for_each_connector(connector, dev) \ 1025 - list_for_each_entry(connector, &(dev)->mode_config.connector_list, head) 1026 - 1027 - /** 1028 1013 * struct drm_connector_list_iter - connector_list iterator 1029 1014 * 1030 1015 * This iterator tracks state needed to be able to walk the connector_list
+3 -1
include/drm/drm_crtc.h
··· 214 214 * atomic commit. In that case the event can be send out any time 215 215 * after the hardware has stopped scanning out the current 216 216 * framebuffers. It should contain the timestamp and counter for the 217 - * last vblank before the display pipeline was shut off. 217 + * last vblank before the display pipeline was shut off. The simplest 218 + * way to achieve that is calling drm_crtc_send_vblank_event() 219 + * somewhen after drm_crtc_vblank_off() has been called. 218 220 * 219 221 * - For a CRTC which is enabled at the end of the commit (even when it 220 222 * undergoes an full modeset) the vblank timestamp and counter must
+31 -2
include/drm/drm_drv.h
··· 327 327 struct timeval *vblank_time, 328 328 bool in_vblank_irq); 329 329 330 - /* these have to be filled in */ 331 - 330 + /** 331 + * @irq_handler: 332 + * 333 + * Interrupt handler called when using drm_irq_install(). Not used by 334 + * drivers which implement their own interrupt handling. 335 + */ 332 336 irqreturn_t(*irq_handler) (int irq, void *arg); 337 + 338 + /** 339 + * @irq_preinstall: 340 + * 341 + * Optional callback used by drm_irq_install() which is called before 342 + * the interrupt handler is registered. This should be used to clear out 343 + * any pending interrupts (from e.g. firmware based drives) and reset 344 + * the interrupt handling registers. 345 + */ 333 346 void (*irq_preinstall) (struct drm_device *dev); 347 + 348 + /** 349 + * @irq_postinstall: 350 + * 351 + * Optional callback used by drm_irq_install() which is called after 352 + * the interrupt handler is registered. This should be used to enable 353 + * interrupt generation in the hardware. 354 + */ 334 355 int (*irq_postinstall) (struct drm_device *dev); 356 + 357 + /** 358 + * @irq_uninstall: 359 + * 360 + * Optional callback used by drm_irq_uninstall() which is called before 361 + * the interrupt handler is unregistered. This should be used to disable 362 + * interrupt generation in the hardware. 363 + */ 335 364 void (*irq_uninstall) (struct drm_device *dev); 336 365 337 366 /**
+1
include/drm/drm_file.h
··· 40 40 struct dma_fence; 41 41 struct drm_file; 42 42 struct drm_device; 43 + struct device; 43 44 44 45 /* 45 46 * FIXME: Not sure we want to have drm_minor here in the end, but to avoid
+1 -157
include/drm/drm_irq.h
··· 24 24 #ifndef _DRM_IRQ_H_ 25 25 #define _DRM_IRQ_H_ 26 26 27 - #include <linux/seqlock.h> 28 - 29 - /** 30 - * struct drm_pending_vblank_event - pending vblank event tracking 31 - */ 32 - struct drm_pending_vblank_event { 33 - /** 34 - * @base: Base structure for tracking pending DRM events. 35 - */ 36 - struct drm_pending_event base; 37 - /** 38 - * @pipe: drm_crtc_index() of the &drm_crtc this event is for. 39 - */ 40 - unsigned int pipe; 41 - /** 42 - * @event: Actual event which will be sent to userspace. 43 - */ 44 - struct drm_event_vblank event; 45 - }; 46 - 47 - /** 48 - * struct drm_vblank_crtc - vblank tracking for a CRTC 49 - * 50 - * This structure tracks the vblank state for one CRTC. 51 - * 52 - * Note that for historical reasons - the vblank handling code is still shared 53 - * with legacy/non-kms drivers - this is a free-standing structure not directly 54 - * connected to &struct drm_crtc. But all public interface functions are taking 55 - * a &struct drm_crtc to hide this implementation detail. 56 - */ 57 - struct drm_vblank_crtc { 58 - /** 59 - * @dev: Pointer to the &drm_device. 60 - */ 61 - struct drm_device *dev; 62 - /** 63 - * @queue: Wait queue for vblank waiters. 64 - */ 65 - wait_queue_head_t queue; /**< VBLANK wait queue */ 66 - /** 67 - * @disable_timer: Disable timer for the delayed vblank disabling 68 - * hysteresis logic. Vblank disabling is controlled through the 69 - * drm_vblank_offdelay module option and the setting of the 70 - * &drm_device.max_vblank_count value. 71 - */ 72 - struct timer_list disable_timer; 73 - 74 - /** 75 - * @seqlock: Protect vblank count and time. 76 - */ 77 - seqlock_t seqlock; /* protects vblank count and time */ 78 - 79 - /** 80 - * @count: Current software vblank counter. 81 - */ 82 - u32 count; 83 - /** 84 - * @time: Vblank timestamp corresponding to @count. 85 - */ 86 - struct timeval time; 87 - 88 - /** 89 - * @refcount: Number of users/waiters of the vblank interrupt. Only when 90 - * this refcount reaches 0 can the hardware interrupt be disabled using 91 - * @disable_timer. 92 - */ 93 - atomic_t refcount; /* number of users of vblank interruptsper crtc */ 94 - /** 95 - * @last: Protected by &drm_device.vbl_lock, used for wraparound handling. 96 - */ 97 - u32 last; 98 - /** 99 - * @inmodeset: Tracks whether the vblank is disabled due to a modeset. 100 - * For legacy driver bit 2 additionally tracks whether an additional 101 - * temporary vblank reference has been acquired to paper over the 102 - * hardware counter resetting/jumping. KMS drivers should instead just 103 - * call drm_crtc_vblank_off() and drm_crtc_vblank_on(), which explicitly 104 - * save and restore the vblank count. 105 - */ 106 - unsigned int inmodeset; /* Display driver is setting mode */ 107 - /** 108 - * @pipe: drm_crtc_index() of the &drm_crtc corresponding to this 109 - * structure. 110 - */ 111 - unsigned int pipe; 112 - /** 113 - * @framedur_ns: Frame/Field duration in ns, used by 114 - * drm_calc_vbltimestamp_from_scanoutpos() and computed by 115 - * drm_calc_timestamping_constants(). 116 - */ 117 - int framedur_ns; 118 - /** 119 - * @linedur_ns: Line duration in ns, used by 120 - * drm_calc_vbltimestamp_from_scanoutpos() and computed by 121 - * drm_calc_timestamping_constants(). 122 - */ 123 - int linedur_ns; 124 - 125 - /** 126 - * @hwmode: 127 - * 128 - * Cache of the current hardware display mode. Only valid when @enabled 129 - * is set. This is used by helpers like 130 - * drm_calc_vbltimestamp_from_scanoutpos(). We can't just access the 131 - * hardware mode by e.g. looking at &drm_crtc_state.adjusted_mode, 132 - * because that one is really hard to get from interrupt context. 133 - */ 134 - struct drm_display_mode hwmode; 135 - 136 - /** 137 - * @enabled: Tracks the enabling state of the corresponding &drm_crtc to 138 - * avoid double-disabling and hence corrupting saved state. Needed by 139 - * drivers not using atomic KMS, since those might go through their CRTC 140 - * disabling functions multiple times. 141 - */ 142 - bool enabled; 143 - }; 27 + struct drm_device; 144 28 145 29 int drm_irq_install(struct drm_device *dev, int irq); 146 30 int drm_irq_uninstall(struct drm_device *dev); 147 - 148 - int drm_vblank_init(struct drm_device *dev, unsigned int num_crtcs); 149 - u32 drm_crtc_vblank_count(struct drm_crtc *crtc); 150 - u32 drm_crtc_vblank_count_and_time(struct drm_crtc *crtc, 151 - struct timeval *vblanktime); 152 - void drm_crtc_send_vblank_event(struct drm_crtc *crtc, 153 - struct drm_pending_vblank_event *e); 154 - void drm_crtc_arm_vblank_event(struct drm_crtc *crtc, 155 - struct drm_pending_vblank_event *e); 156 - bool drm_handle_vblank(struct drm_device *dev, unsigned int pipe); 157 - bool drm_crtc_handle_vblank(struct drm_crtc *crtc); 158 - int drm_crtc_vblank_get(struct drm_crtc *crtc); 159 - void drm_crtc_vblank_put(struct drm_crtc *crtc); 160 - void drm_wait_one_vblank(struct drm_device *dev, unsigned int pipe); 161 - void drm_crtc_wait_one_vblank(struct drm_crtc *crtc); 162 - void drm_crtc_vblank_off(struct drm_crtc *crtc); 163 - void drm_crtc_vblank_reset(struct drm_crtc *crtc); 164 - void drm_crtc_vblank_on(struct drm_crtc *crtc); 165 - void drm_vblank_cleanup(struct drm_device *dev); 166 - u32 drm_accurate_vblank_count(struct drm_crtc *crtc); 167 - 168 - bool drm_calc_vbltimestamp_from_scanoutpos(struct drm_device *dev, 169 - unsigned int pipe, int *max_error, 170 - struct timeval *vblank_time, 171 - bool in_vblank_irq); 172 - void drm_calc_timestamping_constants(struct drm_crtc *crtc, 173 - const struct drm_display_mode *mode); 174 - 175 - /** 176 - * drm_crtc_vblank_waitqueue - get vblank waitqueue for the CRTC 177 - * @crtc: which CRTC's vblank waitqueue to retrieve 178 - * 179 - * This function returns a pointer to the vblank waitqueue for the CRTC. 180 - * Drivers can use this to implement vblank waits using wait_event() and related 181 - * functions. 182 - */ 183 - static inline wait_queue_head_t *drm_crtc_vblank_waitqueue(struct drm_crtc *crtc) 184 - { 185 - return &crtc->dev->vblank[drm_crtc_index(crtc)].queue; 186 - } 187 31 188 32 #endif
+17
include/drm/drm_modes.h
··· 197 197 * there's the hardware timings, which are corrected for interlacing, 198 198 * double-clocking and similar things. They are provided as a convenience, and 199 199 * can be appropriately computed using drm_mode_set_crtcinfo(). 200 + * 201 + * For printing you can use %DRM_MODE_FMT and DRM_MODE_ARG(). 200 202 */ 201 203 struct drm_display_mode { 202 204 /** ··· 408 406 */ 409 407 enum hdmi_picture_aspect picture_aspect_ratio; 410 408 }; 409 + 410 + /** 411 + * DRM_MODE_FMT - printf string for &struct drm_display_mode 412 + */ 413 + #define DRM_MODE_FMT "%d:\"%s\" %d %d %d %d %d %d %d %d %d %d 0x%x 0x%x" 414 + 415 + /** 416 + * DRM_MODE_ARG - printf arguments for &struct drm_display_mode 417 + * @m: display mode 418 + */ 419 + #define DRM_MODE_ARG(m) \ 420 + (m)->base.id, (m)->name, (m)->vrefresh, (m)->clock, \ 421 + (m)->hdisplay, (m)->hsync_start, (m)->hsync_end, (m)->htotal, \ 422 + (m)->vdisplay, (m)->vsync_start, (m)->vsync_end, (m)->vtotal, \ 423 + (m)->type, (m)->flags 411 424 412 425 #define obj_to_mode(x) container_of(x, struct drm_display_mode, base) 413 426
+1 -13
include/drm/drm_os_linux.h
··· 6 6 #include <linux/interrupt.h> /* For task queue support */ 7 7 #include <linux/sched/signal.h> 8 8 #include <linux/delay.h> 9 - 10 - #ifndef readq 11 - static inline u64 readq(void __iomem *reg) 12 - { 13 - return ((u64) readl(reg)) | (((u64) readl(reg + 4UL)) << 32); 14 - } 15 - 16 - static inline void writeq(u64 val, void __iomem *reg) 17 - { 18 - writel(val & 0xffffffff, reg); 19 - writel(val >> 32, reg + 0x4UL); 20 - } 21 - #endif 9 + #include <linux/io-64-nonatomic-lo-hi.h> 22 10 23 11 /** Current process ID */ 24 12 #define DRM_CURRENTPID task_pid_nr(current)
+2
include/drm/drm_prime.h
··· 59 59 struct drm_gem_object; 60 60 struct drm_file; 61 61 62 + struct device; 63 + 62 64 struct dma_buf *drm_gem_prime_export(struct drm_device *dev, 63 65 struct drm_gem_object *obj, 64 66 int flags);
+27
include/drm/drm_rect.h
··· 43 43 }; 44 44 45 45 /** 46 + * DRM_RECT_FMT - printf string for &struct drm_rect 47 + */ 48 + #define DRM_RECT_FMT "%dx%d%+d%+d" 49 + /** 50 + * DRM_RECT_ARG - printf arguments for &struct drm_rect 51 + * @r: rectangle struct 52 + */ 53 + #define DRM_RECT_ARG(r) drm_rect_width(r), drm_rect_height(r), (r)->x1, (r)->y1 54 + 55 + /** 56 + * DRM_RECT_FP_FMT - printf string for &struct drm_rect in 16.16 fixed point 57 + */ 58 + #define DRM_RECT_FP_FMT "%d.%06ux%d.%06u%+d.%06u%+d.%06u" 59 + /** 60 + * DRM_RECT_FP_ARG - printf arguments for &struct drm_rect in 16.16 fixed point 61 + * @r: rectangle struct 62 + * 63 + * This is useful for e.g. printing plane source rectangles, which are in 16.16 64 + * fixed point. 65 + */ 66 + #define DRM_RECT_FP_ARG(r) \ 67 + drm_rect_width(r) >> 16, ((drm_rect_width(r) & 0xffff) * 15625) >> 10, \ 68 + drm_rect_height(r) >> 16, ((drm_rect_height(r) & 0xffff) * 15625) >> 10, \ 69 + (r)->x1 >> 16, (((r)->x1 & 0xffff) * 15625) >> 10, \ 70 + (r)->y1 >> 16, (((r)->y1 & 0xffff) * 15625) >> 10 71 + 72 + /** 46 73 * drm_rect_adjust_size - adjust the size of the rectangle 47 74 * @r: rectangle to be adjusted 48 75 * @dw: horizontal adjustment
+181
include/drm/drm_vblank.h
··· 1 + /* 2 + * Copyright 2016 Intel Corp. 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 (including the next 12 + * paragraph) shall be included in all copies or substantial portions of the 13 + * 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 + * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS 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 + 24 + #ifndef _DRM_VBLANK_H_ 25 + #define _DRM_VBLANK_H_ 26 + 27 + #include <linux/seqlock.h> 28 + #include <linux/idr.h> 29 + #include <linux/poll.h> 30 + 31 + #include <drm/drm_file.h> 32 + #include <drm/drm_modes.h> 33 + #include <uapi/drm/drm.h> 34 + 35 + struct drm_device; 36 + struct drm_crtc; 37 + 38 + /** 39 + * struct drm_pending_vblank_event - pending vblank event tracking 40 + */ 41 + struct drm_pending_vblank_event { 42 + /** 43 + * @base: Base structure for tracking pending DRM events. 44 + */ 45 + struct drm_pending_event base; 46 + /** 47 + * @pipe: drm_crtc_index() of the &drm_crtc this event is for. 48 + */ 49 + unsigned int pipe; 50 + /** 51 + * @event: Actual event which will be sent to userspace. 52 + */ 53 + struct drm_event_vblank event; 54 + }; 55 + 56 + /** 57 + * struct drm_vblank_crtc - vblank tracking for a CRTC 58 + * 59 + * This structure tracks the vblank state for one CRTC. 60 + * 61 + * Note that for historical reasons - the vblank handling code is still shared 62 + * with legacy/non-kms drivers - this is a free-standing structure not directly 63 + * connected to &struct drm_crtc. But all public interface functions are taking 64 + * a &struct drm_crtc to hide this implementation detail. 65 + */ 66 + struct drm_vblank_crtc { 67 + /** 68 + * @dev: Pointer to the &drm_device. 69 + */ 70 + struct drm_device *dev; 71 + /** 72 + * @queue: Wait queue for vblank waiters. 73 + */ 74 + wait_queue_head_t queue; /**< VBLANK wait queue */ 75 + /** 76 + * @disable_timer: Disable timer for the delayed vblank disabling 77 + * hysteresis logic. Vblank disabling is controlled through the 78 + * drm_vblank_offdelay module option and the setting of the 79 + * &drm_device.max_vblank_count value. 80 + */ 81 + struct timer_list disable_timer; 82 + 83 + /** 84 + * @seqlock: Protect vblank count and time. 85 + */ 86 + seqlock_t seqlock; /* protects vblank count and time */ 87 + 88 + /** 89 + * @count: Current software vblank counter. 90 + */ 91 + u32 count; 92 + /** 93 + * @time: Vblank timestamp corresponding to @count. 94 + */ 95 + struct timeval time; 96 + 97 + /** 98 + * @refcount: Number of users/waiters of the vblank interrupt. Only when 99 + * this refcount reaches 0 can the hardware interrupt be disabled using 100 + * @disable_timer. 101 + */ 102 + atomic_t refcount; /* number of users of vblank interruptsper crtc */ 103 + /** 104 + * @last: Protected by &drm_device.vbl_lock, used for wraparound handling. 105 + */ 106 + u32 last; 107 + /** 108 + * @inmodeset: Tracks whether the vblank is disabled due to a modeset. 109 + * For legacy driver bit 2 additionally tracks whether an additional 110 + * temporary vblank reference has been acquired to paper over the 111 + * hardware counter resetting/jumping. KMS drivers should instead just 112 + * call drm_crtc_vblank_off() and drm_crtc_vblank_on(), which explicitly 113 + * save and restore the vblank count. 114 + */ 115 + unsigned int inmodeset; /* Display driver is setting mode */ 116 + /** 117 + * @pipe: drm_crtc_index() of the &drm_crtc corresponding to this 118 + * structure. 119 + */ 120 + unsigned int pipe; 121 + /** 122 + * @framedur_ns: Frame/Field duration in ns, used by 123 + * drm_calc_vbltimestamp_from_scanoutpos() and computed by 124 + * drm_calc_timestamping_constants(). 125 + */ 126 + int framedur_ns; 127 + /** 128 + * @linedur_ns: Line duration in ns, used by 129 + * drm_calc_vbltimestamp_from_scanoutpos() and computed by 130 + * drm_calc_timestamping_constants(). 131 + */ 132 + int linedur_ns; 133 + 134 + /** 135 + * @hwmode: 136 + * 137 + * Cache of the current hardware display mode. Only valid when @enabled 138 + * is set. This is used by helpers like 139 + * drm_calc_vbltimestamp_from_scanoutpos(). We can't just access the 140 + * hardware mode by e.g. looking at &drm_crtc_state.adjusted_mode, 141 + * because that one is really hard to get from interrupt context. 142 + */ 143 + struct drm_display_mode hwmode; 144 + 145 + /** 146 + * @enabled: Tracks the enabling state of the corresponding &drm_crtc to 147 + * avoid double-disabling and hence corrupting saved state. Needed by 148 + * drivers not using atomic KMS, since those might go through their CRTC 149 + * disabling functions multiple times. 150 + */ 151 + bool enabled; 152 + }; 153 + 154 + int drm_vblank_init(struct drm_device *dev, unsigned int num_crtcs); 155 + u32 drm_crtc_vblank_count(struct drm_crtc *crtc); 156 + u32 drm_crtc_vblank_count_and_time(struct drm_crtc *crtc, 157 + struct timeval *vblanktime); 158 + void drm_crtc_send_vblank_event(struct drm_crtc *crtc, 159 + struct drm_pending_vblank_event *e); 160 + void drm_crtc_arm_vblank_event(struct drm_crtc *crtc, 161 + struct drm_pending_vblank_event *e); 162 + bool drm_handle_vblank(struct drm_device *dev, unsigned int pipe); 163 + bool drm_crtc_handle_vblank(struct drm_crtc *crtc); 164 + int drm_crtc_vblank_get(struct drm_crtc *crtc); 165 + void drm_crtc_vblank_put(struct drm_crtc *crtc); 166 + void drm_wait_one_vblank(struct drm_device *dev, unsigned int pipe); 167 + void drm_crtc_wait_one_vblank(struct drm_crtc *crtc); 168 + void drm_crtc_vblank_off(struct drm_crtc *crtc); 169 + void drm_crtc_vblank_reset(struct drm_crtc *crtc); 170 + void drm_crtc_vblank_on(struct drm_crtc *crtc); 171 + void drm_vblank_cleanup(struct drm_device *dev); 172 + u32 drm_accurate_vblank_count(struct drm_crtc *crtc); 173 + 174 + bool drm_calc_vbltimestamp_from_scanoutpos(struct drm_device *dev, 175 + unsigned int pipe, int *max_error, 176 + struct timeval *vblank_time, 177 + bool in_vblank_irq); 178 + void drm_calc_timestamping_constants(struct drm_crtc *crtc, 179 + const struct drm_display_mode *mode); 180 + wait_queue_head_t *drm_crtc_vblank_waitqueue(struct drm_crtc *crtc); 181 + #endif