Linux Audio

Check our new training course

Loading...
v5.4
  1/* SPDX-License-Identifier: GPL-2.0 OR MIT */
  2/**************************************************************************
  3 *
  4 * Copyright 2009-2015 VMware, Inc., Palo Alto, CA., USA
 
  5 *
  6 * Permission is hereby granted, free of charge, to any person obtaining a
  7 * copy of this software and associated documentation files (the
  8 * "Software"), to deal in the Software without restriction, including
  9 * without limitation the rights to use, copy, modify, merge, publish,
 10 * distribute, sub license, and/or sell copies of the Software, and to
 11 * permit persons to whom the Software is furnished to do so, subject to
 12 * the following conditions:
 13 *
 14 * The above copyright notice and this permission notice (including the
 15 * next paragraph) shall be included in all copies or substantial portions
 16 * of the Software.
 17 *
 18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 20 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
 21 * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
 22 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
 23 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
 24 * USE OR OTHER DEALINGS IN THE SOFTWARE.
 25 *
 26 **************************************************************************/
 27
 28#ifndef VMWGFX_KMS_H_
 29#define VMWGFX_KMS_H_
 30
 31#include <drm/drm_encoder.h>
 
 32#include <drm/drm_probe_helper.h>
 33
 34#include "vmwgfx_drv.h"
 35
 36/**
 37 * struct vmw_du_update_plane - Closure structure for vmw_du_helper_plane_update
 38 * @plane: Plane which is being updated.
 39 * @old_state: Old state of plane.
 40 * @dev_priv: Device private.
 41 * @du: Display unit on which to update the plane.
 42 * @vfb: Framebuffer which is blitted to display unit.
 43 * @out_fence: Out fence for resource finish.
 44 * @mutex: The mutex used to protect resource reservation.
 45 * @cpu_blit: True if need cpu blit.
 46 * @intr: Whether to perform waits interruptible if possible.
 47 *
 48 * This structure loosely represent the set of operations needed to perform a
 49 * plane update on a display unit. Implementer will define that functionality
 50 * according to the function callbacks for this structure. In brief it involves
 51 * surface/buffer object validation, populate FIFO commands and command
 52 * submission to the device.
 53 */
 54struct vmw_du_update_plane {
 55	/**
 56	 * @calc_fifo_size: Calculate fifo size.
 57	 *
 58	 * Determine fifo size for the commands needed for update. The number of
 59	 * damage clips on display unit @num_hits will be passed to allocate
 60	 * sufficient fifo space.
 61	 *
 62	 * Return: Fifo size needed
 63	 */
 64	uint32_t (*calc_fifo_size)(struct vmw_du_update_plane *update,
 65				   uint32_t num_hits);
 66
 67	/**
 68	 * @post_prepare: Populate fifo for resource preparation.
 69	 *
 70	 * Some surface resource or buffer object need some extra cmd submission
 71	 * like update GB image for proxy surface and define a GMRFB for screen
 72	 * object. That should should be done here as this callback will be
 73	 * called after FIFO allocation with the address of command buufer.
 74	 *
 75	 * This callback is optional.
 76	 *
 77	 * Return: Size of commands populated to command buffer.
 78	 */
 79	uint32_t (*post_prepare)(struct vmw_du_update_plane *update, void *cmd);
 80
 81	/**
 82	 * @pre_clip: Populate fifo before clip.
 83	 *
 84	 * This is where pre clip related command should be populated like
 85	 * surface copy/DMA, etc.
 86	 *
 87	 * This callback is optional.
 88	 *
 89	 * Return: Size of commands populated to command buffer.
 90	 */
 91	uint32_t (*pre_clip)(struct vmw_du_update_plane *update, void *cmd,
 92			     uint32_t num_hits);
 93
 94	/**
 95	 * @clip: Populate fifo for clip.
 96	 *
 97	 * This is where to populate clips for surface copy/dma or blit commands
 98	 * if needed. This will be called times have damage in display unit,
 99	 * which is one if doing full update. @clip is the damage in destination
100	 * coordinates which is crtc/DU and @src_x, @src_y is damage clip src in
101	 * framebuffer coordinate.
102	 *
103	 * This callback is optional.
104	 *
105	 * Return: Size of commands populated to command buffer.
106	 */
107	uint32_t (*clip)(struct vmw_du_update_plane *update, void *cmd,
108			 struct drm_rect *clip, uint32_t src_x, uint32_t src_y);
109
110	/**
111	 * @post_clip: Populate fifo after clip.
112	 *
113	 * This is where to populate display unit update commands or blit
114	 * commands.
115	 *
116	 * Return: Size of commands populated to command buffer.
117	 */
118	uint32_t (*post_clip)(struct vmw_du_update_plane *update, void *cmd,
119				    struct drm_rect *bb);
120
121	struct drm_plane *plane;
122	struct drm_plane_state *old_state;
123	struct vmw_private *dev_priv;
124	struct vmw_display_unit *du;
125	struct vmw_framebuffer *vfb;
126	struct vmw_fence_obj **out_fence;
127	struct mutex *mutex;
128	bool cpu_blit;
129	bool intr;
130};
131
132/**
133 * struct vmw_du_update_plane_surface - closure structure for surface
134 * @base: base closure structure.
135 * @cmd_start: FIFO command start address (used by SOU only).
136 */
137struct vmw_du_update_plane_surface {
138	struct vmw_du_update_plane base;
139	/* This member is to handle special case SOU surface update */
140	void *cmd_start;
141};
142
143/**
144 * struct vmw_du_update_plane_buffer - Closure structure for buffer object
145 * @base: Base closure structure.
146 * @fb_left: x1 for fb damage bounding box.
147 * @fb_top: y1 for fb damage bounding box.
148 */
149struct vmw_du_update_plane_buffer {
150	struct vmw_du_update_plane base;
151	int fb_left, fb_top;
152};
153
154/**
155 * struct vmw_kms_dirty - closure structure for the vmw_kms_helper_dirty
156 * function.
157 *
158 * @fifo_commit: Callback that is called once for each display unit after
159 * all clip rects. This function must commit the fifo space reserved by the
160 * helper. Set up by the caller.
161 * @clip: Callback that is called for each cliprect on each display unit.
162 * Set up by the caller.
163 * @fifo_reserve_size: Fifo size that the helper should try to allocat for
164 * each display unit. Set up by the caller.
165 * @dev_priv: Pointer to the device private. Set up by the helper.
166 * @unit: The current display unit. Set up by the helper before a call to @clip.
167 * @cmd: The allocated fifo space. Set up by the helper before the first @clip
168 * call.
169 * @crtc: The crtc for which to build dirty commands.
170 * @num_hits: Number of clip rect commands for this display unit.
171 * Cleared by the helper before the first @clip call. Updated by the @clip
172 * callback.
173 * @fb_x: Clip rect left side in framebuffer coordinates.
174 * @fb_y: Clip rect right side in framebuffer coordinates.
175 * @unit_x1: Clip rect left side in crtc coordinates.
176 * @unit_y1: Clip rect top side in crtc coordinates.
177 * @unit_x2: Clip rect right side in crtc coordinates.
178 * @unit_y2: Clip rect bottom side in crtc coordinates.
179 *
180 * The clip rect coordinates are updated by the helper for each @clip call.
181 * Note that this may be derived from if more info needs to be passed between
182 * helper caller and helper callbacks.
183 */
184struct vmw_kms_dirty {
185	void (*fifo_commit)(struct vmw_kms_dirty *);
186	void (*clip)(struct vmw_kms_dirty *);
187	size_t fifo_reserve_size;
188	struct vmw_private *dev_priv;
189	struct vmw_display_unit *unit;
190	void *cmd;
191	struct drm_crtc *crtc;
192	u32 num_hits;
193	s32 fb_x;
194	s32 fb_y;
195	s32 unit_x1;
196	s32 unit_y1;
197	s32 unit_x2;
198	s32 unit_y2;
199};
200
201#define VMWGFX_NUM_DISPLAY_UNITS 8
202
203
204#define vmw_framebuffer_to_vfb(x) \
205	container_of(x, struct vmw_framebuffer, base)
206#define vmw_framebuffer_to_vfbs(x) \
207	container_of(x, struct vmw_framebuffer_surface, base.base)
208#define vmw_framebuffer_to_vfbd(x) \
209	container_of(x, struct vmw_framebuffer_bo, base.base)
210
211/**
212 * Base class for framebuffers
213 *
214 * @pin is called the when ever a crtc uses this framebuffer
215 * @unpin is called
216 */
217struct vmw_framebuffer {
218	struct drm_framebuffer base;
219	int (*pin)(struct vmw_framebuffer *fb);
220	int (*unpin)(struct vmw_framebuffer *fb);
221	bool bo;
222	struct ttm_base_object *user_obj;
223	uint32_t user_handle;
224};
225
226/*
227 * Clip rectangle
228 */
229struct vmw_clip_rect {
230	int x1, x2, y1, y2;
231};
232
233struct vmw_framebuffer_surface {
234	struct vmw_framebuffer base;
235	struct vmw_surface *surface;
236	struct vmw_buffer_object *buffer;
237	struct list_head head;
238	bool is_bo_proxy;  /* true if this is proxy surface for DMA buf */
239};
240
241
242struct vmw_framebuffer_bo {
243	struct vmw_framebuffer base;
244	struct vmw_buffer_object *buffer;
245};
246
247
248static const uint32_t vmw_primary_plane_formats[] = {
249	DRM_FORMAT_XRGB1555,
250	DRM_FORMAT_RGB565,
251	DRM_FORMAT_RGB888,
252	DRM_FORMAT_XRGB8888,
253	DRM_FORMAT_ARGB8888,
 
 
254};
255
256static const uint32_t vmw_cursor_plane_formats[] = {
257	DRM_FORMAT_ARGB8888,
258};
259
260
261#define vmw_crtc_state_to_vcs(x) container_of(x, struct vmw_crtc_state, base)
262#define vmw_plane_state_to_vps(x) container_of(x, struct vmw_plane_state, base)
263#define vmw_connector_state_to_vcs(x) \
264		container_of(x, struct vmw_connector_state, base)
 
