1 /* 2 * Copyright (c) 2015-2018, The Linux Foundation. All rights reserved. 3 * Copyright (C) 2013 Red Hat 4 * Author: Rob Clark <robdclark@gmail.com> 5 * 6 * This program is free software; you can redistribute it and/or modify it 7 * under the terms of the GNU General Public License version 2 as published by 8 * the Free Software Foundation. 9 * 10 * This program is distributed in the hope that it will be useful, but WITHOUT 11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 13 * more details. 14 * 15 * You should have received a copy of the GNU General Public License along with 16 * this program. If not, see <http://www.gnu.org/licenses/>. 17 */ 18 19 #ifndef __DPU_KMS_H__ 20 #define __DPU_KMS_H__ 21 22 #include "msm_drv.h" 23 #include "msm_kms.h" 24 #include "msm_mmu.h" 25 #include "msm_gem.h" 26 #include "dpu_hw_catalog.h" 27 #include "dpu_hw_ctl.h" 28 #include "dpu_hw_lm.h" 29 #include "dpu_hw_interrupts.h" 30 #include "dpu_hw_top.h" 31 #include "dpu_io_util.h" 32 #include "dpu_rm.h" 33 #include "dpu_core_perf.h" 34 35 #define DRMID(x) ((x) ? (x)->base.id : -1) 36 37 /** 38 * DPU_DEBUG - macro for kms/plane/crtc/encoder/connector logs 39 * @fmt: Pointer to format string 40 */ 41 #define DPU_DEBUG(fmt, ...) \ 42 do { \ 43 if (unlikely(drm_debug & DRM_UT_KMS)) \ 44 DRM_DEBUG(fmt, ##__VA_ARGS__); \ 45 else \ 46 pr_debug(fmt, ##__VA_ARGS__); \ 47 } while (0) 48 49 /** 50 * DPU_DEBUG_DRIVER - macro for hardware driver logging 51 * @fmt: Pointer to format string 52 */ 53 #define DPU_DEBUG_DRIVER(fmt, ...) \ 54 do { \ 55 if (unlikely(drm_debug & DRM_UT_DRIVER)) \ 56 DRM_ERROR(fmt, ##__VA_ARGS__); \ 57 else \ 58 pr_debug(fmt, ##__VA_ARGS__); \ 59 } while (0) 60 61 #define DPU_ERROR(fmt, ...) pr_err("[dpu error]" fmt, ##__VA_ARGS__) 62 63 /** 64 * ktime_compare_safe - compare two ktime structures 65 * This macro is similar to the standard ktime_compare() function, but 66 * attempts to also handle ktime overflows. 67 * @A: First ktime value 68 * @B: Second ktime value 69 * Returns: -1 if A < B, 0 if A == B, 1 if A > B 70 */ 71 #define ktime_compare_safe(A, B) \ 72 ktime_compare(ktime_sub((A), (B)), ktime_set(0, 0)) 73 74 #define DPU_NAME_SIZE 12 75 76 /* timeout in frames waiting for frame done */ 77 #define DPU_FRAME_DONE_TIMEOUT 60 78 79 /* 80 * struct dpu_irq_callback - IRQ callback handlers 81 * @list: list to callback 82 * @func: intr handler 83 * @arg: argument for the handler 84 */ 85 struct dpu_irq_callback { 86 struct list_head list; 87 void (*func)(void *arg, int irq_idx); 88 void *arg; 89 }; 90 91 /** 92 * struct dpu_irq: IRQ structure contains callback registration info 93 * @total_irq: total number of irq_idx obtained from HW interrupts mapping 94 * @irq_cb_tbl: array of IRQ callbacks setting 95 * @enable_counts array of IRQ enable counts 96 * @cb_lock: callback lock 97 * @debugfs_file: debugfs file for irq statistics 98 */ 99 struct dpu_irq { 100 u32 total_irqs; 101 struct list_head *irq_cb_tbl; 102 atomic_t *enable_counts; 103 atomic_t *irq_counts; 104 spinlock_t cb_lock; 105 }; 106 107 struct dpu_kms { 108 struct msm_kms base; 109 struct drm_device *dev; 110 int core_rev; 111 struct dpu_mdss_cfg *catalog; 112 113 /* io/register spaces: */ 114 void __iomem *mmio, *vbif[VBIF_MAX], *reg_dma; 115 unsigned long mmio_len, vbif_len[VBIF_MAX], reg_dma_len; 116 117 struct regulator *vdd; 118 struct regulator *mmagic; 119 struct regulator *venus; 120 121 struct dpu_hw_intr *hw_intr; 122 struct dpu_irq irq_obj; 123 124 struct dpu_core_perf perf; 125 126 struct dpu_rm rm; 127 bool rm_init; 128 129 struct dpu_hw_vbif *hw_vbif[VBIF_MAX]; 130 struct dpu_hw_mdp *hw_mdp; 131 132 bool has_danger_ctrl; 133 134 struct platform_device *pdev; 135 bool rpm_enabled; 136 struct dss_module_power mp; 137 }; 138 139 struct vsync_info { 140 u32 frame_count; 141 u32 line_count; 142 }; 143 144 #define to_dpu_kms(x) container_of(x, struct dpu_kms, base) 145 146 /* get struct msm_kms * from drm_device * */ 147 #define ddev_to_msm_kms(D) ((D) && (D)->dev_private ? \ 148 ((struct msm_drm_private *)((D)->dev_private))->kms : NULL) 149 150 /** 151 * Debugfs functions - extra helper functions for debugfs support 152 * 153 * Main debugfs documentation is located at, 154 * 155 * Documentation/filesystems/debugfs.txt 156 * 157 * @dpu_debugfs_setup_regset32: Initialize data for dpu_debugfs_create_regset32 158 * @dpu_debugfs_create_regset32: Create 32-bit register dump file 159 * @dpu_debugfs_get_root: Get root dentry for DPU_KMS's debugfs node 160 */ 161 162 /** 163 * Companion structure for dpu_debugfs_create_regset32. Do not initialize the 164 * members of this structure explicitly; use dpu_debugfs_setup_regset32 instead. 165 */ 166 struct dpu_debugfs_regset32 { 167 uint32_t offset; 168 uint32_t blk_len; 169 struct dpu_kms *dpu_kms; 170 }; 171 172 /** 173 * dpu_debugfs_setup_regset32 - Initialize register block definition for debugfs 174 * This function is meant to initialize dpu_debugfs_regset32 structures for use 175 * with dpu_debugfs_create_regset32. 176 * @regset: opaque register definition structure 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_setup_regset32(struct dpu_debugfs_regset32 *regset, 182 uint32_t offset, uint32_t length, struct dpu_kms *dpu_kms); 183 184 /** 185 * dpu_debugfs_create_regset32 - Create register read back file for debugfs 186 * 187 * This function is almost identical to the standard debugfs_create_regset32() 188 * function, with the main difference being that a list of register 189 * names/offsets do not need to be provided. The 'read' function simply outputs 190 * sequential register values over a specified range. 191 * 192 * Similar to the related debugfs_create_regset32 API, the structure pointed to 193 * by regset needs to persist for the lifetime of the created file. The calling 194 * code is responsible for initialization/management of this structure. 195 * 196 * The structure pointed to by regset is meant to be opaque. Please use 197 * dpu_debugfs_setup_regset32 to initialize it. 198 * 199 * @name: File name within debugfs 200 * @mode: File mode within debugfs 201 * @parent: Parent directory entry within debugfs, can be NULL 202 * @regset: Pointer to persistent register block definition 203 * 204 * Return: dentry pointer for newly created file, use either debugfs_remove() 205 * or debugfs_remove_recursive() (on a parent directory) to remove the 206 * file 207 */ 208 void *dpu_debugfs_create_regset32(const char *name, umode_t mode, 209 void *parent, struct dpu_debugfs_regset32 *regset); 210 211 /** 212 * dpu_debugfs_get_root - Return root directory entry for KMS's debugfs 213 * 214 * The return value should be passed as the 'parent' argument to subsequent 215 * debugfs create calls. 216 * 217 * @dpu_kms: Pointer to DPU's KMS structure 218 * 219 * Return: dentry pointer for DPU's debugfs location 220 */ 221 void *dpu_debugfs_get_root(struct dpu_kms *dpu_kms); 222 223 /** 224 * DPU info management functions 225 * These functions/definitions allow for building up a 'dpu_info' structure 226 * containing one or more "key=value\n" entries. 227 */ 228 #define DPU_KMS_INFO_MAX_SIZE 4096 229 230 /** 231 * Vblank enable/disable functions 232 */ 233 int dpu_enable_vblank(struct msm_kms *kms, struct drm_crtc *crtc); 234 void dpu_disable_vblank(struct msm_kms *kms, struct drm_crtc *crtc); 235 236 void dpu_kms_encoder_enable(struct drm_encoder *encoder); 237 238 /** 239 * dpu_kms_get_clk_rate() - get the clock rate 240 * @dpu_kms: poiner to dpu_kms structure 241 * @clock_name: clock name to get the rate 242 * 243 * Return: current clock rate 244 */ 245 u64 dpu_kms_get_clk_rate(struct dpu_kms *dpu_kms, char *clock_name); 246 247 #endif /* __dpu_kms_H__ */ 248