xref: /linux/drivers/gpu/drm/vmwgfx/vmwgfx_kms.h (revision 7b0062036c3b71b4a69e244ecf0502c06c4cf5f0)
1dff96888SDirk Hohndel (VMware) /* SPDX-License-Identifier: GPL-2.0 OR MIT */
2fb1d9738SJakob Bornecrantz /**************************************************************************
3fb1d9738SJakob Bornecrantz  *
46703e28fSZack Rusin  * Copyright 2009-2023 VMware, Inc., Palo Alto, CA., USA
5fb1d9738SJakob Bornecrantz  *
6fb1d9738SJakob Bornecrantz  * Permission is hereby granted, free of charge, to any person obtaining a
7fb1d9738SJakob Bornecrantz  * copy of this software and associated documentation files (the
8fb1d9738SJakob Bornecrantz  * "Software"), to deal in the Software without restriction, including
9fb1d9738SJakob Bornecrantz  * without limitation the rights to use, copy, modify, merge, publish,
10fb1d9738SJakob Bornecrantz  * distribute, sub license, and/or sell copies of the Software, and to
11fb1d9738SJakob Bornecrantz  * permit persons to whom the Software is furnished to do so, subject to
12fb1d9738SJakob Bornecrantz  * the following conditions:
13fb1d9738SJakob Bornecrantz  *
14fb1d9738SJakob Bornecrantz  * The above copyright notice and this permission notice (including the
15fb1d9738SJakob Bornecrantz  * next paragraph) shall be included in all copies or substantial portions
16fb1d9738SJakob Bornecrantz  * of the Software.
17fb1d9738SJakob Bornecrantz  *
18fb1d9738SJakob Bornecrantz  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19fb1d9738SJakob Bornecrantz  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20fb1d9738SJakob Bornecrantz  * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
21fb1d9738SJakob Bornecrantz  * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
22fb1d9738SJakob Bornecrantz  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
23fb1d9738SJakob Bornecrantz  * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
24fb1d9738SJakob Bornecrantz  * USE OR OTHER DEALINGS IN THE SOFTWARE.
25fb1d9738SJakob Bornecrantz  *
26fb1d9738SJakob Bornecrantz  **************************************************************************/
27fb1d9738SJakob Bornecrantz 
28fb1d9738SJakob Bornecrantz #ifndef VMWGFX_KMS_H_
29fb1d9738SJakob Bornecrantz #define VMWGFX_KMS_H_
30fb1d9738SJakob Bornecrantz 
319338203cSLaurent Pinchart #include <drm/drm_encoder.h>
32720cf96dSVille Syrjälä #include <drm/drm_framebuffer.h>
33fcd70cd3SDaniel Vetter #include <drm/drm_probe_helper.h>
34d5c1f011SSam Ravnborg 
35fb1d9738SJakob Bornecrantz #include "vmwgfx_drv.h"
36fb1d9738SJakob Bornecrantz 
37e41774c0SDeepak Rawat /**
38e41774c0SDeepak Rawat  * struct vmw_du_update_plane - Closure structure for vmw_du_helper_plane_update
39e41774c0SDeepak Rawat  * @plane: Plane which is being updated.
40e41774c0SDeepak Rawat  * @old_state: Old state of plane.
41e41774c0SDeepak Rawat  * @dev_priv: Device private.
42e41774c0SDeepak Rawat  * @du: Display unit on which to update the plane.
43e41774c0SDeepak Rawat  * @vfb: Framebuffer which is blitted to display unit.
44e41774c0SDeepak Rawat  * @out_fence: Out fence for resource finish.
45e41774c0SDeepak Rawat  * @mutex: The mutex used to protect resource reservation.
46e41774c0SDeepak Rawat  * @cpu_blit: True if need cpu blit.
47e41774c0SDeepak Rawat  * @intr: Whether to perform waits interruptible if possible.
48e41774c0SDeepak Rawat  *
49e41774c0SDeepak Rawat  * This structure loosely represent the set of operations needed to perform a
50e41774c0SDeepak Rawat  * plane update on a display unit. Implementer will define that functionality
51e41774c0SDeepak Rawat  * according to the function callbacks for this structure. In brief it involves
52e41774c0SDeepak Rawat  * surface/buffer object validation, populate FIFO commands and command
53e41774c0SDeepak Rawat  * submission to the device.
54e41774c0SDeepak Rawat  */
55e41774c0SDeepak Rawat struct vmw_du_update_plane {
56e41774c0SDeepak Rawat 	/**
57e41774c0SDeepak Rawat 	 * @calc_fifo_size: Calculate fifo size.
58e41774c0SDeepak Rawat 	 *
59e41774c0SDeepak Rawat 	 * Determine fifo size for the commands needed for update. The number of
60e41774c0SDeepak Rawat 	 * damage clips on display unit @num_hits will be passed to allocate
61e41774c0SDeepak Rawat 	 * sufficient fifo space.
62e41774c0SDeepak Rawat 	 *
63e41774c0SDeepak Rawat 	 * Return: Fifo size needed
64e41774c0SDeepak Rawat 	 */
65e41774c0SDeepak Rawat 	uint32_t (*calc_fifo_size)(struct vmw_du_update_plane *update,
66e41774c0SDeepak Rawat 				   uint32_t num_hits);
6736cc79bcSSinclair Yeh 
68e41774c0SDeepak Rawat 	/**
69e41774c0SDeepak Rawat 	 * @post_prepare: Populate fifo for resource preparation.
70e41774c0SDeepak Rawat 	 *
71e41774c0SDeepak Rawat 	 * Some surface resource or buffer object need some extra cmd submission
72e41774c0SDeepak Rawat 	 * like update GB image for proxy surface and define a GMRFB for screen
7305436815STom Rix 	 * object. That should be done here as this callback will be
74e41774c0SDeepak Rawat 	 * called after FIFO allocation with the address of command buufer.
75e41774c0SDeepak Rawat 	 *
76e41774c0SDeepak Rawat 	 * This callback is optional.
77e41774c0SDeepak Rawat 	 *
78e41774c0SDeepak Rawat 	 * Return: Size of commands populated to command buffer.
79e41774c0SDeepak Rawat 	 */
80e41774c0SDeepak Rawat 	uint32_t (*post_prepare)(struct vmw_du_update_plane *update, void *cmd);
81e41774c0SDeepak Rawat 
82e41774c0SDeepak Rawat 	/**
83e41774c0SDeepak Rawat 	 * @pre_clip: Populate fifo before clip.
84e41774c0SDeepak Rawat 	 *
85e41774c0SDeepak Rawat 	 * This is where pre clip related command should be populated like
86e41774c0SDeepak Rawat 	 * surface copy/DMA, etc.
87e41774c0SDeepak Rawat 	 *
88e41774c0SDeepak Rawat 	 * This callback is optional.
89e41774c0SDeepak Rawat 	 *
90e41774c0SDeepak Rawat 	 * Return: Size of commands populated to command buffer.
91e41774c0SDeepak Rawat 	 */
92e41774c0SDeepak Rawat 	uint32_t (*pre_clip)(struct vmw_du_update_plane *update, void *cmd,
93e41774c0SDeepak Rawat 			     uint32_t num_hits);
94e41774c0SDeepak Rawat 
95e41774c0SDeepak Rawat 	/**
96e41774c0SDeepak Rawat 	 * @clip: Populate fifo for clip.
97e41774c0SDeepak Rawat 	 *
98e41774c0SDeepak Rawat 	 * This is where to populate clips for surface copy/dma or blit commands
99e41774c0SDeepak Rawat 	 * if needed. This will be called times have damage in display unit,
100e41774c0SDeepak Rawat 	 * which is one if doing full update. @clip is the damage in destination
101e41774c0SDeepak Rawat 	 * coordinates which is crtc/DU and @src_x, @src_y is damage clip src in
102e41774c0SDeepak Rawat 	 * framebuffer coordinate.
103e41774c0SDeepak Rawat 	 *
104e41774c0SDeepak Rawat 	 * This callback is optional.
105e41774c0SDeepak Rawat 	 *
106e41774c0SDeepak Rawat 	 * Return: Size of commands populated to command buffer.
107e41774c0SDeepak Rawat 	 */
108e41774c0SDeepak Rawat 	uint32_t (*clip)(struct vmw_du_update_plane *update, void *cmd,
109e41774c0SDeepak Rawat 			 struct drm_rect *clip, uint32_t src_x, uint32_t src_y);
110e41774c0SDeepak Rawat 
111e41774c0SDeepak Rawat 	/**
112e41774c0SDeepak Rawat 	 * @post_clip: Populate fifo after clip.
113e41774c0SDeepak Rawat 	 *
114e41774c0SDeepak Rawat 	 * This is where to populate display unit update commands or blit
115e41774c0SDeepak Rawat 	 * commands.
116e41774c0SDeepak Rawat 	 *
117e41774c0SDeepak Rawat 	 * Return: Size of commands populated to command buffer.
118e41774c0SDeepak Rawat 	 */
119e41774c0SDeepak Rawat 	uint32_t (*post_clip)(struct vmw_du_update_plane *update, void *cmd,
120e41774c0SDeepak Rawat 				    struct drm_rect *bb);
121e41774c0SDeepak Rawat 
122e41774c0SDeepak Rawat 	struct drm_plane *plane;
123e41774c0SDeepak Rawat 	struct drm_plane_state *old_state;
124e41774c0SDeepak Rawat 	struct vmw_private *dev_priv;
125e41774c0SDeepak Rawat 	struct vmw_display_unit *du;
126e41774c0SDeepak Rawat 	struct vmw_framebuffer *vfb;
127e41774c0SDeepak Rawat 	struct vmw_fence_obj **out_fence;
128e41774c0SDeepak Rawat 	struct mutex *mutex;
129e41774c0SDeepak Rawat 	bool intr;
130e41774c0SDeepak Rawat };
13136cc79bcSSinclair Yeh 
1321a4b172aSThomas Hellstrom /**
13343d1e627SDeepak Rawat  * struct vmw_du_update_plane_surface - closure structure for surface
13443d1e627SDeepak Rawat  * @base: base closure structure.
13543d1e627SDeepak Rawat  * @cmd_start: FIFO command start address (used by SOU only).
13643d1e627SDeepak Rawat  */
13743d1e627SDeepak Rawat struct vmw_du_update_plane_surface {
13843d1e627SDeepak Rawat 	struct vmw_du_update_plane base;
13943d1e627SDeepak Rawat 	/* This member is to handle special case SOU surface update */
14043d1e627SDeepak Rawat 	void *cmd_start;
14143d1e627SDeepak Rawat };
14243d1e627SDeepak Rawat 
14343d1e627SDeepak Rawat /**
144bc7be607SDeepak Rawat  * struct vmw_du_update_plane_buffer - Closure structure for buffer object
145bc7be607SDeepak Rawat  * @base: Base closure structure.
146bc7be607SDeepak Rawat  * @fb_left: x1 for fb damage bounding box.
147bc7be607SDeepak Rawat  * @fb_top: y1 for fb damage bounding box.
148bc7be607SDeepak Rawat  */
149bc7be607SDeepak Rawat struct vmw_du_update_plane_buffer {
150bc7be607SDeepak Rawat 	struct vmw_du_update_plane base;
151bc7be607SDeepak Rawat 	int fb_left, fb_top;
152bc7be607SDeepak Rawat };
153bc7be607SDeepak Rawat 
154bc7be607SDeepak Rawat /**
1551a4b172aSThomas Hellstrom  * struct vmw_kms_dirty - closure structure for the vmw_kms_helper_dirty
1561a4b172aSThomas Hellstrom  * function.
1571a4b172aSThomas Hellstrom  *
1581a4b172aSThomas Hellstrom  * @fifo_commit: Callback that is called once for each display unit after
1591a4b172aSThomas Hellstrom  * all clip rects. This function must commit the fifo space reserved by the
1601a4b172aSThomas Hellstrom  * helper. Set up by the caller.
1611a4b172aSThomas Hellstrom  * @clip: Callback that is called for each cliprect on each display unit.
1621a4b172aSThomas Hellstrom  * Set up by the caller.
1631a4b172aSThomas Hellstrom  * @fifo_reserve_size: Fifo size that the helper should try to allocat for
1641a4b172aSThomas Hellstrom  * each display unit. Set up by the caller.
1651a4b172aSThomas Hellstrom  * @dev_priv: Pointer to the device private. Set up by the helper.
1661a4b172aSThomas Hellstrom  * @unit: The current display unit. Set up by the helper before a call to @clip.
1671a4b172aSThomas Hellstrom  * @cmd: The allocated fifo space. Set up by the helper before the first @clip
1681a4b172aSThomas Hellstrom  * call.
16991e9f352SDeepak Rawat  * @crtc: The crtc for which to build dirty commands.
1701a4b172aSThomas Hellstrom  * @num_hits: Number of clip rect commands for this display unit.
1711a4b172aSThomas Hellstrom  * Cleared by the helper before the first @clip call. Updated by the @clip
1721a4b172aSThomas Hellstrom  * callback.
1731a4b172aSThomas Hellstrom  * @fb_x: Clip rect left side in framebuffer coordinates.
1741a4b172aSThomas Hellstrom  * @fb_y: Clip rect right side in framebuffer coordinates.
1751a4b172aSThomas Hellstrom  * @unit_x1: Clip rect left side in crtc coordinates.
1761a4b172aSThomas Hellstrom  * @unit_y1: Clip rect top side in crtc coordinates.
1771a4b172aSThomas Hellstrom  * @unit_x2: Clip rect right side in crtc coordinates.
1781a4b172aSThomas Hellstrom  * @unit_y2: Clip rect bottom side in crtc coordinates.
1791a4b172aSThomas Hellstrom  *
1801a4b172aSThomas Hellstrom  * The clip rect coordinates are updated by the helper for each @clip call.
1811a4b172aSThomas Hellstrom  * Note that this may be derived from if more info needs to be passed between
1821a4b172aSThomas Hellstrom  * helper caller and helper callbacks.
1831a4b172aSThomas Hellstrom  */
1841a4b172aSThomas Hellstrom struct vmw_kms_dirty {
1851a4b172aSThomas Hellstrom 	void (*fifo_commit)(struct vmw_kms_dirty *);
1861a4b172aSThomas Hellstrom 	void (*clip)(struct vmw_kms_dirty *);
1871a4b172aSThomas Hellstrom 	size_t fifo_reserve_size;
1881a4b172aSThomas Hellstrom 	struct vmw_private *dev_priv;
1891a4b172aSThomas Hellstrom 	struct vmw_display_unit *unit;
1901a4b172aSThomas Hellstrom 	void *cmd;
19191e9f352SDeepak Rawat 	struct drm_crtc *crtc;
1921a4b172aSThomas Hellstrom 	u32 num_hits;
1931a4b172aSThomas Hellstrom 	s32 fb_x;
1941a4b172aSThomas Hellstrom 	s32 fb_y;
1951a4b172aSThomas Hellstrom 	s32 unit_x1;
1961a4b172aSThomas Hellstrom 	s32 unit_y1;
1971a4b172aSThomas Hellstrom 	s32 unit_x2;
1981a4b172aSThomas Hellstrom 	s32 unit_y2;
1991a4b172aSThomas Hellstrom };
200c8261a96SSinclair Yeh 
20156d1c78dSJakob Bornecrantz #define VMWGFX_NUM_DISPLAY_UNITS 8
20256d1c78dSJakob Bornecrantz 
203fb1d9738SJakob Bornecrantz 
204fb1d9738SJakob Bornecrantz #define vmw_framebuffer_to_vfb(x) \
205fb1d9738SJakob Bornecrantz 	container_of(x, struct vmw_framebuffer, base)
206c8261a96SSinclair Yeh #define vmw_framebuffer_to_vfbs(x) \
207c8261a96SSinclair Yeh 	container_of(x, struct vmw_framebuffer_surface, base.base)
208c8261a96SSinclair Yeh #define vmw_framebuffer_to_vfbd(x) \
209f1d34bfdSThomas Hellstrom 	container_of(x, struct vmw_framebuffer_bo, base.base)
210fb1d9738SJakob Bornecrantz 
211fb1d9738SJakob Bornecrantz /**
212fb1d9738SJakob Bornecrantz  * Base class for framebuffers
213fb1d9738SJakob Bornecrantz  *
214fb1d9738SJakob Bornecrantz  * @pin is called the when ever a crtc uses this framebuffer
215fb1d9738SJakob Bornecrantz  * @unpin is called
216fb1d9738SJakob Bornecrantz  */
217fb1d9738SJakob Bornecrantz struct vmw_framebuffer {
218fb1d9738SJakob Bornecrantz 	struct drm_framebuffer base;
219f1d34bfdSThomas Hellstrom 	bool bo;
220c8261a96SSinclair Yeh };
221fb1d9738SJakob Bornecrantz 
222c8261a96SSinclair Yeh struct vmw_framebuffer_surface {
223c8261a96SSinclair Yeh 	struct vmw_framebuffer base;
224c8261a96SSinclair Yeh 	struct vmw_surface *surface;
225f1d34bfdSThomas Hellstrom 	bool is_bo_proxy;  /* true if this is proxy surface for DMA buf */
226c8261a96SSinclair Yeh };
227c8261a96SSinclair Yeh 
228c8261a96SSinclair Yeh 
229f1d34bfdSThomas Hellstrom struct vmw_framebuffer_bo {
230c8261a96SSinclair Yeh 	struct vmw_framebuffer base;
23109881d29SZack Rusin 	struct vmw_bo *buffer;
232c8261a96SSinclair Yeh };
233c8261a96SSinclair Yeh 
234fb1d9738SJakob Bornecrantz 
235d8713d66SLee Jones static const uint32_t __maybe_unused vmw_primary_plane_formats[] = {
23636cc79bcSSinclair Yeh 	DRM_FORMAT_XRGB1555,
23736cc79bcSSinclair Yeh 	DRM_FORMAT_RGB565,
23836cc79bcSSinclair Yeh 	DRM_FORMAT_XRGB8888,
23936cc79bcSSinclair Yeh 	DRM_FORMAT_ARGB8888,
24036cc79bcSSinclair Yeh };
241fb1d9738SJakob Bornecrantz 
242d8713d66SLee Jones static const uint32_t __maybe_unused vmw_cursor_plane_formats[] = {
24336cc79bcSSinclair Yeh 	DRM_FORMAT_ARGB8888,
24436cc79bcSSinclair Yeh };
245bfc2638dSJakob Bornecrantz 
2469c2542a4SSinclair Yeh 
2479c2542a4SSinclair Yeh #define vmw_crtc_state_to_vcs(x) container_of(x, struct vmw_crtc_state, base)
248cc5ec459SSinclair Yeh #define vmw_plane_state_to_vps(x) container_of(x, struct vmw_plane_state, base)
249d7721ca7SSinclair Yeh #define vmw_connector_state_to_vcs(x) \
250d7721ca7SSinclair Yeh 		container_of(x, struct vmw_connector_state, base)
251485d98d4SMartin Krastev #define vmw_plane_to_vcp(x) container_of(x, struct vmw_cursor_plane, base)
2529c2542a4SSinclair Yeh 
2539c2542a4SSinclair Yeh /**
2549c2542a4SSinclair Yeh  * Derived class for crtc state object
2559c2542a4SSinclair Yeh  *
2569c2542a4SSinclair Yeh  * @base DRM crtc object
2579c2542a4SSinclair Yeh  */
2589c2542a4SSinclair Yeh struct vmw_crtc_state {
2599c2542a4SSinclair Yeh 	struct drm_crtc_state base;
2609c2542a4SSinclair Yeh };
2619c2542a4SSinclair Yeh 
26240f9e40bSMichael Banack struct vmw_cursor_plane_state {
263668b2066SZack Rusin 	struct vmw_bo *bo;
264bb6780aaSMichael Banack 	s32 hotspot_x;
265bb6780aaSMichael Banack 	s32 hotspot_y;
26640f9e40bSMichael Banack };
26740f9e40bSMichael Banack 
268fb1d9738SJakob Bornecrantz /**
269cc5ec459SSinclair Yeh  * Derived class for plane state object
270cc5ec459SSinclair Yeh  *
271cc5ec459SSinclair Yeh  * @base DRM plane object
272cc5ec459SSinclair Yeh  * @surf Display surface for STDU
273f1d34bfdSThomas Hellstrom  * @bo display bo for SOU
274cc5ec459SSinclair Yeh  * @content_fb_type Used by STDU.
275f1d34bfdSThomas Hellstrom  * @bo_size Size of the bo, used by Screen Object Display Unit
276cc5ec459SSinclair Yeh  * @pinned pin count for STDU display surface
277cc5ec459SSinclair Yeh  */
278cc5ec459SSinclair Yeh struct vmw_plane_state {
279cc5ec459SSinclair Yeh 	struct drm_plane_state base;
280cc5ec459SSinclair Yeh 	struct vmw_surface *surf;
28109881d29SZack Rusin 	struct vmw_bo *bo;
282cc5ec459SSinclair Yeh 
283cc5ec459SSinclair Yeh 	int content_fb_type;
284f1d34bfdSThomas Hellstrom 	unsigned long bo_size;
285cc5ec459SSinclair Yeh 
286cc5ec459SSinclair Yeh 	int pinned;
287810b3e16SSinclair Yeh 
288810b3e16SSinclair Yeh 	/* For CPU Blit */
289810b3e16SSinclair Yeh 	unsigned int cpp;
290485d98d4SMartin Krastev 
29192f59ac4SMichael Banack 	bool surf_mapped;
29240f9e40bSMichael Banack 	struct vmw_cursor_plane_state cursor;
293cc5ec459SSinclair Yeh };
294cc5ec459SSinclair Yeh 
295d7721ca7SSinclair Yeh 
296d7721ca7SSinclair Yeh /**
297d7721ca7SSinclair Yeh  * Derived class for connector state object
298d7721ca7SSinclair Yeh  *
299d7721ca7SSinclair Yeh  * @base DRM connector object
300d7721ca7SSinclair Yeh  * @is_implicit connector property
301d7721ca7SSinclair Yeh  *
302d7721ca7SSinclair Yeh  */
303d7721ca7SSinclair Yeh struct vmw_connector_state {
304d7721ca7SSinclair Yeh 	struct drm_connector_state base;
305d7721ca7SSinclair Yeh 
3063e79ecdaSDeepak Rawat 	/**
3073e79ecdaSDeepak Rawat 	 * @gui_x:
3083e79ecdaSDeepak Rawat 	 *
3093e79ecdaSDeepak Rawat 	 * vmwgfx connector property representing the x position of this display
3103e79ecdaSDeepak Rawat 	 * unit (connector is synonymous to display unit) in overall topology.
3113e79ecdaSDeepak Rawat 	 * This is what the device expect as xRoot while creating screen.
3123e79ecdaSDeepak Rawat 	 */
3133e79ecdaSDeepak Rawat 	int gui_x;
3143e79ecdaSDeepak Rawat 
3153e79ecdaSDeepak Rawat 	/**
3163e79ecdaSDeepak Rawat 	 * @gui_y:
3173e79ecdaSDeepak Rawat 	 *
3183e79ecdaSDeepak Rawat 	 * vmwgfx connector property representing the y position of this display
3193e79ecdaSDeepak Rawat 	 * unit (connector is synonymous to display unit) in overall topology.
3203e79ecdaSDeepak Rawat 	 * This is what the device expect as yRoot while creating screen.
3213e79ecdaSDeepak Rawat 	 */
3223e79ecdaSDeepak Rawat 	int gui_y;
323d7721ca7SSinclair Yeh };
324d7721ca7SSinclair Yeh 
325cc5ec459SSinclair Yeh /**
326485d98d4SMartin Krastev  * Derived class for cursor plane object
327485d98d4SMartin Krastev  *
328485d98d4SMartin Krastev  * @base DRM plane object
32953bc3f6fSMichael Banack  * @cursor.cursor_mobs Cursor mobs available for re-use
330485d98d4SMartin Krastev  */
331485d98d4SMartin Krastev struct vmw_cursor_plane {
332485d98d4SMartin Krastev 	struct drm_plane base;
33353bc3f6fSMichael Banack 
334668b2066SZack Rusin 	struct vmw_bo *cursor_mobs[3];
335485d98d4SMartin Krastev };
336485d98d4SMartin Krastev 
337485d98d4SMartin Krastev /**
338fb1d9738SJakob Bornecrantz  * Base class display unit.
339fb1d9738SJakob Bornecrantz  *
340fb1d9738SJakob Bornecrantz  * Since the SVGA hw doesn't have a concept of a crtc, encoder or connector
341fb1d9738SJakob Bornecrantz  * so the display unit is all of them at the same time. This is true for both
342fb1d9738SJakob Bornecrantz  * legacy multimon and screen objects.
343fb1d9738SJakob Bornecrantz  */
344fb1d9738SJakob Bornecrantz struct vmw_display_unit {
345fb1d9738SJakob Bornecrantz 	struct drm_crtc crtc;
346fb1d9738SJakob Bornecrantz 	struct drm_encoder encoder;
347fb1d9738SJakob Bornecrantz 	struct drm_connector connector;
34836cc79bcSSinclair Yeh 	struct drm_plane primary;
349485d98d4SMartin Krastev 	struct vmw_cursor_plane cursor;
350fb1d9738SJakob Bornecrantz 
351fb1d9738SJakob Bornecrantz 	struct vmw_surface *cursor_surface;
352fb1d9738SJakob Bornecrantz 	size_t cursor_age;
353fb1d9738SJakob Bornecrantz 
354fb1d9738SJakob Bornecrantz 	int cursor_x;
355fb1d9738SJakob Bornecrantz 	int cursor_y;
356fb1d9738SJakob Bornecrantz 
357fb1d9738SJakob Bornecrantz 	int hotspot_x;
358fb1d9738SJakob Bornecrantz 	int hotspot_y;
3598fbf9d92SThomas Hellstrom 	s32 core_hotspot_x;
3608fbf9d92SThomas Hellstrom 	s32 core_hotspot_y;
361fb1d9738SJakob Bornecrantz 
362fb1d9738SJakob Bornecrantz 	unsigned unit;
363626ab771SJakob Bornecrantz 
364626ab771SJakob Bornecrantz 	/*
365626ab771SJakob Bornecrantz 	 * Prefered mode tracking.
366626ab771SJakob Bornecrantz 	 */
367626ab771SJakob Bornecrantz 	unsigned pref_width;
368626ab771SJakob Bornecrantz 	unsigned pref_height;
369626ab771SJakob Bornecrantz 	bool pref_active;
370cd2b89e7SThomas Hellstrom 
371cd2b89e7SThomas Hellstrom 	/*
372cd2b89e7SThomas Hellstrom 	 * Gui positioning
373cd2b89e7SThomas Hellstrom 	 */
374cd2b89e7SThomas Hellstrom 	int gui_x;
375cd2b89e7SThomas Hellstrom 	int gui_y;
3766987427aSThomas Hellstrom 	bool is_implicit;
3776dd687b4SThomas Hellstrom 	int set_gui_x;
3786dd687b4SThomas Hellstrom 	int set_gui_y;
379cd2eb57dSZack Rusin 
380cd2eb57dSZack Rusin 	struct {
381*7b006203SZack Rusin 		struct work_struct crc_generator_work;
382cd2eb57dSZack Rusin 		struct hrtimer timer;
383cd2eb57dSZack Rusin 		ktime_t period_ns;
384*7b006203SZack Rusin 
385*7b006203SZack Rusin 		/* protects concurrent access to the vblank handler */
386*7b006203SZack Rusin 		atomic_t atomic_lock;
387*7b006203SZack Rusin 		/* protected by @atomic_lock */
388*7b006203SZack Rusin 		bool crc_enabled;
389*7b006203SZack Rusin 		struct vmw_surface *surface;
390*7b006203SZack Rusin 
391*7b006203SZack Rusin 		/* protects concurrent access to the crc worker */
392*7b006203SZack Rusin 		spinlock_t crc_state_lock;
393*7b006203SZack Rusin 		/* protected by @crc_state_lock */
394*7b006203SZack Rusin 		bool crc_pending;
395*7b006203SZack Rusin 		u64 frame_start;
396*7b006203SZack Rusin 		u64 frame_end;
397cd2eb57dSZack Rusin 	} vkms;
398fb1d9738SJakob Bornecrantz };
399fb1d9738SJakob Bornecrantz 
4002fcd5a73SJakob Bornecrantz #define vmw_crtc_to_du(x) \
4012fcd5a73SJakob Bornecrantz 	container_of(x, struct vmw_display_unit, crtc)
402626ab771SJakob Bornecrantz #define vmw_connector_to_du(x) \
403626ab771SJakob Bornecrantz 	container_of(x, struct vmw_display_unit, connector)
404626ab771SJakob Bornecrantz 
405626ab771SJakob Bornecrantz 
406fb1d9738SJakob Bornecrantz /*
407fb1d9738SJakob Bornecrantz  * Shared display unit functions - vmwgfx_kms.c
408fb1d9738SJakob Bornecrantz  */
409cd2eb57dSZack Rusin void vmw_du_init(struct vmw_display_unit *du);
410c8261a96SSinclair Yeh void vmw_du_cleanup(struct vmw_display_unit *du);
411626ab771SJakob Bornecrantz void vmw_du_crtc_save(struct drm_crtc *crtc);
412626ab771SJakob Bornecrantz void vmw_du_crtc_restore(struct drm_crtc *crtc);
4137ea77283SMaarten Lankhorst int vmw_du_crtc_gamma_set(struct drm_crtc *crtc,
414626ab771SJakob Bornecrantz 			   u16 *r, u16 *g, u16 *b,
4156d124ff8SDaniel Vetter 			   uint32_t size,
4166d124ff8SDaniel Vetter 			   struct drm_modeset_acquire_ctx *ctx);
4179c2542a4SSinclair Yeh int vmw_du_connector_set_property(struct drm_connector *connector,
4189c2542a4SSinclair Yeh 				  struct drm_property *property,
4199c2542a4SSinclair Yeh 				  uint64_t val);
420d7721ca7SSinclair Yeh int vmw_du_connector_atomic_set_property(struct drm_connector *connector,
421d7721ca7SSinclair Yeh 					 struct drm_connector_state *state,
422d7721ca7SSinclair Yeh 					 struct drm_property *property,
423d7721ca7SSinclair Yeh 					 uint64_t val);
424d7721ca7SSinclair Yeh int
425d7721ca7SSinclair Yeh vmw_du_connector_atomic_get_property(struct drm_connector *connector,
426d7721ca7SSinclair Yeh 				     const struct drm_connector_state *state,
427d7721ca7SSinclair Yeh 				     struct drm_property *property,
428d7721ca7SSinclair Yeh 				     uint64_t *val);
4299a69a9acSMaarten Lankhorst int vmw_du_connector_dpms(struct drm_connector *connector, int mode);
430626ab771SJakob Bornecrantz void vmw_du_connector_save(struct drm_connector *connector);
431626ab771SJakob Bornecrantz void vmw_du_connector_restore(struct drm_connector *connector);
432626ab771SJakob Bornecrantz enum drm_connector_status
433626ab771SJakob Bornecrantz vmw_du_connector_detect(struct drm_connector *connector, bool force);
4341a4b172aSThomas Hellstrom int vmw_kms_helper_dirty(struct vmw_private *dev_priv,
4351a4b172aSThomas Hellstrom 			 struct vmw_framebuffer *framebuffer,
4361a4b172aSThomas Hellstrom 			 const struct drm_clip_rect *clips,
4371a4b172aSThomas Hellstrom 			 const struct drm_vmw_rect *vclips,
4381a4b172aSThomas Hellstrom 			 s32 dest_x, s32 dest_y,
4391a4b172aSThomas Hellstrom 			 int num_clips,
4401a4b172aSThomas Hellstrom 			 int increment,
4411a4b172aSThomas Hellstrom 			 struct vmw_kms_dirty *dirty);
442935f7950SMartin Krastev enum drm_mode_status vmw_connector_mode_valid(struct drm_connector *connector,
443935f7950SMartin Krastev 					      struct drm_display_mode *mode);
444935f7950SMartin Krastev int vmw_connector_get_modes(struct drm_connector *connector);
445cd2b89e7SThomas Hellstrom 
4462724b2d5SThomas Hellstrom void vmw_kms_helper_validation_finish(struct vmw_private *dev_priv,
4471a4b172aSThomas Hellstrom 				      struct drm_file *file_priv,
4482724b2d5SThomas Hellstrom 				      struct vmw_validation_context *ctx,
4491a4b172aSThomas Hellstrom 				      struct vmw_fence_obj **out_fence,
4501a4b172aSThomas Hellstrom 				      struct drm_vmw_fence_rep __user *
4511a4b172aSThomas Hellstrom 				      user_fence_rep);
45210b1e0caSThomas Hellstrom int vmw_kms_readback(struct vmw_private *dev_priv,
45310b1e0caSThomas Hellstrom 		     struct drm_file *file_priv,
45410b1e0caSThomas Hellstrom 		     struct vmw_framebuffer *vfb,
45510b1e0caSThomas Hellstrom 		     struct drm_vmw_fence_rep __user *user_fence_rep,
45610b1e0caSThomas Hellstrom 		     struct drm_vmw_rect *vclips,
45710b1e0caSThomas Hellstrom 		     uint32_t num_clips);
458fd006a43SThomas Hellstrom struct vmw_framebuffer *
459fd006a43SThomas Hellstrom vmw_kms_new_framebuffer(struct vmw_private *dev_priv,
46009881d29SZack Rusin 			struct vmw_bo *bo,
461fd006a43SThomas Hellstrom 			struct vmw_surface *surface,
462fd006a43SThomas Hellstrom 			bool only_2d,
463dabdcdc9SDaniel Vetter 			const struct drm_mode_fb_cmd2 *mode_cmd);
464a278724aSThomas Hellstrom void vmw_guess_mode_timing(struct drm_display_mode *mode);
4659d9486e4SThomas Hellstrom void vmw_kms_update_implicit_fb(struct vmw_private *dev_priv);
4669d9486e4SThomas Hellstrom void vmw_kms_create_implicit_placement_property(struct vmw_private *dev_priv);
46775c06855SThomas Hellstrom 
46836cc79bcSSinclair Yeh /* Universal Plane Helpers */
46936cc79bcSSinclair Yeh void vmw_du_primary_plane_destroy(struct drm_plane *plane);
47036cc79bcSSinclair Yeh void vmw_du_cursor_plane_destroy(struct drm_plane *plane);
47136cc79bcSSinclair Yeh 
47206ec4190SSinclair Yeh /* Atomic Helpers */
473060e2ad5SSinclair Yeh int vmw_du_primary_plane_atomic_check(struct drm_plane *plane,
4747c11b99aSMaxime Ripard 				      struct drm_atomic_state *state);
475060e2ad5SSinclair Yeh int vmw_du_cursor_plane_atomic_check(struct drm_plane *plane,
4767c11b99aSMaxime Ripard 				     struct drm_atomic_state *state);
477060e2ad5SSinclair Yeh void vmw_du_cursor_plane_atomic_update(struct drm_plane *plane,
478977697e2SMaxime Ripard 				       struct drm_atomic_state *state);
479060e2ad5SSinclair Yeh int vmw_du_cursor_plane_prepare_fb(struct drm_plane *plane,
480060e2ad5SSinclair Yeh 				   struct drm_plane_state *new_state);
481485d98d4SMartin Krastev void vmw_du_cursor_plane_cleanup_fb(struct drm_plane *plane,
482485d98d4SMartin Krastev 			     struct drm_plane_state *old_state);
483060e2ad5SSinclair Yeh void vmw_du_plane_cleanup_fb(struct drm_plane *plane,
484060e2ad5SSinclair Yeh 			     struct drm_plane_state *old_state);
485cc5ec459SSinclair Yeh void vmw_du_plane_reset(struct drm_plane *plane);
486cc5ec459SSinclair Yeh struct drm_plane_state *vmw_du_plane_duplicate_state(struct drm_plane *plane);
487cc5ec459SSinclair Yeh void vmw_du_plane_destroy_state(struct drm_plane *plane,
488cc5ec459SSinclair Yeh 				struct drm_plane_state *state);
489060e2ad5SSinclair Yeh void vmw_du_plane_unpin_surf(struct vmw_plane_state *vps,
490060e2ad5SSinclair Yeh 			     bool unreference);
491060e2ad5SSinclair Yeh 
49206ec4190SSinclair Yeh int vmw_du_crtc_atomic_check(struct drm_crtc *crtc,
49329b77ad7SMaxime Ripard 			     struct drm_atomic_state *state);
49406ec4190SSinclair Yeh void vmw_du_crtc_atomic_begin(struct drm_crtc *crtc,
495f6ebe9f9SMaxime Ripard 			      struct drm_atomic_state *state);
4969c2542a4SSinclair Yeh void vmw_du_crtc_reset(struct drm_crtc *crtc);
4979c2542a4SSinclair Yeh struct drm_crtc_state *vmw_du_crtc_duplicate_state(struct drm_crtc *crtc);
4989c2542a4SSinclair Yeh void vmw_du_crtc_destroy_state(struct drm_crtc *crtc,
4999c2542a4SSinclair Yeh 				struct drm_crtc_state *state);
500d7721ca7SSinclair Yeh void vmw_du_connector_reset(struct drm_connector *connector);
501d7721ca7SSinclair Yeh struct drm_connector_state *
502d7721ca7SSinclair Yeh vmw_du_connector_duplicate_state(struct drm_connector *connector);
503d7721ca7SSinclair Yeh 
504d7721ca7SSinclair Yeh void vmw_du_connector_destroy_state(struct drm_connector *connector,
505d7721ca7SSinclair Yeh 				    struct drm_connector_state *state);
506fb1d9738SJakob Bornecrantz 
507fb1d9738SJakob Bornecrantz /*
508d8bd19d2SJakob Bornecrantz  * Legacy display unit functions - vmwgfx_ldu.c
509fb1d9738SJakob Bornecrantz  */
510c8261a96SSinclair Yeh int vmw_kms_ldu_init_display(struct vmw_private *dev_priv);
511c8261a96SSinclair Yeh int vmw_kms_ldu_close_display(struct vmw_private *dev_priv);
5126bf6bf03SThomas Hellstrom int vmw_kms_update_proxy(struct vmw_resource *res,
5136bf6bf03SThomas Hellstrom 			 const struct drm_clip_rect *clips,
5146bf6bf03SThomas Hellstrom 			 unsigned num_clips,
5156bf6bf03SThomas Hellstrom 			 int increment);
516fb1d9738SJakob Bornecrantz 
51756d1c78dSJakob Bornecrantz /*
51856d1c78dSJakob Bornecrantz  * Screen Objects display functions - vmwgfx_scrn.c
51956d1c78dSJakob Bornecrantz  */
520c8261a96SSinclair Yeh int vmw_kms_sou_init_display(struct vmw_private *dev_priv);
521c8261a96SSinclair Yeh int vmw_kms_sou_do_surface_dirty(struct vmw_private *dev_priv,
522c8261a96SSinclair Yeh 				 struct vmw_framebuffer *framebuffer,
523c8261a96SSinclair Yeh 				 struct drm_clip_rect *clips,
52410b1e0caSThomas Hellstrom 				 struct drm_vmw_rect *vclips,
52510b1e0caSThomas Hellstrom 				 struct vmw_resource *srf,
52610b1e0caSThomas Hellstrom 				 s32 dest_x,
52710b1e0caSThomas Hellstrom 				 s32 dest_y,
528c8261a96SSinclair Yeh 				 unsigned num_clips, int inc,
52991e9f352SDeepak Rawat 				 struct vmw_fence_obj **out_fence,
53091e9f352SDeepak Rawat 				 struct drm_crtc *crtc);
531f1d34bfdSThomas Hellstrom int vmw_kms_sou_do_bo_dirty(struct vmw_private *dev_priv,
532c8261a96SSinclair Yeh 			    struct vmw_framebuffer *framebuffer,
533c8261a96SSinclair Yeh 			    struct drm_clip_rect *clips,
534897b8180SThomas Hellstrom 			    struct drm_vmw_rect *vclips,
535f1d34bfdSThomas Hellstrom 			    unsigned int num_clips, int increment,
53610b1e0caSThomas Hellstrom 			    bool interruptible,
53791e9f352SDeepak Rawat 			    struct vmw_fence_obj **out_fence,
53891e9f352SDeepak Rawat 			    struct drm_crtc *crtc);
53910b1e0caSThomas Hellstrom int vmw_kms_sou_readback(struct vmw_private *dev_priv,
54010b1e0caSThomas Hellstrom 			 struct drm_file *file_priv,
54110b1e0caSThomas Hellstrom 			 struct vmw_framebuffer *vfb,
54210b1e0caSThomas Hellstrom 			 struct drm_vmw_fence_rep __user *user_fence_rep,
54310b1e0caSThomas Hellstrom 			 struct drm_vmw_rect *vclips,
54491e9f352SDeepak Rawat 			 uint32_t num_clips,
54591e9f352SDeepak Rawat 			 struct drm_crtc *crtc);
54635c05125SSinclair Yeh 
54735c05125SSinclair Yeh /*
54835c05125SSinclair Yeh  * Screen Target Display Unit functions - vmwgfx_stdu.c
54935c05125SSinclair Yeh  */
55035c05125SSinclair Yeh int vmw_kms_stdu_init_display(struct vmw_private *dev_priv);
5516bf6bf03SThomas Hellstrom int vmw_kms_stdu_surface_dirty(struct vmw_private *dev_priv,
55235c05125SSinclair Yeh 			       struct vmw_framebuffer *framebuffer,
55335c05125SSinclair Yeh 			       struct drm_clip_rect *clips,
5546bf6bf03SThomas Hellstrom 			       struct drm_vmw_rect *vclips,
5556bf6bf03SThomas Hellstrom 			       struct vmw_resource *srf,
5566bf6bf03SThomas Hellstrom 			       s32 dest_x,
5576bf6bf03SThomas Hellstrom 			       s32 dest_y,
5586bf6bf03SThomas Hellstrom 			       unsigned num_clips, int inc,
55991e9f352SDeepak Rawat 			       struct vmw_fence_obj **out_fence,
56091e9f352SDeepak Rawat 			       struct drm_crtc *crtc);
56139985eeaSZack Rusin int vmw_kms_stdu_readback(struct vmw_private *dev_priv,
56235c05125SSinclair Yeh 			  struct drm_file *file_priv,
56335c05125SSinclair Yeh 			  struct vmw_framebuffer *vfb,
5646bf6bf03SThomas Hellstrom 			  struct drm_vmw_fence_rep __user *user_fence_rep,
5656bf6bf03SThomas Hellstrom 			  struct drm_clip_rect *clips,
5666bf6bf03SThomas Hellstrom 			  struct drm_vmw_rect *vclips,
5676bf6bf03SThomas Hellstrom 			  uint32_t num_clips,
5686bf6bf03SThomas Hellstrom 			  int increment,
56991e9f352SDeepak Rawat 			  struct drm_crtc *crtc);
570b5ec427eSJakob Bornecrantz 
571e41774c0SDeepak Rawat int vmw_du_helper_plane_update(struct vmw_du_update_plane *update);
572e41774c0SDeepak Rawat 
573e41774c0SDeepak Rawat /**
574e41774c0SDeepak Rawat  * vmw_du_translate_to_crtc - Translate a rect from framebuffer to crtc
575e41774c0SDeepak Rawat  * @state: Plane state.
576e41774c0SDeepak Rawat  * @r: Rectangle to translate.
577e41774c0SDeepak Rawat  */
578e41774c0SDeepak Rawat static inline void vmw_du_translate_to_crtc(struct drm_plane_state *state,
579e41774c0SDeepak Rawat 					    struct drm_rect *r)
580e41774c0SDeepak Rawat {
581e41774c0SDeepak Rawat 	int translate_crtc_x = -((state->src_x >> 16) - state->crtc_x);
582e41774c0SDeepak Rawat 	int translate_crtc_y = -((state->src_y >> 16) - state->crtc_y);
583e41774c0SDeepak Rawat 
584e41774c0SDeepak Rawat 	drm_rect_translate(r, translate_crtc_x, translate_crtc_y);
585e41774c0SDeepak Rawat }
586e41774c0SDeepak Rawat 
587fb1d9738SJakob Bornecrantz #endif
588