265
266/**
267 * Derived class for crtc state object
268 *
269 * @base DRM crtc object
270 */
271struct vmw_crtc_state {
272	struct drm_crtc_state base;
273};
274
 
 
 
 
 
 
275/**
276 * Derived class for plane state object
277 *
278 * @base DRM plane object
279 * @surf Display surface for STDU
280 * @bo display bo for SOU
281 * @content_fb_type Used by STDU.
282 * @bo_size Size of the bo, used by Screen Object Display Unit
283 * @pinned pin count for STDU display surface
284 */
285struct vmw_plane_state {
286	struct drm_plane_state base;
287	struct vmw_surface *surf;
288	struct vmw_buffer_object *bo;
289
290	int content_fb_type;
291	unsigned long bo_size;
292
293	int pinned;
294
295	/* For CPU Blit */
296	unsigned int cpp;
 
 
 
297};
298
299
300/**
301 * Derived class for connector state object
302 *
303 * @base DRM connector object
304 * @is_implicit connector property
305 *
306 */
307struct vmw_connector_state {
308	struct drm_connector_state base;
309
310	/**
311	 * @gui_x:
312	 *
313	 * vmwgfx connector property representing the x position of this display
314	 * unit (connector is synonymous to display unit) in overall topology.
315	 * This is what the device expect as xRoot while creating screen.
316	 */
317	int gui_x;
318
319	/**
320	 * @gui_y:
321	 *
322	 * vmwgfx connector property representing the y position of this display
323	 * unit (connector is synonymous to display unit) in overall topology.
324	 * This is what the device expect as yRoot while creating screen.
325	 */
326	int gui_y;
327};
328
329/**
 
 
 
 
 
 
 
 
 
 
 
 
330 * Base class display unit.
331 *
332 * Since the SVGA hw doesn't have a concept of a crtc, encoder or connector
333 * so the display unit is all of them at the same time. This is true for both
334 * legacy multimon and screen objects.
335 */
336struct vmw_display_unit {
337	struct drm_crtc crtc;
338	struct drm_encoder encoder;
339	struct drm_connector connector;
340	struct drm_plane primary;
341	struct drm_plane cursor;
342
343	struct vmw_surface *cursor_surface;
344	struct vmw_buffer_object *cursor_bo;
345	size_t cursor_age;
346
347	int cursor_x;
348	int cursor_y;
349
350	int hotspot_x;
351	int hotspot_y;
352	s32 core_hotspot_x;
353	s32 core_hotspot_y;
354
355	unsigned unit;
356
357	/*
358	 * Prefered mode tracking.
359	 */
360	unsigned pref_width;
361	unsigned pref_height;
362	bool pref_active;
363	struct drm_display_mode *pref_mode;
364
365	/*
366	 * Gui positioning
367	 */
368	int gui_x;
369	int gui_y;
370	bool is_implicit;
371	int set_gui_x;
372	int set_gui_y;
373};
374
375struct vmw_validation_ctx {
376	struct vmw_resource *res;
377	struct vmw_buffer_object *buf;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
378};
379
380#define vmw_crtc_to_du(x) \
381	container_of(x, struct vmw_display_unit, crtc)
382#define vmw_connector_to_du(x) \
383	container_of(x, struct vmw_display_unit, connector)
384
385
386/*
387 * Shared display unit functions - vmwgfx_kms.c
388 */
 
