vmwgfx_kms.h 17.8 KB
Newer Older
1
/* SPDX-License-Identifier: GPL-2.0 OR MIT */
2 3
/**************************************************************************
 *
4
 * Copyright 2009-2023 VMware, Inc., Palo Alto, CA., USA
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the
 * "Software"), to deal in the Software without restriction, including
 * without limitation the rights to use, copy, modify, merge, publish,
 * distribute, sub license, and/or sell copies of the Software, and to
 * permit persons to whom the Software is furnished to do so, subject to
 * the following conditions:
 *
 * The above copyright notice and this permission notice (including the
 * next paragraph) shall be included in all copies or substantial portions
 * of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
 * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
 * USE OR OTHER DEALINGS IN THE SOFTWARE.
 *
 **************************************************************************/

#ifndef VMWGFX_KMS_H_
#define VMWGFX_KMS_H_

31
#include <drm/drm_encoder.h>
32
#include <drm/drm_framebuffer.h>
33
#include <drm/drm_probe_helper.h>
34

35 36
#include "vmwgfx_drv.h"

37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
/**
 * struct vmw_du_update_plane - Closure structure for vmw_du_helper_plane_update
 * @plane: Plane which is being updated.
 * @old_state: Old state of plane.
 * @dev_priv: Device private.
 * @du: Display unit on which to update the plane.
 * @vfb: Framebuffer which is blitted to display unit.
 * @out_fence: Out fence for resource finish.
 * @mutex: The mutex used to protect resource reservation.
 * @cpu_blit: True if need cpu blit.
 * @intr: Whether to perform waits interruptible if possible.
 *
 * This structure loosely represent the set of operations needed to perform a
 * plane update on a display unit. Implementer will define that functionality
 * according to the function callbacks for this structure. In brief it involves
 * surface/buffer object validation, populate FIFO commands and command
 * submission to the device.
 */
struct vmw_du_update_plane {
	/**
	 * @calc_fifo_size: Calculate fifo size.
	 *
	 * Determine fifo size for the commands needed for update. The number of
	 * damage clips on display unit @num_hits will be passed to allocate
	 * sufficient fifo space.
	 *
	 * Return: Fifo size needed
	 */
	uint32_t (*calc_fifo_size)(struct vmw_du_update_plane *update,
				   uint32_t num_hits);

	/**
	 * @post_prepare: Populate fifo for resource preparation.
	 *
	 * Some surface resource or buffer object need some extra cmd submission
	 * like update GB image for proxy surface and define a GMRFB for screen
Tom Rix's avatar
Tom Rix committed
73
	 * object. That should be done here as this callback will be
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
	 * called after FIFO allocation with the address of command buufer.
	 *
	 * This callback is optional.
	 *
	 * Return: Size of commands populated to command buffer.
	 */
	uint32_t (*post_prepare)(struct vmw_du_update_plane *update, void *cmd);

	/**
	 * @pre_clip: Populate fifo before clip.
	 *
	 * This is where pre clip related command should be populated like
	 * surface copy/DMA, etc.
	 *
	 * This callback is optional.
	 *
	 * Return: Size of commands populated to command buffer.
	 */
	uint32_t (*pre_clip)(struct vmw_du_update_plane *update, void *cmd,
			     uint32_t num_hits);
94

95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130
	/**
	 * @clip: Populate fifo for clip.
	 *
	 * This is where to populate clips for surface copy/dma or blit commands
	 * if needed. This will be called times have damage in display unit,
	 * which is one if doing full update. @clip is the damage in destination
	 * coordinates which is crtc/DU and @src_x, @src_y is damage clip src in
	 * framebuffer coordinate.
	 *
	 * This callback is optional.
	 *
	 * Return: Size of commands populated to command buffer.
	 */
	uint32_t (*clip)(struct vmw_du_update_plane *update, void *cmd,
			 struct drm_rect *clip, uint32_t src_x, uint32_t src_y);

	/**
	 * @post_clip: Populate fifo after clip.
	 *
	 * This is where to populate display unit update commands or blit
	 * commands.
	 *
	 * Return: Size of commands populated to command buffer.
	 */
	uint32_t (*post_clip)(struct vmw_du_update_plane *update, void *cmd,
				    struct drm_rect *bb);

	struct drm_plane *plane;
	struct drm_plane_state *old_state;
	struct vmw_private *dev_priv;
	struct vmw_display_unit *du;
	struct vmw_framebuffer *vfb;
	struct vmw_fence_obj **out_fence;
	struct mutex *mutex;
	bool intr;
};
131

