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