389void vmw_du_cleanup(struct vmw_display_unit *du);
390void vmw_du_crtc_save(struct drm_crtc *crtc);
391void vmw_du_crtc_restore(struct drm_crtc *crtc);
392int vmw_du_crtc_gamma_set(struct drm_crtc *crtc,
393			   u16 *r, u16 *g, u16 *b,
394			   uint32_t size,
395			   struct drm_modeset_acquire_ctx *ctx);
396int vmw_du_connector_set_property(struct drm_connector *connector,
397				  struct drm_property *property,
398				  uint64_t val);
399int vmw_du_connector_atomic_set_property(struct drm_connector *connector,
400					 struct drm_connector_state *state,
401					 struct drm_property *property,
402					 uint64_t val);
403int
404vmw_du_connector_atomic_get_property(struct drm_connector *connector,
405				     const struct drm_connector_state *state,
406				     struct drm_property *property,
407				     uint64_t *val);
408int vmw_du_connector_dpms(struct drm_connector *connector, int mode);
409void vmw_du_connector_save(struct drm_connector *connector);
410void vmw_du_connector_restore(struct drm_connector *connector);
411enum drm_connector_status
412vmw_du_connector_detect(struct drm_connector *connector, bool force);
413int vmw_du_connector_fill_modes(struct drm_connector *connector,
414				uint32_t max_width, uint32_t max_height);
415int vmw_kms_helper_dirty(struct vmw_private *dev_priv,
416			 struct vmw_framebuffer *framebuffer,
417			 const struct drm_clip_rect *clips,
418			 const struct drm_vmw_rect *vclips,
419			 s32 dest_x, s32 dest_y,
420			 int num_clips,
421			 int increment,
422			 struct vmw_kms_dirty *dirty);
 
 
 