132 133 134 135 136 137 138 139 140 141 142
/**
 * struct vmw_du_update_plane_surface - closure structure for surface
 * @base: base closure structure.
 * @cmd_start: FIFO command start address (used by SOU only).
 */
struct vmw_du_update_plane_surface {
	struct vmw_du_update_plane base;
	/* This member is to handle special case SOU surface update */
	void *cmd_start;
};

143 144 145 146 147 148 149 150 151 152 153
/**
 * struct vmw_du_update_plane_buffer - Closure structure for buffer object
 * @base: Base closure structure.
 * @fb_left: x1 for fb damage bounding box.
 * @fb_top: y1 for fb damage bounding box.
 */
struct vmw_du_update_plane_buffer {
	struct vmw_du_update_plane base;
	int fb_left, fb_top;
};

154 155 156 157 158 159 160 161 162 163 164 165 166 167 168
/**
 * struct vmw_kms_dirty - closure structure for the vmw_kms_helper_dirty
 * function.
 *
 * @fifo_commit: Callback that is called once for each display unit after
 * all clip rects. This function must commit the fifo space reserved by the
 * helper. Set up by the caller.
 * @clip: Callback that is called for each cliprect on each display unit.
 * Set up by the caller.
 * @fifo_reserve_size: Fifo size that the helper should try to allocat for
 * each display unit. Set up by the caller.
 * @dev_priv: Pointer to the device private. Set up by the helper.
 * @unit: The current display unit. Set up by the helper before a call to @clip.
 * @cmd: The allocated fifo space. Set up by the helper before the first @clip
 * call.
169
 * @crtc: The crtc for which to build dirty commands.
170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190
 * @num_hits: Number of clip rect commands for this display unit.
 * Cleared by the helper before the first @clip call. Updated by the @clip
 * callback.
 * @fb_x: Clip rect left side in framebuffer coordinates.
 * @fb_y: Clip rect right side in framebuffer coordinates.
 * @unit_x1: Clip rect left side in crtc coordinates.
 * @unit_y1: Clip rect top side in crtc coordinates.
 * @unit_x2: Clip rect right side in crtc coordinates.
 * @unit_y2: Clip rect bottom side in crtc coordinates.
 *
 * The clip rect coordinates are updated by the helper for each @clip call.
 * Note that this may be derived from if more info needs to be passed between
 * helper caller and helper callbacks.
 */
struct vmw_kms_dirty {
	void (*fifo_commit)(struct vmw_kms_dirty *);
	void (*clip)(struct vmw_kms_dirty *);
	size_t fifo_reserve_size;
	struct vmw_private *dev_priv;
	struct vmw_display_unit *unit;
	void *cmd;
191
	struct drm_crtc *crtc;
192 193 194 195 196 197 198 199
	u32 num_hits;
	s32 fb_x;
	s32 fb_y;
	s32 unit_x1;
	s32 unit_y1;
	s32 unit_x2;
	s32 unit_y2;
};
200

201 202
#define VMWGFX_NUM_DISPLAY_UNITS 8

203 204 205

#define vmw_framebuffer_to_vfb(x) \
	container_of(x, struct vmw_framebuffer, base)
206 207 208
#define vmw_framebuffer_to_vfbs(x) \
	container_of(x, struct vmw_framebuffer_surface, base.base)
#define vmw_framebuffer_to_vfbd(x) \
209
	container_of(x, struct vmw_framebuffer_bo, base.base)
210 211 212 213 214 215 216 217 218

/**
 * Base class for framebuffers
 *
 * @pin is called the when ever a crtc uses this framebuffer
 * @unpin is called
 */
struct vmw_framebuffer {
	struct drm_framebuffer base;
219
	bool bo;
220 221 222 223 224
};

struct vmw_framebuffer_surface {
	struct vmw_framebuffer base;
	struct vmw_surface *surface;
225
	bool is_bo_proxy;  /* true if this is proxy surface for DMA buf */
226
};
227

228

229
struct vmw_framebuffer_bo {
230
	struct vmw_framebuffer base;
231
	struct vmw_bo *buffer;
232
};
233 234


235
static const uint32_t __maybe_unused vmw_primary_plane_formats[] = {
236 237 238 239 240
	DRM_FORMAT_XRGB1555,
	DRM_FORMAT_RGB565,
	DRM_FORMAT_XRGB8888,
	DRM_FORMAT_ARGB8888,
};
241

242
static const uint32_t __maybe_unused vmw_cursor_plane_formats[] = {
243 244
	DRM_FORMAT_ARGB8888,
};
245

