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 56 /** 57 * ktime_compare_safe - compare two ktime structures 58 * This macro is similar to the standard ktime_compare() function, but 59 * attempts to also handle ktime overflows. 60 * @A: First ktime value 61 * @B: Second ktime value 62 * Returns: -1 if A < B, 0 if A == B, 1 if A > B 63 */ 64 #define ktime_compare_safe(A, B) \ 65 ktime_compare(ktime_sub((A), (B)), ktime_set(0, 0)) 66 67 #define DPU_NAME_SIZE 12 68 69 /* 70 * struct dpu_irq_callback - IRQ callback handlers 71 * @list: list to callback 72 * @func: intr handler 73 * @arg: argument for the handler 74 */ 75 struct dpu_irq_callback { 76 struct list_head list; 77 void (*func)(void *arg, int irq_idx); 78 void *arg; 79 }; 80 81 struct dpu_kms { 82 struct msm_kms base; 83 struct drm_device *dev; 84 int core_rev; 85 struct dpu_mdss_cfg *catalog; 86 87 /* io/register spaces: */ 88 void __iomem *mmio, *vbif[VBIF_MAX], *reg_dma; 89 90 struct regulator *vdd; 91 struct regulator *mmagic; 92 struct regulator *venus; 93 94 struct dpu_hw_intr *hw_intr; 95 96 struct dpu_core_perf perf; 97 98 /* 99 * Global private object state, Do not access directly, use 100 * dpu_kms_global_get_state() 101 */ 102 struct drm_modeset_lock global_state_lock; 103 struct drm_private_obj global_state; 104 105 struct dpu_rm rm; 106 bool rm_init; 107 108 struct dpu_hw_vbif *hw_vbif[VBIF_MAX]; 109 struct dpu_hw_mdp *hw_mdp; 110 111 bool has_danger_ctrl; 112 113 struct platform_device *pdev; 114 bool rpm_enabled; 115 116 struct dss_module_power mp; 117 118 /* reference count bandwidth requests, so we know when we can 119 * release bandwidth. Each atomic update increments, and frame- 120 * done event decrements. Additionally, for video mode, the 121 * reference is incremented when crtc is enabled, and decremented 122 * when disabled. 123 */ 124 atomic_t bandwidth_ref; 125 struct icc_path *path[2]; 126 u32 num_paths; 127 }; 128 129 struct vsync_info { 130 u32 frame_count; 131 u32 line_count; 132 }; 133 134 #define to_dpu_kms(x) container_of(x, struct dpu_kms, base) 135 136 #define to_dpu_global_state(x) container_of(x, struct dpu_global_state, base) 137 138 /* Global private object state for tracking resources that are shared across 139 * multiple kms objects (planes/crtcs/etc). 140 */ 141 struct dpu_global_state { 142 struct drm_private_state base; 143 144 uint32_t pingpong_to_enc_id[PINGPONG_MAX - PINGPONG_0]; 145 uint32_t mixer_to_enc_id[LM_MAX - LM_0]; 146 uint32_t ctl_to_enc_id[CTL_MAX - CTL_0]; 147 uint32_t intf_to_enc_id[INTF_MAX - INTF_0]; 148 uint32_t dspp_to_enc_id[DSPP_MAX - DSPP_0]; 149 }; 150 151 struct dpu_global_state 152 *dpu_kms_get_existing_global_state(struct dpu_kms *dpu_kms); 153 struct dpu_global_state 154 *__must_check dpu_kms_get_global_state(struct drm_atomic_state *s); 155 156 /** 157 * Debugfs functions - extra helper functions for debugfs support 158 * 159 * Main debugfs documentation is located at, 160 * 161 * Documentation/filesystems/debugfs.rst 162 * 163 * @dpu_debugfs_create_regset32: Create 32-bit register dump file 164 */ 165 166 /** 167 * dpu_debugfs_create_regset32 - Create register read back file for debugfs 168 * 169 * This function is almost identical to the standard debugfs_create_regset32() 170 * function, with the main difference being that a list of register 171 * names/offsets do not need to be provided. The 'read' function simply outputs 172 * sequential register values over a specified range. 173 * 174 * @name: File name within debugfs 175 * @mode: File mode within debugfs 176 * @parent: Parent directory entry within debugfs, can be NULL 177 * @offset: sub-block offset 178 * @length: sub-block length, in bytes 179 * @dpu_kms: pointer to dpu kms structure 180 */ 181 void dpu_debugfs_create_regset32(const char *name, umode_t mode, 182 void *parent, 183 uint32_t offset, uint32_t length, struct dpu_kms *dpu_kms); 184 185 /** 186 * dpu_debugfs_get_root - Return root directory entry for KMS's debugfs 187 * 188 * The return value should be passed as the 'parent' argument to subsequent 189 * debugfs create calls. 190 * 191 * @dpu_kms: Pointer to DPU's KMS structure 192 * 193 * Return: dentry pointer for DPU's debugfs location 194 */ 195 void *dpu_debugfs_get_root(struct dpu_kms *dpu_kms); 196 197 /** 198 * DPU info management functions 199 * These functions/definitions allow for building up a 'dpu_info' structure 200 * containing one or more "key=value\n" entries. 201 */ 202 #define DPU_KMS_INFO_MAX_SIZE 4096 203 204 /** 205 * Vblank enable/disable functions 206 */ 207 int dpu_enable_vblank(struct msm_kms *kms, struct drm_crtc *crtc); 208 void dpu_disable_vblank(struct msm_kms *kms, struct drm_crtc *crtc); 209 210 /** 211 * dpu_kms_get_clk_rate() - get the clock rate 212 * @dpu_kms: pointer to dpu_kms structure 213 * @clock_name: clock name to get the rate 214 * 215 * Return: current clock rate 216 */ 217 u64 dpu_kms_get_clk_rate(struct dpu_kms *dpu_kms, char *clock_name); 218 219 #endif /* __dpu_kms_H__ */ 220