423
424void vmw_kms_helper_validation_finish(struct vmw_private *dev_priv,
425				      struct drm_file *file_priv,
426				      struct vmw_validation_context *ctx,
427				      struct vmw_fence_obj **out_fence,
428				      struct drm_vmw_fence_rep __user *
429				      user_fence_rep);
430int vmw_kms_readback(struct vmw_private *dev_priv,
431		     struct drm_file *file_priv,
432		     struct vmw_framebuffer *vfb,
433		     struct drm_vmw_fence_rep __user *user_fence_rep,
434		     struct drm_vmw_rect *vclips,
435		     uint32_t num_clips);
436struct vmw_framebuffer *
437vmw_kms_new_framebuffer(struct vmw_private *dev_priv,
438			struct vmw_buffer_object *bo,
439			struct vmw_surface *surface,
440			bool only_2d,
441			const struct drm_mode_fb_cmd2 *mode_cmd);
442int vmw_kms_fbdev_init_data(struct vmw_private *dev_priv,
443			    unsigned unit,
444			    u32 max_width,
445			    u32 max_height,
446			    struct drm_connector **p_con,
447			    struct drm_crtc **p_crtc,
448			    struct drm_display_mode **p_mode);
449void vmw_guess_mode_timing(struct drm_display_mode *mode);
450void vmw_kms_update_implicit_fb(struct vmw_private *dev_priv);
451void vmw_kms_create_implicit_placement_property(struct vmw_private *dev_priv);
452
453/* Universal Plane Helpers */
454void vmw_du_primary_plane_destroy(struct drm_plane *plane);
455void vmw_du_cursor_plane_destroy(struct drm_plane *plane);
456
457/* Atomic Helpers */
458int vmw_du_primary_plane_atomic_check(struct drm_plane *plane,
459				      struct drm_plane_state *state);
460int vmw_du_cursor_plane_atomic_check(struct drm_plane *plane,
461				     struct drm_plane_state *state);
462void vmw_du_cursor_plane_atomic_update(struct drm_plane *plane,
463				       struct drm_plane_state *old_state);
464int vmw_du_cursor_plane_prepare_fb(struct drm_plane *plane,
465				   struct drm_plane_state *new_state);
 
 
466void vmw_du_plane_cleanup_fb(struct drm_plane *plane,
467			     struct drm_plane_state *old_state);
468void vmw_du_plane_reset(struct drm_plane *plane);
469struct drm_plane_state *vmw_du_plane_duplicate_state(struct drm_plane *plane);
470void vmw_du_plane_destroy_state(struct drm_plane *plane,
471				struct drm_plane_state *state);
472void vmw_du_plane_unpin_surf(struct vmw_plane_state *vps,
473			     bool unreference);
474
475int vmw_du_crtc_atomic_check(struct drm_crtc *crtc,
476			     struct drm_crtc_state *state);
477void vmw_du_crtc_atomic_begin(struct drm_crtc *crtc,
478			      struct drm_crtc_state *old_crtc_state);
479void vmw_du_crtc_atomic_flush(struct drm_crtc *crtc,
480			      struct drm_crtc_state *old_crtc_state);
481void vmw_du_crtc_reset(struct drm_crtc *crtc);
482struct drm_crtc_state *vmw_du_crtc_duplicate_state(struct drm_crtc *crtc);
483void vmw_du_crtc_destroy_state(struct drm_crtc *crtc,
484				struct drm_crtc_state *state);
485void vmw_du_connector_reset(struct drm_connector *connector);
486struct drm_connector_state *
487vmw_du_connector_duplicate_state(struct drm_connector *connector);
488
489void vmw_du_connector_destroy_state(struct drm_connector *connector,
490				    struct drm_connector_state *state);
491
492/*
493 * Legacy display unit functions - vmwgfx_ldu.c
494 */
495int vmw_kms_ldu_init_display(struct vmw_private *dev_priv);
496int vmw_kms_ldu_close_display(struct vmw_private *dev_priv);
497int vmw_kms_ldu_do_bo_dirty(struct vmw_private *dev_priv,
498			    struct vmw_framebuffer *framebuffer,
499			    unsigned int flags, unsigned int color,
500			    struct drm_clip_rect *clips,
501			    unsigned int num_clips, int increment);
502int vmw_kms_update_proxy(struct vmw_resource *res,
503			 const struct drm_clip_rect *clips,
504			 unsigned num_clips,
505			 int increment);
506
507/*
508 * Screen Objects display functions - vmwgfx_scrn.c
509 */
510int vmw_kms_sou_init_display(struct vmw_private *dev_priv);
511int vmw_kms_sou_do_surface_dirty(struct vmw_private *dev_priv,
512				 struct vmw_framebuffer *framebuffer,
513				 struct drm_clip_rect *clips,
514				 struct drm_vmw_rect *vclips,
515				 struct vmw_resource *srf,
516				 s32 dest_x,
517				 s32 dest_y,
518				 unsigned num_clips, int inc,
519				 struct vmw_fence_obj **out_fence,
520				 struct drm_crtc *crtc);
521int vmw_kms_sou_do_bo_dirty(struct vmw_private *dev_priv,
522			    struct vmw_framebuffer *framebuffer,
523			    struct drm_clip_rect *clips,
524			    struct drm_vmw_rect *vclips,
525			    unsigned int num_clips, int increment,
526			    bool interruptible,
527			    struct vmw_fence_obj **out_fence,
528			    struct drm_crtc *crtc);
529int vmw_kms_sou_readback(struct vmw_private *dev_priv,
530			 struct drm_file *file_priv,
531			 struct vmw_framebuffer *vfb,
532			 struct drm_vmw_fence_rep __user *user_fence_rep,
533			 struct drm_vmw_rect *vclips,
534			 uint32_t num_clips,
535			 struct drm_crtc *crtc);
536
537/*
538 * Screen Target Display Unit functions - vmwgfx_stdu.c
539 */
540int vmw_kms_stdu_init_display(struct vmw_private *dev_priv);
541int vmw_kms_stdu_surface_dirty(struct vmw_private *dev_priv,
542			       struct vmw_framebuffer *framebuffer,
543			       struct drm_clip_rect *clips,
544			       struct drm_vmw_rect *vclips,
545			       struct vmw_resource *srf,
546			       s32 dest_x,
547			       s32 dest_y,
548			       unsigned num_clips, int inc,
549			       struct vmw_fence_obj **out_fence,
550			       struct drm_crtc *crtc);
551int vmw_kms_stdu_dma(struct vmw_private *dev_priv,
552		     struct drm_file *file_priv,
553		     struct vmw_framebuffer *vfb,
554		     struct drm_vmw_fence_rep __user *user_fence_rep,
555		     struct drm_clip_rect *clips,
556		     struct drm_vmw_rect *vclips,
557		     uint32_t num_clips,
558		     int increment,
559		     bool to_surface,
560		     bool interruptible,
561		     struct drm_crtc *crtc);
562
563int vmw_du_helper_plane_update(struct vmw_du_update_plane *update);
564
565/**
566 * vmw_du_translate_to_crtc - Translate a rect from framebuffer to crtc
567 * @state: Plane state.
568 * @r: Rectangle to translate.
569 */
570static inline void vmw_du_translate_to_crtc(struct drm_plane_state *state,
571					    struct drm_rect *r)
572{
573	int translate_crtc_x = -((state->src_x >> 16) - state->crtc_x);
574	int translate_crtc_y = -((state->src_y >> 16) - state->crtc_y);
575
576	drm_rect_translate(r, translate_crtc_x, translate_crtc_y);
577}
578
579#endif
v6.13.7
  1/* SPDX-License-Identifier: GPL-2.0 OR MIT */
  2/**************************************************************************
  3 *
  4 * Copyright (c) 2009-2024 Broadcom. All Rights Reserved. The term
  5 * “Broadcom” refers to Broadcom Inc. and/or its subsidiaries.
  6 *
  7 * Permission is hereby granted, free of charge, to any person obtaining a
  8 * copy of this software and associated documentation files (the
  9 * "Software"), to deal in the Software without restriction, including
 10 * without limitation the rights to use, copy, modify, merge, publish,
 11 * distribute, sub license, and/or sell copies of the Software, and to
 12 * permit persons to whom the Software is furnished to do so, subject to
 13 * the following conditions:
 14 *
 15 * The above copyright notice and this permission notice (including the
 16 * next paragraph) shall be included in all copies or substantial portions
 17 * of the Software.
 18 *
 19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 20 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 21 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
 22 * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
 23 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
 24 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
 25 * USE OR OTHER DEALINGS IN THE SOFTWARE.
 26 *
 27 **************************************************************************/
 28
 29#ifndef VMWGFX_KMS_H_
 30#define VMWGFX_KMS_H_
 31
 32#include <drm/drm_encoder.h>
 33#include <drm/drm_framebuffer.h>
 34#include <drm/drm_probe_helper.h>
 35
 36#include "vmwgfx_drv.h"
 37
 38/**
 39 * struct vmw_du_update_plane - Closure structure for vmw_du_helper_plane_update
 40 * @plane: Plane which is being updated.
 41 * @old_state: Old state of plane.
 42 * @dev_priv: Device private.
 43 * @du: Display unit on which to update the plane.
 44 * @vfb: Framebuffer which is blitted to display unit.
 45 * @out_fence: Out fence for resource finish.
 46 * @mutex: The mutex used to protect resource reservation.
 47 * @cpu_blit: True if need cpu blit.
 48 * @intr: Whether to perform waits interruptible if possible.
 49 *
 50 * This structure loosely represent the set of operations needed to perform a
 51 * plane update on a display unit. Implementer will define that functionality
 52 * according to the function callbacks for this structure. In brief it involves
 53 * surface/buffer object validation, populate FIFO commands and command
 54 * submission to the device.
 55 */
 56struct vmw_du_update_plane {
 57	/**
 58	 * @calc_fifo_size: Calculate fifo size.
 59	 *
 60	 * Determine fifo size for the commands needed for update. The number of
 61	 * damage clips on display unit @num_hits will be passed to allocate
 62	 * sufficient fifo space.
 63	 *
 64	 * Return: Fifo size needed
 65	 */
 66	uint32_t (*calc_fifo_size)(struct vmw_du_update_plane *update,
 67				   uint32_t num_hits);
 68
 69	/**
 70	 * @post_prepare: Populate fifo for resource preparation.
 71	 *
 72	 * Some surface resource or buffer object need some extra cmd submission
 73	 * like update GB image for proxy surface and define a GMRFB for screen
 74	 * object. That should be done here as this callback will be
 75	 * called after FIFO allocation with the address of command buufer.
 76	 *
 77	 * This callback is optional.
 78	 *
 79	 * Return: Size of commands populated to command buffer.
 80	 */
 81	uint32_t (*post_prepare)(struct vmw_du_update_plane *update, void *cmd);
 82
 83	/**
 84	 * @pre_clip: Populate fifo before clip.
 85	 *
 86	 * This is where pre clip related command should be populated like
 87	 * surface copy/DMA, etc.
 88	 *
 89	 * This callback is optional.
 90	 *
 91	 * Return: Size of commands populated to command buffer.
 92	 */
 93	uint32_t (*pre_clip)(struct vmw_du_update_plane *update, void *cmd,
 94			     uint32_t num_hits);
 95
 96	/**
 97	 * @clip: Populate fifo for clip.
 98	 *
 99	 * This is where to populate clips for surface copy/dma or blit commands
100	 * if needed. This will be called times have damage in display unit,
101	 * which is one if doing full update. @clip is the damage in destination
102	 * coordinates which is crtc/DU and @src_x, @src_y is damage clip src in
103	 * framebuffer coordinate.
104	 *
105	 * This callback is optional.
106	 *
107	 * Return: Size of commands populated to command buffer.
108	 */
109	uint32_t (*clip)(struct vmw_du_update_plane *update, void *cmd,
110			 struct drm_rect *clip, uint32_t src_x, uint32_t src_y);
111
112	/**
113	 * @post_clip: Populate fifo after clip.
114	 *
115	 * This is where to populate display unit update commands or blit
116	 * commands.
117	 *
118	 * Return: Size of commands populated to command buffer.
119	 */
120	uint32_t (*post_clip)(struct vmw_du_update_plane *update, void *cmd,
121				    struct drm_rect *bb);
122
123	struct drm_plane *plane;
124	struct drm_plane_state *old_state;
125	struct vmw_private *dev_priv;
126	struct vmw_display_unit *du;
127	struct vmw_framebuffer *vfb;
128	struct vmw_fence_obj **out_fence;
129	struct mutex *mutex;
 
130	bool intr;
131};
132
133/**
134 * struct vmw_du_update_plane_surface - closure structure for surface
135 * @base: base closure structure.
136 * @cmd_start: FIFO command start address (used by SOU only).
137 */
138struct vmw_du_update_plane_surface {
139	struct vmw_du_update_plane base;
140	/* This member is to handle special case SOU surface update */
141	void *cmd_start;
142};
143
144/**
145 * struct vmw_du_update_plane_buffer - Closure structure for buffer object
146 * @base: Base closure structure.
147 * @fb_left: x1 for fb damage bounding box.
148 * @fb_top: y1 for fb damage bounding box.
149 */
150struct vmw_du_update_plane_buffer {
151	struct vmw_du_update_plane base;
152	int fb_left, fb_top;
153};
154
155/**
156 * struct vmw_kms_dirty - closure structure for the vmw_kms_helper_dirty
157 * function.
158 *
159 * @fifo_commit: Callback that is called once for each display unit after
160 * all clip rects. This function must commit the fifo space reserved by the
161 * helper. Set up by the caller.
162 * @clip: Callback that is called for each cliprect on each display unit.
163 * Set up by the caller.
164 * @fifo_reserve_size: Fifo size that the helper should try to allocat for
165 * each display unit. Set up by the caller.
166 * @dev_priv: Pointer to the device private. Set up by the helper.
167 * @unit: The current display unit. Set up by the helper before a call to @clip.
168 * @cmd: The allocated fifo space. Set up by the helper before the first @clip
169 * call.
170 * @crtc: The crtc for which to build dirty commands.
171 * @num_hits: Number of clip rect commands for this display unit.
172 * Cleared by the helper before the first @clip call. Updated by the @clip
173 * callback.
174 * @fb_x: Clip rect left side in framebuffer coordinates.
175 * @fb_y: Clip rect right side in framebuffer coordinates.
176 * @unit_x1: Clip rect left side in crtc coordinates.
177 * @unit_y1: Clip rect top side in crtc coordinates.
178 * @unit_x2: Clip rect right side in crtc coordinates.
179 * @unit_y2: Clip rect bottom side in crtc coordinates.
180 *
181 * The clip rect coordinates are updated by the helper for each @clip call.
182 * Note that this may be derived from if more info needs to be passed between
183 * helper caller and helper callbacks.
184 */
185struct vmw_kms_dirty {
186	void (*fifo_commit)(struct vmw_kms_dirty *);
187	void (*clip)(struct vmw_kms_dirty *);
188	size_t fifo_reserve_size;
189	struct vmw_private *dev_priv;
190	struct vmw_display_unit *unit;
191	void *cmd;
192	struct drm_crtc *crtc;
193	u32 num_hits;
194	s32 fb_x;
195	s32 fb_y;
196	s32 unit_x1;
197	s32 unit_y1;
198	s32 unit_x2;
199	s32 unit_y2;
200};
201
 
 
 