246 247

#define vmw_crtc_state_to_vcs(x) container_of(x, struct vmw_crtc_state, base)
248
#define vmw_plane_state_to_vps(x) container_of(x, struct vmw_plane_state, base)
249 250
#define vmw_connector_state_to_vcs(x) \
		container_of(x, struct vmw_connector_state, base)
251
#define vmw_plane_to_vcp(x) container_of(x, struct vmw_cursor_plane, base)
252 253 254 255 256 257 258 259 260 261

/**
 * Derived class for crtc state object
 *
 * @base DRM crtc object
 */
struct vmw_crtc_state {
	struct drm_crtc_state base;
};

262
struct vmw_cursor_plane_state {
263
	struct vmw_bo *bo;
264 265
	s32 hotspot_x;
	s32 hotspot_y;
266 267
};

268 269 270 271 272
/**
 * Derived class for plane state object
 *
 * @base DRM plane object
 * @surf Display surface for STDU
273
 * @bo display bo for SOU
274
 * @content_fb_type Used by STDU.
275
 * @bo_size Size of the bo, used by Screen Object Display Unit
276 277 278 279 280
 * @pinned pin count for STDU display surface
 */
struct vmw_plane_state {
	struct drm_plane_state base;
	struct vmw_surface *surf;
281
	struct vmw_bo *bo;
282 283

	int content_fb_type;
284
	unsigned long bo_size;
285 286

	int pinned;
287 288 289

	/* For CPU Blit */
	unsigned int cpp;
290

291
	bool surf_mapped;
292
	struct vmw_cursor_plane_state cursor;
293 294
};

295 296 297 298 299 300 301 302 303 304 305

/**
 * Derived class for connector state object
 *
 * @base DRM connector object
 * @is_implicit connector property
 *
 */
struct vmw_connector_state {
	struct drm_connector_state base;

306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322
	/**
	 * @gui_x:
	 *
	 * vmwgfx connector property representing the x position of this display
	 * unit (connector is synonymous to display unit) in overall topology.
	 * This is what the device expect as xRoot while creating screen.
	 */
	int gui_x;

	/**
	 * @gui_y:
	 *
	 * vmwgfx connector property representing the y position of this display
	 * unit (connector is synonymous to display unit) in overall topology.
	 * This is what the device expect as yRoot while creating screen.
	 */
	int gui_y;
323 324
};

325 326 327 328
/**
 * Derived class for cursor plane object
 *
 * @base DRM plane object
329
 * @cursor.cursor_mobs Cursor mobs available for re-use
330 331 332
 */
struct vmw_cursor_plane {
	struct drm_plane base;
333

334
	struct vmw_bo *cursor_mobs[3];
335 336
};

337 338 339 340 341 342 343 344 345 346 347
/**
 * Base class display unit.
 *
 * Since the SVGA hw doesn't have a concept of a crtc, encoder or connector
 * so the display unit is all of them at the same time. This is true for both
 * legacy multimon and screen objects.
 */
struct vmw_display_unit {
	struct drm_crtc crtc;
	struct drm_encoder encoder;
	struct drm_connector connector;
348
	struct drm_plane primary;
349
	struct vmw_cursor_plane cursor;
350 351 352 353 354 355 356 357 358

	struct vmw_surface *cursor_surface;
	size_t cursor_age;

	int cursor_x;
	int cursor_y;

	int hotspot_x;
	int hotspot_y;
359 360
	s32 core_hotspot_x;
	s32 core_hotspot_y;
361 362

	unsigned unit;
363 364 365 366 367 368 369

	/*
	 * Prefered mode tracking.
	 */
	unsigned pref_width;
	unsigned pref_height;
	bool pref_active;
370 371 372 373 374 375

	/*
	 * Gui positioning
	 */
	int gui_x;
	int gui_y;
376
	bool is_implicit;
377 378
	int set_gui_x;
	int set_gui_y;
379 380
};

381 382
#define vmw_crtc_to_du(x) \
	container_of(x, struct vmw_display_unit, crtc)
383 384 385 386
#define vmw_connector_to_du(x) \
	container_of(x, struct vmw_display_unit, connector)


387 388 389
/*
 * Shared display unit functions - vmwgfx_kms.c
 */
390
void vmw_du_cleanup(struct vmw_display_unit *du);
391 392
void vmw_du_crtc_save(struct drm_crtc *crtc);
void vmw_du_crtc_restore(struct drm_crtc *crtc);
393
int vmw_du_crtc_gamma_set(struct drm_crtc *crtc,
394
			   u16 *r, u16 *g, u16 *b,
395 396
			   uint32_t size,
			   struct drm_modeset_acquire_ctx *ctx);
