Linux Audio

Check our new training course

Loading...
  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_rm.h"
 25#include "dpu_core_perf.h"
 26
 27#define DRMID(x) ((x) ? (x)->base.id : -1)
 28
 29/**
 30 * DPU_DEBUG - macro for kms/plane/crtc/encoder/connector logs
 31 * @fmt: Pointer to format string
 32 */
 33#define DPU_DEBUG(fmt, ...)                                                \
 34	do {                                                               \
 35		if (drm_debug_enabled(DRM_UT_KMS))                         \
 36			DRM_DEBUG(fmt, ##__VA_ARGS__); \
 37		else                                                       \
 38			pr_debug(fmt, ##__VA_ARGS__);                      \
 39	} while (0)
 40
 41/**
 42 * DPU_DEBUG_DRIVER - macro for hardware driver logging
 43 * @fmt: Pointer to format string
 44 */
 45#define DPU_DEBUG_DRIVER(fmt, ...)                                         \
 46	do {                                                               \
 47		if (drm_debug_enabled(DRM_UT_DRIVER))                      \
 48			DRM_ERROR(fmt, ##__VA_ARGS__); \
 49		else                                                       \
 50			pr_debug(fmt, ##__VA_ARGS__);                      \
 51	} while (0)
 52
 53#define DPU_ERROR(fmt, ...) pr_err("[dpu error]" fmt, ##__VA_ARGS__)
 54#define DPU_ERROR_RATELIMITED(fmt, ...) pr_err_ratelimited("[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
 67struct dpu_kms {
 68	struct msm_kms base;
 69	struct drm_device *dev;
 70	const struct dpu_mdss_cfg *catalog;
 71	const struct msm_mdss_data *mdss;
 72
 73	/* io/register spaces: */
 74	void __iomem *mmio, *vbif[VBIF_MAX];
 75
 76	struct regulator *vdd;
 77	struct regulator *mmagic;
 78	struct regulator *venus;
 79
 80	struct dpu_hw_intr *hw_intr;
 81
 82	struct dpu_core_perf perf;
 83
 84	/*
 85	 * Global private object state, Do not access directly, use
 86	 * dpu_kms_global_get_state()
 87	 */
 88	struct drm_private_obj global_state;
 89
 90	struct dpu_rm rm;
 91
 92	struct dpu_hw_vbif *hw_vbif[VBIF_MAX];
 93	struct dpu_hw_mdp *hw_mdp;
 94
 95	bool has_danger_ctrl;
 96
 97	struct platform_device *pdev;
 98	bool rpm_enabled;
 99
100	struct clk_bulk_data *clocks;
101	size_t num_clocks;
102
103	/* reference count bandwidth requests, so we know when we can
104	 * release bandwidth.  Each atomic update increments, and frame-
105	 * done event decrements.  Additionally, for video mode, the
106	 * reference is incremented when crtc is enabled, and decremented
107	 * when disabled.
108	 */
109	atomic_t bandwidth_ref;
110	struct icc_path *path[2];
111	u32 num_paths;
112};
113
114struct vsync_info {
115	u32 frame_count;
116	u32 line_count;
117};
118
119#define DPU_ENC_WR_PTR_START_TIMEOUT_US 20000
120
121#define DPU_ENC_MAX_POLL_TIMEOUT_US	2000
122
123#define to_dpu_kms(x) container_of(x, struct dpu_kms, base)
124
125#define to_dpu_global_state(x) container_of(x, struct dpu_global_state, base)
126
127/* Global private object state for tracking resources that are shared across
128 * multiple kms objects (planes/crtcs/etc).
129 */
130struct dpu_global_state {
131	struct drm_private_state base;
132
133	uint32_t pingpong_to_enc_id[PINGPONG_MAX - PINGPONG_0];
134	uint32_t mixer_to_enc_id[LM_MAX - LM_0];
135	uint32_t ctl_to_enc_id[CTL_MAX - CTL_0];
136	uint32_t dspp_to_enc_id[DSPP_MAX - DSPP_0];
137	uint32_t dsc_to_enc_id[DSC_MAX - DSC_0];
138	uint32_t cdm_to_enc_id;
139};
140
141struct dpu_global_state
142	*dpu_kms_get_existing_global_state(struct dpu_kms *dpu_kms);
143struct dpu_global_state
144	*__must_check dpu_kms_get_global_state(struct drm_atomic_state *s);
145
146/**
147 * Debugfs functions - extra helper functions for debugfs support
148 *
149 * Main debugfs documentation is located at,
150 *
151 * Documentation/filesystems/debugfs.rst
152 *
153 * @dpu_debugfs_create_regset32: Create 32-bit register dump file
154 */
155
156/**
157 * dpu_debugfs_create_regset32 - Create register read back file for debugfs
158 *
159 * This function is almost identical to the standard debugfs_create_regset32()
160 * function, with the main difference being that a list of register
161 * names/offsets do not need to be provided. The 'read' function simply outputs
162 * sequential register values over a specified range.
163 *
164 * @name:   File name within debugfs
165 * @mode:   File mode within debugfs
166 * @parent: Parent directory entry within debugfs, can be NULL
167 * @offset: sub-block offset
168 * @length: sub-block length, in bytes
169 * @dpu_kms: pointer to dpu kms structure
170 */
171void dpu_debugfs_create_regset32(const char *name, umode_t mode,
172		void *parent,
173		uint32_t offset, uint32_t length, struct dpu_kms *dpu_kms);
174
175/**
176 * dpu_debugfs_get_root - Return root directory entry for KMS's debugfs
177 *
178 * The return value should be passed as the 'parent' argument to subsequent
179 * debugfs create calls.
180 *
181 * @dpu_kms: Pointer to DPU's KMS structure
182 *
183 * Return: dentry pointer for DPU's debugfs location
184 */
185void *dpu_debugfs_get_root(struct dpu_kms *dpu_kms);
186
187/**
188 * DPU info management functions
189 * These functions/definitions allow for building up a 'dpu_info' structure
190 * containing one or more "key=value\n" entries.
191 */
192#define DPU_KMS_INFO_MAX_SIZE	4096
193
194/**
195 * Vblank enable/disable functions
196 */
197int dpu_enable_vblank(struct msm_kms *kms, struct drm_crtc *crtc);
198void dpu_disable_vblank(struct msm_kms *kms, struct drm_crtc *crtc);
199
200/**
201 * dpu_kms_get_clk_rate() - get the clock rate
202 * @dpu_kms:  pointer to dpu_kms structure
203 * @clock_name: clock name to get the rate
204 *
205 * Return: current clock rate
206 */
207unsigned long dpu_kms_get_clk_rate(struct dpu_kms *dpu_kms, char *clock_name);
208
209#endif /* __dpu_kms_H__ */