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