202#define vmw_framebuffer_to_vfb(x) \
203	container_of(x, struct vmw_framebuffer, base)
204#define vmw_framebuffer_to_vfbs(x) \
205	container_of(x, struct vmw_framebuffer_surface, base.base)
206#define vmw_framebuffer_to_vfbd(x) \
207	container_of(x, struct vmw_framebuffer_bo, base.base)
208
209/**
210 * Base class for framebuffers
211 *
212 * @pin is called the when ever a crtc uses this framebuffer
213 * @unpin is called
214 */
215struct vmw_framebuffer {
216	struct drm_framebuffer base;
 
 
217	bool bo;
 
 
 
 
 
 
 
 
 
218};
219
220struct vmw_framebuffer_surface {
221	struct vmw_framebuffer base;
222	struct vmw_user_object uo;
 
 
 
223};
224
 
225struct vmw_framebuffer_bo {
226	struct vmw_framebuffer base;
227	struct vmw_bo *buffer;
228};
229
230
231static const uint32_t __maybe_unused vmw_primary_plane_formats[] = {
 
 
 
232	DRM_FORMAT_XRGB8888,
233	DRM_FORMAT_ARGB8888,
234	DRM_FORMAT_RGB565,
235	DRM_FORMAT_XRGB1555,
236};
237
238static const uint32_t __maybe_unused vmw_cursor_plane_formats[] = {
239	DRM_FORMAT_ARGB8888,
240};
241
242
243#define vmw_crtc_state_to_vcs(x) container_of(x, struct vmw_crtc_state, base)
244#define vmw_plane_state_to_vps(x) container_of(x, struct vmw_plane_state, base)
245#define vmw_connector_state_to_vcs(x) \
246		container_of(x, struct vmw_connector_state, base)
247#define vmw_plane_to_vcp(x) container_of(x, struct vmw_cursor_plane, base)
248
249/**
250 * Derived class for crtc state object
251 *
252 * @base DRM crtc object
253 */
254struct vmw_crtc_state {
255	struct drm_crtc_state base;
256};
257
258struct vmw_cursor_plane_state {
259	struct vmw_bo *bo;
260	s32 hotspot_x;
261	s32 hotspot_y;
262};
263
264/**
265 * Derived class for plane state object
266 *
267 * @base DRM plane object
268 * @surf Display surface for STDU
269 * @bo display bo for SOU
270 * @content_fb_type Used by STDU.
271 * @bo_size Size of the bo, used by Screen Object Display Unit
272 * @pinned pin count for STDU display surface
273 */
274struct vmw_plane_state {
275	struct drm_plane_state base;
276	struct vmw_user_object uo;
 
277
278	int content_fb_type;
279	unsigned long bo_size;
280
281	int pinned;
282
283	/* For CPU Blit */
284	unsigned int cpp;
285
286	bool surf_mapped;
287	struct vmw_cursor_plane_state cursor;
288};
289
290
291/**
292 * Derived class for connector state object
293 *
294 * @base DRM connector object
295 * @is_implicit connector property
296 *
297 */
298struct vmw_connector_state {
299	struct drm_connector_state base;
300
301	/**
302	 * @gui_x:
303	 *
304	 * vmwgfx connector property representing the x position of this display
305	 * unit (connector is synonymous to display unit) in overall topology.
306	 * This is what the device expect as xRoot while creating screen.
307	 */
308	int gui_x;
309
310	/**
311	 * @gui_y:
312	 *
313	 * vmwgfx connector property representing the y position of this display
314	 * unit (connector is synonymous to display unit) in overall topology.
315	 * This is what the device expect as yRoot while creating screen.
316	 */
317	int gui_y;
318};
319
320/**
321 * Derived class for cursor plane object
322 *
323 * @base DRM plane object
324 * @cursor.cursor_mobs Cursor mobs available for re-use
325 */
326struct vmw_cursor_plane {
327	struct drm_plane base;
328
329	struct vmw_bo *cursor_mobs[3];
330};
331
332/**
333 * Base class display unit.
334 *
335 * Since the SVGA hw doesn't have a concept of a crtc, encoder or connector
336 * so the display unit is all of them at the same time. This is true for both
337 * legacy multimon and screen objects.
338 */
339struct vmw_display_unit {
340	struct drm_crtc crtc;
341	struct drm_encoder encoder;
342	struct drm_connector connector;
343	struct drm_plane primary;
344	struct vmw_cursor_plane cursor;
345
346	struct vmw_surface *cursor_surface;
 
347	size_t cursor_age;
348
349	int cursor_x;
350	int cursor_y;
351
352	int hotspot_x;
353	int hotspot_y;
354	s32 core_hotspot_x;
355	s32 core_hotspot_y;
356
357	unsigned unit;
358
359	/*
360	 * Prefered mode tracking.
361	 */
362	unsigned pref_width;
363	unsigned pref_height;
364	bool pref_active;
 
365
366	/*
367	 * Gui positioning
368	 */
369	int gui_x;
370	int gui_y;
371	bool is_implicit;
372	int set_gui_x;
373	int set_gui_y;
 
374
375	struct {
376		struct work_struct crc_generator_work;
377		struct hrtimer timer;
378		ktime_t period_ns;
379
380		/* protects concurrent access to the vblank handler */
381		atomic_t atomic_lock;
382		/* protected by @atomic_lock */
383		bool crc_enabled;
384		struct vmw_surface *surface;
385
386		/* protects concurrent access to the crc worker */
387		spinlock_t crc_state_lock;
388		/* protected by @crc_state_lock */
389		bool crc_pending;
390		u64 frame_start;
391		u64 frame_end;
392	} vkms;
393};
394
395#define vmw_crtc_to_du(x) \
396	container_of(x, struct vmw_display_unit, crtc)
397#define vmw_connector_to_du(x) \
398	container_of(x, struct vmw_display_unit, connector)
399
400
401/*
402 * Shared display unit functions - vmwgfx_kms.c
403 */
404void vmw_du_init(struct vmw_display_unit *du);
405void vmw_du_cleanup(struct vmw_display_unit *du);
406void vmw_du_crtc_save(struct drm_crtc *crtc);
407void vmw_du_crtc_restore(struct drm_crtc *crtc);
408int vmw_du_crtc_gamma_set(struct drm_crtc *crtc,
409			   u16 *r, u16 *g, u16 *b,
410			   uint32_t size,
411			   struct drm_modeset_acquire_ctx *ctx);
412int vmw_du_connector_set_property(struct drm_connector *connector,
413				  struct drm_property *property,
414				  uint64_t val);
415int vmw_du_connector_atomic_set_property(struct drm_connector *connector,
416					 struct drm_connector_state *state,
417					 struct drm_property *property,
418					 uint64_t val);
419int
420vmw_du_connector_atomic_get_property(struct drm_connector *connector,
421				     const struct drm_connector_state *state,
422				     struct drm_property *property,
423				     uint64_t *val);
424int vmw_du_connector_dpms(struct drm_connector *connector, int mode);
425void vmw_du_connector_save(struct drm_connector *connector);
426void vmw_du_connector_restore(struct drm_connector *connector);
427enum drm_connector_status
428vmw_du_connector_detect(struct drm_connector *connector, bool force);
 
 
429int vmw_kms_helper_dirty(struct vmw_private *dev_priv,
430			 struct vmw_framebuffer *framebuffer,
431			 const struct drm_clip_rect *clips,
432			 const struct drm_vmw_rect *vclips,
433			 s32 dest_x, s32 dest_y,
434			 int num_clips,
435			 int increment,
436			 struct vmw_kms_dirty *dirty);
437enum drm_mode_status vmw_connector_mode_valid(struct drm_connector *connector,
438					      struct drm_display_mode *mode);
439int vmw_connector_get_modes(struct drm_connector *connector);
440
441void vmw_kms_helper_validation_finish(struct vmw_private *dev_priv,
442				      struct drm_file *file_priv,
443				      struct vmw_validation_context *ctx,
444				      struct vmw_fence_obj **out_fence,
445				      struct drm_vmw_fence_rep __user *
446				      user_fence_rep);
447int vmw_kms_readback(struct vmw_private *dev_priv,
448		     struct drm_file *file_priv,
449		     struct vmw_framebuffer *vfb,
450		     struct drm_vmw_fence_rep __user *user_fence_rep,
451		     struct drm_vmw_rect *vclips,
452		     uint32_t num_clips);
453struct vmw_framebuffer *
454vmw_kms_new_framebuffer(struct vmw_private *dev_priv,
455			struct vmw_user_object *uo,
 
 
456			const struct drm_mode_fb_cmd2 *mode_cmd);
 
 
 
 
 
 
 
