1 /* SPDX-License-Identifier: GPL-2.0-only */ 2 /* 3 * Copyright (c) 2015-2018, The Linux Foundation. All rights reserved. 4 * Copyright (C) 2013 Red Hat 5 * Author: Rob Clark <robdclark@gmail.com> 6 */ 7 8 #ifndef __DPU_KMS_H__ 9 #define __DPU_KMS_H__ 10 11 #include <linux/interconnect.h> 12 13 #include <drm/drm_drv.h> 14 15 #include "msm_drv.h" 16 #include "msm_kms.h" 17 #include "msm_mmu.h" 18 #include "msm_gem.h" 19 #include "dpu_hw_catalog.h" 20 #include "dpu_hw_ctl.h" 21 #include "dpu_hw_lm.h" 22 #include "dpu_hw_interrupts.h" 23 #include "dpu_hw_top.h" 24 #include "dpu_io_util.h" 25 #include "dpu_rm.h" 26 #include "dpu_core_perf.h" 27 28 #define DRMID(x) ((x) ? (x)->base.id : -1) 29 30 /** 31 * DPU_DEBUG - macro for kms/plane/crtc/encoder/connector logs 32 * @fmt: Pointer to format string 33 */ 34 #define DPU_DEBUG(fmt, ...) \ 35 do { \ 36 if (drm_debug_enabled(DRM_UT_KMS)) \ 37 DRM_DEBUG(fmt, ##__VA_ARGS__); \ 38 else \ 39 pr_debug(fmt, ##__VA_ARGS__); \ 40 } while (0) 41 42 /** 43 * DPU_DEBUG_DRIVER - macro for hardware driver logging 44 * @fmt: Pointer to format string 45 */ 46 #define DPU_DEBUG_DRIVER(fmt, ...) \ 47 do { \ 48 if (drm_debug_enabled(DRM_UT_DRIVER)) \ 49 DRM_ERROR(fmt, ##__VA_ARGS__); \ 50 else \ 51 pr_debug(fmt, ##__VA_ARGS__); \ 52 } while (0) 53 54 #define DPU_ERROR(fmt, ...) pr_err("[dpu error]" fmt, ##__VA_ARGS__) 55 #define DPU_ERROR_RATELIMITED(fmt, ...) pr_err_ratelimited("[dpu error]" fmt, ##__VA_ARGS__) 56 57 /** 58 * ktime_compare_safe - compare two ktime structures 59 * This macro is similar to the standard ktime_compare() function, but 60 * attempts to also handle ktime overflows. 61 * @A: First ktime value 62 * @B: Second ktime value 63 * Returns: -1 if A < B, 0 if A == B, 1 if A > B 64 */ 65 #define ktime_compare_safe(A, B) \ 66 ktime_compare(ktime_sub((A), (B)), ktime_set(0, 0)) 67 68 #define DPU_NAME_SIZE 12 69 70 /* 71 * struct dpu_irq_callback - IRQ callback handlers 72 * @list: list to callback 73 * @func: intr handler 74 * @arg: argument for the handler 75 */ 76 struct dpu_irq_callback { 77 struct list_head list; 78 void (*func)(void *arg, int irq_idx); 79 void *arg; 80 }; 81 82 /** 83 * struct dpu_irq: IRQ structure contains callback registration info 84 * @total_irq: total number of irq_idx obtained from HW interrupts mapping 85 * @irq_cb_tbl: array of IRQ callbacks setting 86 * @enable_counts array of IRQ enable counts 87 * @cb_lock: callback lock 88 * @debugfs_file: debugfs file for irq statistics 89 */ 90 struct dpu_irq { 91 u32 total_irqs; 92 struct list_head *irq_cb_tbl; 93 atomic_t *enable_counts; 94 atomic_t *irq_counts; 95 spinlock_t cb_lock; 96 }; 97 98 struct dpu_kms { 99 struct msm_kms base; 100 struct drm_device *dev; 101 int core_rev; 102 struct dpu_mdss_cfg *catalog; 103 104 /* io/register spaces: */ 105 void __iomem *mmio, *vbif[VBIF_MAX], *reg_dma; 106 107 struct regulator *vdd; 108 struct regulator *mmagic; 109 struct regulator *venus; 110 111 struct dpu_hw_intr *hw_intr; 112 struct dpu_irq irq_obj; 113 114 struct dpu_core_perf perf; 115 116 /* 117 * Global private object state, Do not access directly, use 118 * dpu_kms_global_get_state() 119 */ 120 struct drm_modeset_lock global_state_lock; 121 struct drm_private_obj global_state; 122 123 struct dpu_rm rm; 124 bool rm_init; 125 126 struct dpu_hw_vbif *hw_vbif[VBIF_MAX]; 127 struct dpu_hw_mdp *hw_mdp; 128 129 bool has_danger_ctrl; 130 131 struct platform_device *pdev; 132 bool rpm_enabled; 133 134 struct opp_table *opp_table; 135 bool has_opp_table; 136 137 struct dss_module_power mp; 138 139 /* reference count bandwidth requests, so we know when we can 140 * release bandwidth. Each atomic update increments, and frame- 141 * done event decrements. Additionally, for video mode, the 142 * reference is incremented when crtc is enabled, and decremented 143 * when disabled. 144 */ 145 atomic_t bandwidth_ref; 146 struct icc_path *path[2]; 147 u32 num_paths; 148 }; 149 150 struct vsync_info { 151 u32 frame_count; 152 u32 line_count; 153 }; 154 155 #define to_dpu_kms(x) container_of(x, struct dpu_kms, base) 156 157 #define to_dpu_global_state(x) container_of(x, struct dpu_global_state, base) 158 159 /* Global private object state for tracking resources that are shared across 160 * multiple kms objects (planes/crtcs/etc). 161 */ 162 struct dpu_global_state { 163 struct drm_private_state base; 164 165 uint32_t pingpong_to_enc_id[PINGPONG_MAX - PINGPONG_0]; 166 uint32_t mixer_to_enc_id[LM_MAX - LM_0]; 167 uint32_t ctl_to_enc_id[CTL_MAX - CTL_0]; 168 uint32_t intf_to_enc_id[INTF_MAX - INTF_0]; 169 uint32_t dspp_to_enc_id[DSPP_MAX - DSPP_0]; 170 }; 171 172 struct dpu_global_state 173 *dpu_kms_get_existing_global_state(struct dpu_kms *dpu_kms); 174 struct dpu_global_state 175 *__must_check dpu_kms_get_global_state(struct drm_atomic_state *s); 176 177 /** 178 * Debugfs functions - extra helper functions for debugfs support 179 * 180 * Main debugfs documentation is located at, 181 * 182 * Documentation/filesystems/debugfs.rst 183 * 184 * @dpu_debugfs_setup_regset32: Initialize data for dpu_debugfs_create_regset32 185 * @dpu_debugfs_create_regset32: Create 32-bit register dump file 186 * @dpu_debugfs_get_root: Get root dentry for DPU_KMS's debugfs node 187 */ 188 189 /** 190 * Companion structure for dpu_debugfs_create_regset32. Do not initialize the 191 * members of this structure explicitly; use dpu_debugfs_setup_regset32 instead. 192 */ 193 struct dpu_debugfs_regset32 { 194 uint32_t offset; 195 uint32_t blk_len; 196 struct dpu_kms *dpu_kms; 197 }; 198 199 /** 200 * dpu_debugfs_setup_regset32 - Initialize register block definition for debugfs 201 * This function is meant to initialize dpu_debugfs_regset32 structures for use 202 * with dpu_debugfs_create_regset32. 203 * @regset: opaque register definition structure 204 * @offset: sub-block offset 205 * @length: sub-block length, in bytes 206 * @dpu_kms: pointer to dpu kms structure 207 */ 208 void dpu_debugfs_setup_regset32(struct dpu_debugfs_regset32 *regset, 209 uint32_t offset, uint32_t length, struct dpu_kms *dpu_kms); 210 211 /** 212 * dpu_debugfs_create_regset32 - Create register read back file for debugfs 213 * 214 * This function is almost identical to the standard debugfs_create_regset32() 215 * function, with the main difference being that a list of register 216 * names/offsets do not need to be provided. The 'read' function simply outputs 217 * sequential register values over a specified range. 218 * 219 * Similar to the related debugfs_create_regset32 API, the structure pointed to 220 * by regset needs to persist for the lifetime of the created file. The calling 221 * code is responsible for initialization/management of this structure. 222 * 223 * The structure pointed to by regset is meant to be opaque. Please use 224 * dpu_debugfs_setup_regset32 to initialize it. 225 * 226 * @name: File name within debugfs 227 * @mode: File mode within debugfs 228 * @parent: Parent directory entry within debugfs, can be NULL 229 * @regset: Pointer to persistent register block definition 230 */ 231 void dpu_debugfs_create_regset32(const char *name, umode_t mode, 232 void *parent, struct dpu_debugfs_regset32 *regset); 233 234 /** 235 * dpu_debugfs_get_root - Return root directory entry for KMS's debugfs 236 * 237 * The return value should be passed as the 'parent' argument to subsequent 238 * debugfs create calls. 239 * 240 * @dpu_kms: Pointer to DPU's KMS structure 241 * 242 * Return: dentry pointer for DPU's debugfs location 243 */ 244 void *dpu_debugfs_get_root(struct dpu_kms *dpu_kms); 245 246 /** 247 * DPU info management functions 248 * These functions/definitions allow for building up a 'dpu_info' structure 249 * containing one or more "key=value\n" entries. 250 */ 251 #define DPU_KMS_INFO_MAX_SIZE 4096 252 253 /** 254 * Vblank enable/disable functions 255 */ 256 int dpu_enable_vblank(struct msm_kms *kms, struct drm_crtc *crtc); 257 void dpu_disable_vblank(struct msm_kms *kms, struct drm_crtc *crtc); 258 259 void dpu_kms_encoder_enable(struct drm_encoder *encoder); 260 261 /** 262 * dpu_kms_get_clk_rate() - get the clock rate 263 * @dpu_kms: poiner to dpu_kms structure 264 * @clock_name: clock name to get the rate 265 * 266 * Return: current clock rate 267 */ 268 u64 dpu_kms_get_clk_rate(struct dpu_kms *dpu_kms, char *clock_name); 269 270 #endif /* __dpu_kms_H__ */ 271