397 398 399
int vmw_du_connector_set_property(struct drm_connector *connector,
				  struct drm_property *property,
				  uint64_t val);
400 401 402 403 404 405 406 407 408
int vmw_du_connector_atomic_set_property(struct drm_connector *connector,
					 struct drm_connector_state *state,
					 struct drm_property *property,
					 uint64_t val);
int
vmw_du_connector_atomic_get_property(struct drm_connector *connector,
				     const struct drm_connector_state *state,
				     struct drm_property *property,
				     uint64_t *val);
409
int vmw_du_connector_dpms(struct drm_connector *connector, int mode);
410 411 412 413
void vmw_du_connector_save(struct drm_connector *connector);
void vmw_du_connector_restore(struct drm_connector *connector);
enum drm_connector_status
vmw_du_connector_detect(struct drm_connector *connector, bool force);
414 415 416 417 418 419 420 421
int vmw_kms_helper_dirty(struct vmw_private *dev_priv,
			 struct vmw_framebuffer *framebuffer,
			 const struct drm_clip_rect *clips,
			 const struct drm_vmw_rect *vclips,
			 s32 dest_x, s32 dest_y,
			 int num_clips,
			 int increment,
			 struct vmw_kms_dirty *dirty);
422 423 424
enum drm_mode_status vmw_connector_mode_valid(struct drm_connector *connector,
					      struct drm_display_mode *mode);
int vmw_connector_get_modes(struct drm_connector *connector);
425

426 427 428 429 430 431
void vmw_kms_helper_validation_finish(struct vmw_private *dev_priv,
				      struct drm_file *file_priv,
				      struct vmw_validation_context *ctx,
				      struct vmw_fence_obj **out_fence,
				      struct drm_vmw_fence_rep __user *
				      user_fence_rep);
432 433 434 435 436 437
int vmw_kms_readback(struct vmw_private *dev_priv,
		     struct drm_file *file_priv,
		     struct vmw_framebuffer *vfb,
		     struct drm_vmw_fence_rep __user *user_fence_rep,
		     struct drm_vmw_rect *vclips,
		     uint32_t num_clips);
438 439
struct vmw_framebuffer *
vmw_kms_new_framebuffer(struct vmw_private *dev_priv,
440
			struct vmw_bo *bo,
441 442
			struct vmw_surface *surface,
			bool only_2d,
443
			const struct drm_mode_fb_cmd2 *mode_cmd);
444
void vmw_guess_mode_timing(struct drm_display_mode *mode);
445 446
void vmw_kms_update_implicit_fb(struct vmw_private *dev_priv);
void vmw_kms_create_implicit_placement_property(struct vmw_private *dev_priv);
447

448 449 450 451
/* Universal Plane Helpers */
void vmw_du_primary_plane_destroy(struct drm_plane *plane);
void vmw_du_cursor_plane_destroy(struct drm_plane *plane);

452
/* Atomic Helpers */
453
int vmw_du_primary_plane_atomic_check(struct drm_plane *plane,
454
				      struct drm_atomic_state *state);
455
int vmw_du_cursor_plane_atomic_check(struct drm_plane *plane,
456
				     struct drm_atomic_state *state);
457
void vmw_du_cursor_plane_atomic_update(struct drm_plane *plane,
458
				       struct drm_atomic_state *state);
459 460
int vmw_du_cursor_plane_prepare_fb(struct drm_plane *plane,
				   struct drm_plane_state *new_state);
461 462
void vmw_du_cursor_plane_cleanup_fb(struct drm_plane *plane,
			     struct drm_plane_state *old_state);
463 464
void vmw_du_plane_cleanup_fb(struct drm_plane *plane,
			     struct drm_plane_state *old_state);
465 466 467 468
void vmw_du_plane_reset(struct drm_plane *plane);
struct drm_plane_state *vmw_du_plane_duplicate_state(struct drm_plane *plane);
void vmw_du_plane_destroy_state(struct drm_plane *plane,
				struct drm_plane_state *state);
469 470 471
void vmw_du_plane_unpin_surf(struct vmw_plane_state *vps,
			     bool unreference);

472
int vmw_du_crtc_atomic_check(struct drm_crtc *crtc,
473
			     struct drm_atomic_state *state);
474
void vmw_du_crtc_atomic_begin(struct drm_crtc *crtc,
475
			      struct drm_atomic_state *state);
