1 /* SPDX-License-Identifier: GPL-2.0-only */ 2 /* 3 * Copyright (c) 2016-2018, The Linux Foundation. All rights reserved. 4 * Copyright (C) 2013 Red Hat 5 * Author: Rob Clark <robdclark@gmail.com> 6 */ 7 8 #ifndef __MSM_KMS_H__ 9 #define __MSM_KMS_H__ 10 11 #include <linux/clk.h> 12 #include <linux/regulator/consumer.h> 13 14 #include "msm_drv.h" 15 16 #define MAX_PLANE 4 17 18 /* As there are different display controller blocks depending on the 19 * snapdragon version, the kms support is split out and the appropriate 20 * implementation is loaded at runtime. The kms module is responsible 21 * for constructing the appropriate planes/crtcs/encoders/connectors. 22 */ 23 struct msm_kms_funcs { 24 /* hw initialization: */ 25 int (*hw_init)(struct msm_kms *kms); 26 /* irq handling: */ 27 void (*irq_preinstall)(struct msm_kms *kms); 28 int (*irq_postinstall)(struct msm_kms *kms); 29 void (*irq_uninstall)(struct msm_kms *kms); 30 irqreturn_t (*irq)(struct msm_kms *kms); 31 int (*enable_vblank)(struct msm_kms *kms, struct drm_crtc *crtc); 32 void (*disable_vblank)(struct msm_kms *kms, struct drm_crtc *crtc); 33 34 /* 35 * Atomic commit handling: 36 * 37 * Note that in the case of async commits, the funcs which take 38 * a crtc_mask (ie. ->flush_commit(), and ->complete_commit()) 39 * might not be evenly balanced with ->prepare_commit(), however 40 * each crtc that effected by a ->prepare_commit() (potentially 41 * multiple times) will eventually (at end of vsync period) be 42 * flushed and completed. 43 * 44 * This has some implications about tracking of cleanup state, 45 * for example SMP blocks to release after commit completes. Ie. 46 * cleanup state should be also duplicated in the various 47 * duplicate_state() methods, as the current cleanup state at 48 * ->complete_commit() time may have accumulated cleanup work 49 * from multiple commits. 50 */ 51 52 /** 53 * Enable/disable power/clks needed for hw access done in other 54 * commit related methods. 55 * 56 * If mdp4 is migrated to runpm, we could probably drop these 57 * and use runpm directly. 58 */ 59 void (*enable_commit)(struct msm_kms *kms); 60 void (*disable_commit)(struct msm_kms *kms); 61 62 /** 63 * @check_mode_changed: 64 * 65 * Verify if the commit requires a full modeset on one of CRTCs. 66 */ 67 int (*check_mode_changed)(struct msm_kms *kms, struct drm_atomic_state *state); 68 69 /** 70 * Prepare for atomic commit. This is called after any previous 71 * (async or otherwise) commit has completed. 72 */ 73 void (*prepare_commit)(struct msm_kms *kms, struct drm_atomic_state *state); 74 75 /** 76 * Flush an atomic commit. This is called after the hardware 77 * updates have already been pushed down to effected planes/ 78 * crtcs/encoders/connectors. 79 */ 80 void (*flush_commit)(struct msm_kms *kms, unsigned crtc_mask); 81 82 /** 83 * Wait for any in-progress flush to complete on the specified 84 * crtcs. This should not block if there is no in-progress 85 * commit (ie. don't just wait for a vblank), as it will also 86 * be called before ->prepare_commit() to ensure any potential 87 * "async" commit has completed. 88 */ 89 void (*wait_flush)(struct msm_kms *kms, unsigned crtc_mask); 90 91 /** 92 * Clean up after commit is completed. This is called after 93 * ->wait_flush(), to give the backend a chance to do any 94 * post-commit cleanup. 95 */ 96 void (*complete_commit)(struct msm_kms *kms, unsigned crtc_mask); 97 98 /* 99 * Format handling: 100 */ 101 102 /* misc: */ 103 long (*round_pixclk)(struct msm_kms *kms, unsigned long rate, 104 struct drm_encoder *encoder); 105 /* cleanup: */ 106 void (*destroy)(struct msm_kms *kms); 107 108 /* snapshot: */ 109 void (*snapshot)(struct msm_disp_state *disp_state, struct msm_kms *kms); 110 111 #ifdef CONFIG_DEBUG_FS 112 /* debugfs: */ 113 int (*debugfs_init)(struct msm_kms *kms, struct drm_minor *minor); 114 #endif 115 }; 116 117 struct msm_kms; 118 119 /* 120 * A per-crtc timer for pending async atomic flushes. Scheduled to expire 121 * shortly before vblank to flush pending async updates. 122 */ 123 struct msm_pending_timer { 124 struct msm_hrtimer_work work; 125 struct kthread_worker *worker; 126 struct msm_kms *kms; 127 unsigned crtc_idx; 128 }; 129 130 struct msm_kms { 131 const struct msm_kms_funcs *funcs; 132 struct drm_device *dev; 133 134 /* irq number to be passed on to msm_irq_install */ 135 int irq; 136 bool irq_requested; 137 138 /* rate limit the snapshot capture to once per attach */ 139 atomic_t fault_snapshot_capture; 140 141 /* mapper-id used to request GEM buffer mapped for scanout: */ 142 struct msm_gem_address_space *aspace; 143 144 /* disp snapshot support */ 145 struct kthread_worker *dump_worker; 146 struct kthread_work dump_work; 147 struct mutex dump_mutex; 148 149 /* 150 * For async commit, where ->flush_commit() and later happens 151 * from the crtc's pending_timer close to end of the frame: 152 */ 153 struct mutex commit_lock[MAX_CRTCS]; 154 unsigned pending_crtc_mask; 155 struct msm_pending_timer pending_timers[MAX_CRTCS]; 156 }; 157 158 static inline int msm_kms_init(struct msm_kms *kms, 159 const struct msm_kms_funcs *funcs) 160 { 161 unsigned i, ret; 162 163 for (i = 0; i < ARRAY_SIZE(kms->commit_lock); i++) 164 mutex_init(&kms->commit_lock[i]); 165 166 kms->funcs = funcs; 167 168 for (i = 0; i < ARRAY_SIZE(kms->pending_timers); i++) { 169 ret = msm_atomic_init_pending_timer(&kms->pending_timers[i], kms, i); 170 if (ret) { 171 return ret; 172 } 173 } 174 175 return 0; 176 } 177 178 static inline void msm_kms_destroy(struct msm_kms *kms) 179 { 180 unsigned i; 181 182 for (i = 0; i < ARRAY_SIZE(kms->pending_timers); i++) 183 msm_atomic_destroy_pending_timer(&kms->pending_timers[i]); 184 } 185 186 #define for_each_crtc_mask(dev, crtc, crtc_mask) \ 187 drm_for_each_crtc(crtc, dev) \ 188 for_each_if (drm_crtc_mask(crtc) & (crtc_mask)) 189 190 #define for_each_crtc_mask_reverse(dev, crtc, crtc_mask) \ 191 drm_for_each_crtc_reverse(crtc, dev) \ 192 for_each_if (drm_crtc_mask(crtc) & (crtc_mask)) 193 194 int msm_drm_kms_init(struct device *dev, const struct drm_driver *drv); 195 void msm_drm_kms_uninit(struct device *dev); 196 197 #endif /* __MSM_KMS_H__ */ 198