457void vmw_guess_mode_timing(struct drm_display_mode *mode);
458void vmw_kms_update_implicit_fb(struct vmw_private *dev_priv);
459void vmw_kms_create_implicit_placement_property(struct vmw_private *dev_priv);
460
461/* Universal Plane Helpers */
462void vmw_du_primary_plane_destroy(struct drm_plane *plane);
463void vmw_du_cursor_plane_destroy(struct drm_plane *plane);
464
465/* Atomic Helpers */
466int vmw_du_primary_plane_atomic_check(struct drm_plane *plane,
467				      struct drm_atomic_state *state);
468int vmw_du_cursor_plane_atomic_check(struct drm_plane *plane,
469				     struct drm_atomic_state *state);
470void vmw_du_cursor_plane_atomic_update(struct drm_plane *plane,
471				       struct drm_atomic_state *state);
472int vmw_du_cursor_plane_prepare_fb(struct drm_plane *plane,
473				   struct drm_plane_state *new_state);
474void vmw_du_cursor_plane_cleanup_fb(struct drm_plane *plane,
475			     struct drm_plane_state *old_state);
476void vmw_du_plane_cleanup_fb(struct drm_plane *plane,
477			     struct drm_plane_state *old_state);
478void vmw_du_plane_reset(struct drm_plane *plane);
479struct drm_plane_state *vmw_du_plane_duplicate_state(struct drm_plane *plane);
480void vmw_du_plane_destroy_state(struct drm_plane *plane,
481				struct drm_plane_state *state);
482void vmw_du_plane_unpin_surf(struct vmw_plane_state *vps);
 