476
void vmw_du_crtc_atomic_flush(struct drm_crtc *crtc,
477
			      struct drm_atomic_state *state);
478 479 480 481
void vmw_du_crtc_reset(struct drm_crtc *crtc);
struct drm_crtc_state *vmw_du_crtc_duplicate_state(struct drm_crtc *crtc);
void vmw_du_crtc_destroy_state(struct drm_crtc *crtc,
				struct drm_crtc_state *state);
482 483 484 485 486 487
void vmw_du_connector_reset(struct drm_connector *connector);
struct drm_connector_state *
vmw_du_connector_duplicate_state(struct drm_connector *connector);

void vmw_du_connector_destroy_state(struct drm_connector *connector,
				    struct drm_connector_state *state);
488 489

/*
490
 * Legacy display unit functions - vmwgfx_ldu.c
491
 */
492 493
int vmw_kms_ldu_init_display(struct vmw_private *dev_priv);
int vmw_kms_ldu_close_display(struct vmw_private *dev_priv);
494 495 496 497
int vmw_kms_update_proxy(struct vmw_resource *res,
			 const struct drm_clip_rect *clips,
			 unsigned num_clips,
			 int increment);
498

499 500 501
/*
 * Screen Objects display functions - vmwgfx_scrn.c
 */
502 503 504 505
int vmw_kms_sou_init_display(struct vmw_private *dev_priv);
int vmw_kms_sou_do_surface_dirty(struct vmw_private *dev_priv,
				 struct vmw_framebuffer *framebuffer,
				 struct drm_clip_rect *clips,
506 507 508 509
				 struct drm_vmw_rect *vclips,
				 struct vmw_resource *srf,
				 s32 dest_x,
				 s32 dest_y,
510
				 unsigned num_clips, int inc,
511 512
				 struct vmw_fence_obj **out_fence,
				 struct drm_crtc *crtc);
513 514 515 516 517 518 519 520
int vmw_kms_sou_do_bo_dirty(struct vmw_private *dev_priv,
			    struct vmw_framebuffer *framebuffer,
			    struct drm_clip_rect *clips,
			    struct drm_vmw_rect *vclips,
			    unsigned int num_clips, int increment,
			    bool interruptible,
			    struct vmw_fence_obj **out_fence,
			    struct drm_crtc *crtc);
521 522 523 524 525
int vmw_kms_sou_readback(struct vmw_private *dev_priv,
			 struct drm_file *file_priv,
			 struct vmw_framebuffer *vfb,
			 struct drm_vmw_fence_rep __user *user_fence_rep,
			 struct drm_vmw_rect *vclips,
526 527
			 uint32_t num_clips,
			 struct drm_crtc *crtc);
528 529 530 531 532

/*
 * Screen Target Display Unit functions - vmwgfx_stdu.c
 */
int vmw_kms_stdu_init_display(struct vmw_private *dev_priv);
533 534 535 536 537 538 539 540
int vmw_kms_stdu_surface_dirty(struct vmw_private *dev_priv,
			       struct vmw_framebuffer *framebuffer,
			       struct drm_clip_rect *clips,
			       struct drm_vmw_rect *vclips,
			       struct vmw_resource *srf,
			       s32 dest_x,
			       s32 dest_y,
			       unsigned num_clips, int inc,
541 542
			       struct vmw_fence_obj **out_fence,
			       struct drm_crtc *crtc);
543 544 545 546 547 548 549 550 551
int vmw_kms_stdu_readback(struct vmw_private *dev_priv,
			  struct drm_file *file_priv,
			  struct vmw_framebuffer *vfb,
			  struct drm_vmw_fence_rep __user *user_fence_rep,
			  struct drm_clip_rect *clips,
			  struct drm_vmw_rect *vclips,
			  uint32_t num_clips,
			  int increment,
			  struct drm_crtc *crtc);
552

553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568
int vmw_du_helper_plane_update(struct vmw_du_update_plane *update);

/**
 * vmw_du_translate_to_crtc - Translate a rect from framebuffer to crtc
 * @state: Plane state.
 * @r: Rectangle to translate.
 */
static inline void vmw_du_translate_to_crtc(struct drm_plane_state *state,
					    struct drm_rect *r)
{
	int translate_crtc_x = -((state->src_x >> 16) - state->crtc_x);
	int translate_crtc_y = -((state->src_y >> 16) - state->crtc_y);

	drm_rect_translate(r, translate_crtc_x, translate_crtc_y);
}

569
#endif