1 // SPDX-License-Identifier: MIT 2 /* 3 * Copyright © 2023 Intel Corporation 4 */ 5 6 #include <drm/drm_crtc.h> 7 #include <drm/drm_vblank.h> 8 9 #include "gt/intel_rps.h" 10 #include "i915_drv.h" 11 #include "i915_reg.h" 12 #include "intel_display_core.h" 13 #include "intel_display_irq.h" 14 #include "intel_display_rps.h" 15 #include "intel_display_types.h" 16 17 struct wait_rps_boost { 18 struct wait_queue_entry wait; 19 20 struct drm_crtc *crtc; 21 struct i915_request *request; 22 }; 23 24 static int do_rps_boost(struct wait_queue_entry *_wait, 25 unsigned mode, int sync, void *key) 26 { 27 struct wait_rps_boost *wait = container_of(_wait, typeof(*wait), wait); 28 struct i915_request *rq = wait->request; 29 30 /* 31 * If we missed the vblank, but the request is already running it 32 * is reasonable to assume that it will complete before the next 33 * vblank without our intervention, so leave RPS alone. 34 */ 35 if (!i915_request_started(rq)) 36 intel_rps_boost(rq); 37 i915_request_put(rq); 38 39 drm_crtc_vblank_put(wait->crtc); 40 41 list_del(&wait->wait.entry); 42 kfree(wait); 43 return 1; 44 } 45 46 void intel_display_rps_boost_after_vblank(struct drm_crtc *crtc, 47 struct dma_fence *fence) 48 { 49 struct intel_display *display = to_intel_display(crtc->dev); 50 struct wait_rps_boost *wait; 51 52 if (!dma_fence_is_i915(fence)) 53 return; 54 55 if (DISPLAY_VER(display) < 6) 56 return; 57 58 if (drm_crtc_vblank_get(crtc)) 59 return; 60 61 wait = kmalloc(sizeof(*wait), GFP_KERNEL); 62 if (!wait) { 63 drm_crtc_vblank_put(crtc); 64 return; 65 } 66 67 wait->request = to_request(dma_fence_get(fence)); 68 wait->crtc = crtc; 69 70 wait->wait.func = do_rps_boost; 71 wait->wait.flags = 0; 72 73 add_wait_queue(drm_crtc_vblank_waitqueue(crtc), &wait->wait); 74 } 75 76 void intel_display_rps_mark_interactive(struct intel_display *display, 77 struct intel_atomic_state *state, 78 bool interactive) 79 { 80 struct drm_i915_private *i915 = to_i915(display->drm); 81 82 if (state->rps_interactive == interactive) 83 return; 84 85 intel_rps_mark_interactive(&to_gt(i915)->rps, interactive); 86 state->rps_interactive = interactive; 87 } 88 89 void ilk_display_rps_enable(struct intel_display *display) 90 { 91 spin_lock(&display->irq.lock); 92 ilk_enable_display_irq(display, DE_PCU_EVENT); 93 spin_unlock(&display->irq.lock); 94 } 95 96 void ilk_display_rps_disable(struct intel_display *display) 97 { 98 spin_lock(&display->irq.lock); 99 ilk_disable_display_irq(display, DE_PCU_EVENT); 100 spin_unlock(&display->irq.lock); 101 } 102 103 void ilk_display_rps_irq_handler(struct intel_display *display) 104 { 105 struct drm_i915_private *i915 = to_i915(display->drm); 106 107 gen5_rps_irq_handler(&to_gt(i915)->rps); 108 } 109