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_PLANE_H_
9 #define _DPU_PLANE_H_
10 
11 #include <drm/drm_crtc.h>
12 
13 #include "dpu_kms.h"
14 #include "dpu_hw_mdss.h"
15 #include "dpu_hw_sspp.h"
16 
17 /**
18  * struct dpu_plane_state: Define dpu extension of drm plane state object
19  * @base:	base drm plane state object
20  * @aspace:	pointer to address space for input/output buffers
21  * @stage:	assigned by crtc blender
22  * @needs_qos_remap: qos remap settings need to be updated
23  * @multirect_index: index of the rectangle of SSPP
24  * @multirect_mode: parallel or time multiplex multirect mode
25  * @pending:	whether the current update is still pending
26  * @plane_fetch_bw: calculated BW per plane
27  * @plane_clk: calculated clk per plane
28  * @needs_dirtyfb: whether attached CRTC needs pixel data explicitly flushed
29  */
30 struct dpu_plane_state {
31 	struct drm_plane_state base;
32 	struct msm_gem_address_space *aspace;
33 	enum dpu_stage stage;
34 	bool needs_qos_remap;
35 	uint32_t multirect_index;
36 	uint32_t multirect_mode;
37 	bool pending;
38 
39 	u64 plane_fetch_bw;
40 	u64 plane_clk;
41 
42 	bool needs_dirtyfb;
43 };
44 
45 /**
46  * struct dpu_multirect_plane_states: Defines multirect pair of drm plane states
47  * @r0: drm plane configured on rect 0
48  * @r1: drm plane configured on rect 1
49  */
50 struct dpu_multirect_plane_states {
51 	const struct drm_plane_state *r0;
52 	const struct drm_plane_state *r1;
53 };
54 
55 #define to_dpu_plane_state(x) \
56 	container_of(x, struct dpu_plane_state, base)
57 
58 /**
59  * dpu_plane_pipe - return sspp identifier for the given plane
60  * @plane:   Pointer to DRM plane object
61  * Returns: sspp identifier of the given plane
62  */
63 enum dpu_sspp dpu_plane_pipe(struct drm_plane *plane);
64 
65 /**
66  * is_dpu_plane_virtual - check for virtual plane
67  * @plane: Pointer to DRM plane object
68  * returns: true - if the plane is virtual
69  *          false - if the plane is primary
70  */
71 bool is_dpu_plane_virtual(struct drm_plane *plane);
72 
73 /**
74  * dpu_plane_get_ctl_flush - get control flush mask
75  * @plane:   Pointer to DRM plane object
76  * @ctl: Pointer to control hardware
77  * @flush_sspp: Pointer to sspp flush control word
78  */
79 void dpu_plane_get_ctl_flush(struct drm_plane *plane, struct dpu_hw_ctl *ctl,
80 		u32 *flush_sspp);
81 
82 /**
83  * dpu_plane_flush - final plane operations before commit flush
84  * @plane: Pointer to drm plane structure
85  */
86 void dpu_plane_flush(struct drm_plane *plane);
87 
88 /**
89  * dpu_plane_set_error: enable/disable error condition
90  * @plane: pointer to drm_plane structure
91  */
92 void dpu_plane_set_error(struct drm_plane *plane, bool error);
93 
94 /**
95  * dpu_plane_init - create new dpu plane for the given pipe
96  * @dev:   Pointer to DRM device
97  * @pipe:  dpu hardware pipe identifier
98  * @type:  Plane type - PRIMARY/OVERLAY/CURSOR
99  * @possible_crtcs: bitmask of crtc that can be attached to the given pipe
100  * @master_plane_id: primary plane id of a multirect pipe. 0 value passed for
101  *                   a regular plane initialization. A non-zero primary plane
102  *                   id will be passed for a virtual pipe initialization.
103  *
104  */
105 struct drm_plane *dpu_plane_init(struct drm_device *dev,
106 		uint32_t pipe, enum drm_plane_type type,
107 		unsigned long possible_crtcs, u32 master_plane_id);
108 
109 /**
110  * dpu_plane_validate_multirecti_v2 - validate the multirect planes
111  *				      against hw limitations
112  * @plane: drm plate states of the multirect pair
113  */
114 int dpu_plane_validate_multirect_v2(struct dpu_multirect_plane_states *plane);
115 
116 /**
117  * dpu_plane_clear_multirect - clear multirect bits for the given pipe
118  * @drm_state: Pointer to DRM plane state
119  */
120 void dpu_plane_clear_multirect(const struct drm_plane_state *drm_state);
121 
122 /**
123  * dpu_plane_color_fill - enables color fill on plane
124  * @plane:  Pointer to DRM plane object
125  * @color:  RGB fill color value, [23..16] Blue, [15..8] Green, [7..0] Red
126  * @alpha:  8-bit fill alpha value, 255 selects 100% alpha
127  * Returns: 0 on success
128  */
129 int dpu_plane_color_fill(struct drm_plane *plane,
130 		uint32_t color, uint32_t alpha);
131 
132 #ifdef CONFIG_DEBUG_FS
133 void dpu_plane_danger_signal_ctrl(struct drm_plane *plane, bool enable);
134 #else
135 static inline void dpu_plane_danger_signal_ctrl(struct drm_plane *plane, bool enable) {}
136 #endif
137 
138 #endif /* _DPU_PLANE_H_ */
139