483
484int vmw_du_crtc_atomic_check(struct drm_crtc *crtc,
485			     struct drm_atomic_state *state);
486void vmw_du_crtc_atomic_begin(struct drm_crtc *crtc,
487			      struct drm_atomic_state *state);
 
 
488void vmw_du_crtc_reset(struct drm_crtc *crtc);
489struct drm_crtc_state *vmw_du_crtc_duplicate_state(struct drm_crtc *crtc);
490void vmw_du_crtc_destroy_state(struct drm_crtc *crtc,
491				struct drm_crtc_state *state);
492void vmw_du_connector_reset(struct drm_connector *connector);
493struct drm_connector_state *
494vmw_du_connector_duplicate_state(struct drm_connector *connector);
495
496void vmw_du_connector_destroy_state(struct drm_connector *connector,
497				    struct drm_connector_state *state);
498
499/*
500 * Legacy display unit functions - vmwgfx_ldu.c
501 */
502int vmw_kms_ldu_init_display(struct vmw_private *dev_priv);
503int vmw_kms_ldu_close_display(struct vmw_private *dev_priv);
 
 
 
 
 
504int vmw_kms_update_proxy(struct vmw_resource *res,
505			 const struct drm_clip_rect *clips,
506			 unsigned num_clips,
507			 int increment);
508
509/*
510 * Screen Objects display functions - vmwgfx_scrn.c
511 */
512int vmw_kms_sou_init_display(struct vmw_private *dev_priv);
513int vmw_kms_sou_do_surface_dirty(struct vmw_private *dev_priv,
514				 struct vmw_framebuffer *framebuffer,
515				 struct drm_clip_rect *clips,
516				 struct drm_vmw_rect *vclips,
517				 struct vmw_resource *srf,
518				 s32 dest_x,
519				 s32 dest_y,
520				 unsigned num_clips, int inc,
521				 struct vmw_fence_obj **out_fence,
522				 struct drm_crtc *crtc);
523int vmw_kms_sou_do_bo_dirty(struct vmw_private *dev_priv,
524			    struct vmw_framebuffer *framebuffer,
525			    struct drm_clip_rect *clips,
526			    struct drm_vmw_rect *vclips,
527			    unsigned int num_clips, int increment,
528			    bool interruptible,
529			    struct vmw_fence_obj **out_fence,
530			    struct drm_crtc *crtc);
531int vmw_kms_sou_readback(struct vmw_private *dev_priv,
532			 struct drm_file *file_priv,
533			 struct vmw_framebuffer *vfb,
534			 struct drm_vmw_fence_rep __user *user_fence_rep,
535			 struct drm_vmw_rect *vclips,
536			 uint32_t num_clips,
537			 struct drm_crtc *crtc);
538
539/*
540 * Screen Target Display Unit functions - vmwgfx_stdu.c
541 */
542int vmw_kms_stdu_init_display(struct vmw_private *dev_priv);
543int vmw_kms_stdu_surface_dirty(struct vmw_private *dev_priv,
544			       struct vmw_framebuffer *framebuffer,
545			       struct drm_clip_rect *clips,
546			       struct drm_vmw_rect *vclips,
547			       struct vmw_resource *srf,
548			       s32 dest_x,
549			       s32 dest_y,
550			       unsigned num_clips, int inc,
551			       struct vmw_fence_obj **out_fence,
552			       struct drm_crtc *crtc);
553int vmw_kms_stdu_readback(struct vmw_private *dev_priv,
554			  struct drm_file *file_priv,
555			  struct vmw_framebuffer *vfb,
556			  struct drm_vmw_fence_rep __user *user_fence_rep,
557			  struct drm_clip_rect *clips,
558			  struct drm_vmw_rect *vclips,
559			  uint32_t num_clips,
560			  int increment,
561			  struct drm_crtc *crtc);
 
 
562
563int vmw_du_helper_plane_update(struct vmw_du_update_plane *update);
564
565/**
566 * vmw_du_translate_to_crtc - Translate a rect from framebuffer to crtc
567 * @state: Plane state.
568 * @r: Rectangle to translate.
569 */
570static inline void vmw_du_translate_to_crtc(struct drm_plane_state *state,
571					    struct drm_rect *r)
572{
573	int translate_crtc_x = -((state->src_x >> 16) - state->crtc_x);
574	int translate_crtc_y = -((state->src_y >> 16) - state->crtc_y);
575
576	drm_rect_translate(r, translate_crtc_x, translate_crtc_y);
577}
578
579#endif