1dff96888SDirk Hohndel (VMware) /* SPDX-License-Identifier: GPL-2.0 OR MIT */ 2fb1d9738SJakob Bornecrantz /************************************************************************** 3fb1d9738SJakob Bornecrantz * 4485d98d4SMartin Krastev * Copyright 2009-2022 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 cpu_blit; 130e41774c0SDeepak Rawat bool intr; 131e41774c0SDeepak Rawat }; 13236cc79bcSSinclair Yeh 1331a4b172aSThomas Hellstrom /** 13443d1e627SDeepak Rawat * struct vmw_du_update_plane_surface - closure structure for surface 13543d1e627SDeepak Rawat * @base: base closure structure. 13643d1e627SDeepak Rawat * @cmd_start: FIFO command start address (used by SOU only). 13743d1e627SDeepak Rawat */ 13843d1e627SDeepak Rawat struct vmw_du_update_plane_surface { 13943d1e627SDeepak Rawat struct vmw_du_update_plane base; 14043d1e627SDeepak Rawat /* This member is to handle special case SOU surface update */ 14143d1e627SDeepak Rawat void *cmd_start; 14243d1e627SDeepak Rawat }; 14343d1e627SDeepak Rawat 14443d1e627SDeepak Rawat /** 145bc7be607SDeepak Rawat * struct vmw_du_update_plane_buffer - Closure structure for buffer object 146bc7be607SDeepak Rawat * @base: Base closure structure. 147bc7be607SDeepak Rawat * @fb_left: x1 for fb damage bounding box. 148bc7be607SDeepak Rawat * @fb_top: y1 for fb damage bounding box. 149bc7be607SDeepak Rawat */ 150bc7be607SDeepak Rawat struct vmw_du_update_plane_buffer { 151bc7be607SDeepak Rawat struct vmw_du_update_plane base; 152bc7be607SDeepak Rawat int fb_left, fb_top; 153bc7be607SDeepak Rawat }; 154bc7be607SDeepak Rawat 155bc7be607SDeepak Rawat /** 1561a4b172aSThomas Hellstrom * struct vmw_kms_dirty - closure structure for the vmw_kms_helper_dirty 1571a4b172aSThomas Hellstrom * function. 1581a4b172aSThomas Hellstrom * 1591a4b172aSThomas Hellstrom * @fifo_commit: Callback that is called once for each display unit after 1601a4b172aSThomas Hellstrom * all clip rects. This function must commit the fifo space reserved by the 1611a4b172aSThomas Hellstrom * helper. Set up by the caller. 1621a4b172aSThomas Hellstrom * @clip: Callback that is called for each cliprect on each display unit. 1631a4b172aSThomas Hellstrom * Set up by the caller. 1641a4b172aSThomas Hellstrom * @fifo_reserve_size: Fifo size that the helper should try to allocat for 1651a4b172aSThomas Hellstrom * each display unit. Set up by the caller. 1661a4b172aSThomas Hellstrom * @dev_priv: Pointer to the device private. Set up by the helper. 1671a4b172aSThomas Hellstrom * @unit: The current display unit. Set up by the helper before a call to @clip. 1681a4b172aSThomas Hellstrom * @cmd: The allocated fifo space. Set up by the helper before the first @clip 1691a4b172aSThomas Hellstrom * call. 17091e9f352SDeepak Rawat * @crtc: The crtc for which to build dirty commands. 1711a4b172aSThomas Hellstrom * @num_hits: Number of clip rect commands for this display unit. 1721a4b172aSThomas Hellstrom * Cleared by the helper before the first @clip call. Updated by the @clip 1731a4b172aSThomas Hellstrom * callback. 1741a4b172aSThomas Hellstrom * @fb_x: Clip rect left side in framebuffer coordinates. 1751a4b172aSThomas Hellstrom * @fb_y: Clip rect right side in framebuffer coordinates. 1761a4b172aSThomas Hellstrom * @unit_x1: Clip rect left side in crtc coordinates. 1771a4b172aSThomas Hellstrom * @unit_y1: Clip rect top side in crtc coordinates. 1781a4b172aSThomas Hellstrom * @unit_x2: Clip rect right side in crtc coordinates. 1791a4b172aSThomas Hellstrom * @unit_y2: Clip rect bottom side in crtc coordinates. 1801a4b172aSThomas Hellstrom * 1811a4b172aSThomas Hellstrom * The clip rect coordinates are updated by the helper for each @clip call. 1821a4b172aSThomas Hellstrom * Note that this may be derived from if more info needs to be passed between 1831a4b172aSThomas Hellstrom * helper caller and helper callbacks. 1841a4b172aSThomas Hellstrom */ 1851a4b172aSThomas Hellstrom struct vmw_kms_dirty { 1861a4b172aSThomas Hellstrom void (*fifo_commit)(struct vmw_kms_dirty *); 1871a4b172aSThomas Hellstrom void (*clip)(struct vmw_kms_dirty *); 1881a4b172aSThomas Hellstrom size_t fifo_reserve_size; 1891a4b172aSThomas Hellstrom struct vmw_private *dev_priv; 1901a4b172aSThomas Hellstrom struct vmw_display_unit *unit; 1911a4b172aSThomas Hellstrom void *cmd; 19291e9f352SDeepak Rawat struct drm_crtc *crtc; 1931a4b172aSThomas Hellstrom u32 num_hits; 1941a4b172aSThomas Hellstrom s32 fb_x; 1951a4b172aSThomas Hellstrom s32 fb_y; 1961a4b172aSThomas Hellstrom s32 unit_x1; 1971a4b172aSThomas Hellstrom s32 unit_y1; 1981a4b172aSThomas Hellstrom s32 unit_x2; 1991a4b172aSThomas Hellstrom s32 unit_y2; 2001a4b172aSThomas Hellstrom }; 201c8261a96SSinclair Yeh 20256d1c78dSJakob Bornecrantz #define VMWGFX_NUM_DISPLAY_UNITS 8 20356d1c78dSJakob Bornecrantz 204fb1d9738SJakob Bornecrantz 205fb1d9738SJakob Bornecrantz #define vmw_framebuffer_to_vfb(x) \ 206fb1d9738SJakob Bornecrantz container_of(x, struct vmw_framebuffer, base) 207c8261a96SSinclair Yeh #define vmw_framebuffer_to_vfbs(x) \ 208c8261a96SSinclair Yeh container_of(x, struct vmw_framebuffer_surface, base.base) 209c8261a96SSinclair Yeh #define vmw_framebuffer_to_vfbd(x) \ 210f1d34bfdSThomas Hellstrom container_of(x, struct vmw_framebuffer_bo, base.base) 211fb1d9738SJakob Bornecrantz 212fb1d9738SJakob Bornecrantz /** 213fb1d9738SJakob Bornecrantz * Base class for framebuffers 214fb1d9738SJakob Bornecrantz * 215fb1d9738SJakob Bornecrantz * @pin is called the when ever a crtc uses this framebuffer 216fb1d9738SJakob Bornecrantz * @unpin is called 217fb1d9738SJakob Bornecrantz */ 218fb1d9738SJakob Bornecrantz struct vmw_framebuffer { 219fb1d9738SJakob Bornecrantz struct drm_framebuffer base; 220fb1d9738SJakob Bornecrantz int (*pin)(struct vmw_framebuffer *fb); 221fb1d9738SJakob Bornecrantz int (*unpin)(struct vmw_framebuffer *fb); 222f1d34bfdSThomas Hellstrom bool bo; 22390ff18bcSThomas Hellstrom uint32_t user_handle; 224fb1d9738SJakob Bornecrantz }; 225fb1d9738SJakob Bornecrantz 226c8261a96SSinclair Yeh /* 227c8261a96SSinclair Yeh * Clip rectangle 228c8261a96SSinclair Yeh */ 229c8261a96SSinclair Yeh struct vmw_clip_rect { 230c8261a96SSinclair Yeh int x1, x2, y1, y2; 231c8261a96SSinclair Yeh }; 232fb1d9738SJakob Bornecrantz 233c8261a96SSinclair Yeh struct vmw_framebuffer_surface { 234c8261a96SSinclair Yeh struct vmw_framebuffer base; 235c8261a96SSinclair Yeh struct vmw_surface *surface; 236f1d34bfdSThomas Hellstrom struct vmw_buffer_object *buffer; 237c8261a96SSinclair Yeh struct list_head head; 238f1d34bfdSThomas Hellstrom bool is_bo_proxy; /* true if this is proxy surface for DMA buf */ 239c8261a96SSinclair Yeh }; 240c8261a96SSinclair Yeh 241c8261a96SSinclair Yeh 242f1d34bfdSThomas Hellstrom struct vmw_framebuffer_bo { 243c8261a96SSinclair Yeh struct vmw_framebuffer base; 244f1d34bfdSThomas Hellstrom struct vmw_buffer_object *buffer; 245c8261a96SSinclair Yeh }; 246c8261a96SSinclair Yeh 247fb1d9738SJakob Bornecrantz 248d8713d66SLee Jones static const uint32_t __maybe_unused vmw_primary_plane_formats[] = { 24936cc79bcSSinclair Yeh DRM_FORMAT_XRGB1555, 25036cc79bcSSinclair Yeh DRM_FORMAT_RGB565, 25136cc79bcSSinclair Yeh DRM_FORMAT_XRGB8888, 25236cc79bcSSinclair Yeh DRM_FORMAT_ARGB8888, 25336cc79bcSSinclair Yeh }; 254fb1d9738SJakob Bornecrantz 255d8713d66SLee Jones static const uint32_t __maybe_unused vmw_cursor_plane_formats[] = { 25636cc79bcSSinclair Yeh DRM_FORMAT_ARGB8888, 25736cc79bcSSinclair Yeh }; 258bfc2638dSJakob Bornecrantz 2599c2542a4SSinclair Yeh 2609c2542a4SSinclair Yeh #define vmw_crtc_state_to_vcs(x) container_of(x, struct vmw_crtc_state, base) 261cc5ec459SSinclair Yeh #define vmw_plane_state_to_vps(x) container_of(x, struct vmw_plane_state, base) 262d7721ca7SSinclair Yeh #define vmw_connector_state_to_vcs(x) \ 263d7721ca7SSinclair Yeh container_of(x, struct vmw_connector_state, base) 264485d98d4SMartin Krastev #define vmw_plane_to_vcp(x) container_of(x, struct vmw_cursor_plane, base) 2659c2542a4SSinclair Yeh 2669c2542a4SSinclair Yeh /** 2679c2542a4SSinclair Yeh * Derived class for crtc state object 2689c2542a4SSinclair Yeh * 2699c2542a4SSinclair Yeh * @base DRM crtc object 2709c2542a4SSinclair Yeh */ 2719c2542a4SSinclair Yeh struct vmw_crtc_state { 2729c2542a4SSinclair Yeh struct drm_crtc_state base; 2739c2542a4SSinclair Yeh }; 2749c2542a4SSinclair Yeh 27540f9e40bSMichael Banack struct vmw_cursor_plane_state { 27640f9e40bSMichael Banack struct ttm_buffer_object *bo; 27740f9e40bSMichael Banack struct ttm_bo_kmap_obj map; 27840f9e40bSMichael Banack bool mapped; 279*bb6780aaSMichael Banack s32 hotspot_x; 280*bb6780aaSMichael Banack s32 hotspot_y; 28140f9e40bSMichael Banack }; 28240f9e40bSMichael Banack 283fb1d9738SJakob Bornecrantz /** 284cc5ec459SSinclair Yeh * Derived class for plane state object 285cc5ec459SSinclair Yeh * 286cc5ec459SSinclair Yeh * @base DRM plane object 287cc5ec459SSinclair Yeh * @surf Display surface for STDU 288f1d34bfdSThomas Hellstrom * @bo display bo for SOU 289cc5ec459SSinclair Yeh * @content_fb_type Used by STDU. 290f1d34bfdSThomas Hellstrom * @bo_size Size of the bo, used by Screen Object Display Unit 291cc5ec459SSinclair Yeh * @pinned pin count for STDU display surface 292cc5ec459SSinclair Yeh */ 293cc5ec459SSinclair Yeh struct vmw_plane_state { 294cc5ec459SSinclair Yeh struct drm_plane_state base; 295cc5ec459SSinclair Yeh struct vmw_surface *surf; 296f1d34bfdSThomas Hellstrom struct vmw_buffer_object *bo; 297cc5ec459SSinclair Yeh 298cc5ec459SSinclair Yeh int content_fb_type; 299f1d34bfdSThomas Hellstrom unsigned long bo_size; 300cc5ec459SSinclair Yeh 301cc5ec459SSinclair Yeh int pinned; 302810b3e16SSinclair Yeh 303810b3e16SSinclair Yeh /* For CPU Blit */ 304810b3e16SSinclair Yeh unsigned int cpp; 305485d98d4SMartin Krastev 30692f59ac4SMichael Banack bool surf_mapped; 30740f9e40bSMichael Banack struct vmw_cursor_plane_state cursor; 308cc5ec459SSinclair Yeh }; 309cc5ec459SSinclair Yeh 310d7721ca7SSinclair Yeh 311d7721ca7SSinclair Yeh /** 312d7721ca7SSinclair Yeh * Derived class for connector state object 313d7721ca7SSinclair Yeh * 314d7721ca7SSinclair Yeh * @base DRM connector object 315d7721ca7SSinclair Yeh * @is_implicit connector property 316d7721ca7SSinclair Yeh * 317d7721ca7SSinclair Yeh */ 318d7721ca7SSinclair Yeh struct vmw_connector_state { 319d7721ca7SSinclair Yeh struct drm_connector_state base; 320d7721ca7SSinclair Yeh 3213e79ecdaSDeepak Rawat /** 3223e79ecdaSDeepak Rawat * @gui_x: 3233e79ecdaSDeepak Rawat * 3243e79ecdaSDeepak Rawat * vmwgfx connector property representing the x position of this display 3253e79ecdaSDeepak Rawat * unit (connector is synonymous to display unit) in overall topology. 3263e79ecdaSDeepak Rawat * This is what the device expect as xRoot while creating screen. 3273e79ecdaSDeepak Rawat */ 3283e79ecdaSDeepak Rawat int gui_x; 3293e79ecdaSDeepak Rawat 3303e79ecdaSDeepak Rawat /** 3313e79ecdaSDeepak Rawat * @gui_y: 3323e79ecdaSDeepak Rawat * 3333e79ecdaSDeepak Rawat * vmwgfx connector property representing the y position of this display 3343e79ecdaSDeepak Rawat * unit (connector is synonymous to display unit) in overall topology. 3353e79ecdaSDeepak Rawat * This is what the device expect as yRoot while creating screen. 3363e79ecdaSDeepak Rawat */ 3373e79ecdaSDeepak Rawat int gui_y; 338d7721ca7SSinclair Yeh }; 339d7721ca7SSinclair Yeh 340cc5ec459SSinclair Yeh /** 341485d98d4SMartin Krastev * Derived class for cursor plane object 342485d98d4SMartin Krastev * 343485d98d4SMartin Krastev * @base DRM plane object 34453bc3f6fSMichael Banack * @cursor.cursor_mobs Cursor mobs available for re-use 345485d98d4SMartin Krastev */ 346485d98d4SMartin Krastev struct vmw_cursor_plane { 347485d98d4SMartin Krastev struct drm_plane base; 34853bc3f6fSMichael Banack 34953bc3f6fSMichael Banack struct ttm_buffer_object *cursor_mobs[3]; 350485d98d4SMartin Krastev }; 351485d98d4SMartin Krastev 352485d98d4SMartin Krastev /** 353fb1d9738SJakob Bornecrantz * Base class display unit. 354fb1d9738SJakob Bornecrantz * 355fb1d9738SJakob Bornecrantz * Since the SVGA hw doesn't have a concept of a crtc, encoder or connector 356fb1d9738SJakob Bornecrantz * so the display unit is all of them at the same time. This is true for both 357fb1d9738SJakob Bornecrantz * legacy multimon and screen objects. 358fb1d9738SJakob Bornecrantz */ 359fb1d9738SJakob Bornecrantz struct vmw_display_unit { 360fb1d9738SJakob Bornecrantz struct drm_crtc crtc; 361fb1d9738SJakob Bornecrantz struct drm_encoder encoder; 362fb1d9738SJakob Bornecrantz struct drm_connector connector; 36336cc79bcSSinclair Yeh struct drm_plane primary; 364485d98d4SMartin Krastev struct vmw_cursor_plane cursor; 365fb1d9738SJakob Bornecrantz 366fb1d9738SJakob Bornecrantz struct vmw_surface *cursor_surface; 367f1d34bfdSThomas Hellstrom struct vmw_buffer_object *cursor_bo; 368fb1d9738SJakob Bornecrantz size_t cursor_age; 369fb1d9738SJakob Bornecrantz 370fb1d9738SJakob Bornecrantz int cursor_x; 371fb1d9738SJakob Bornecrantz int cursor_y; 372fb1d9738SJakob Bornecrantz 373fb1d9738SJakob Bornecrantz int hotspot_x; 374fb1d9738SJakob Bornecrantz int hotspot_y; 3758fbf9d92SThomas Hellstrom s32 core_hotspot_x; 3768fbf9d92SThomas Hellstrom s32 core_hotspot_y; 377fb1d9738SJakob Bornecrantz 378fb1d9738SJakob Bornecrantz unsigned unit; 379626ab771SJakob Bornecrantz 380626ab771SJakob Bornecrantz /* 381626ab771SJakob Bornecrantz * Prefered mode tracking. 382626ab771SJakob Bornecrantz */ 383626ab771SJakob Bornecrantz unsigned pref_width; 384626ab771SJakob Bornecrantz unsigned pref_height; 385626ab771SJakob Bornecrantz bool pref_active; 386626ab771SJakob Bornecrantz struct drm_display_mode *pref_mode; 387cd2b89e7SThomas Hellstrom 388cd2b89e7SThomas Hellstrom /* 389cd2b89e7SThomas Hellstrom * Gui positioning 390cd2b89e7SThomas Hellstrom */ 391cd2b89e7SThomas Hellstrom int gui_x; 392cd2b89e7SThomas Hellstrom int gui_y; 3936987427aSThomas Hellstrom bool is_implicit; 3946dd687b4SThomas Hellstrom int set_gui_x; 3956dd687b4SThomas Hellstrom int set_gui_y; 396fb1d9738SJakob Bornecrantz }; 397fb1d9738SJakob Bornecrantz 39873a88250SThomas Hellstrom struct vmw_validation_ctx { 39973a88250SThomas Hellstrom struct vmw_resource *res; 400f1d34bfdSThomas Hellstrom struct vmw_buffer_object *buf; 40173a88250SThomas Hellstrom }; 40273a88250SThomas Hellstrom 4032fcd5a73SJakob Bornecrantz #define vmw_crtc_to_du(x) \ 4042fcd5a73SJakob Bornecrantz container_of(x, struct vmw_display_unit, crtc) 405626ab771SJakob Bornecrantz #define vmw_connector_to_du(x) \ 406626ab771SJakob Bornecrantz container_of(x, struct vmw_display_unit, connector) 407626ab771SJakob Bornecrantz 408626ab771SJakob Bornecrantz 409fb1d9738SJakob Bornecrantz /* 410fb1d9738SJakob Bornecrantz * Shared display unit functions - vmwgfx_kms.c 411fb1d9738SJakob Bornecrantz */ 412c8261a96SSinclair Yeh void vmw_du_cleanup(struct vmw_display_unit *du); 413626ab771SJakob Bornecrantz void vmw_du_crtc_save(struct drm_crtc *crtc); 414626ab771SJakob Bornecrantz void vmw_du_crtc_restore(struct drm_crtc *crtc); 4157ea77283SMaarten Lankhorst int vmw_du_crtc_gamma_set(struct drm_crtc *crtc, 416626ab771SJakob Bornecrantz u16 *r, u16 *g, u16 *b, 4176d124ff8SDaniel Vetter uint32_t size, 4186d124ff8SDaniel Vetter struct drm_modeset_acquire_ctx *ctx); 4199c2542a4SSinclair Yeh int vmw_du_connector_set_property(struct drm_connector *connector, 4209c2542a4SSinclair Yeh struct drm_property *property, 4219c2542a4SSinclair Yeh uint64_t val); 422d7721ca7SSinclair Yeh int vmw_du_connector_atomic_set_property(struct drm_connector *connector, 423d7721ca7SSinclair Yeh struct drm_connector_state *state, 424d7721ca7SSinclair Yeh struct drm_property *property, 425d7721ca7SSinclair Yeh uint64_t val); 426d7721ca7SSinclair Yeh int 427d7721ca7SSinclair Yeh vmw_du_connector_atomic_get_property(struct drm_connector *connector, 428d7721ca7SSinclair Yeh const struct drm_connector_state *state, 429d7721ca7SSinclair Yeh struct drm_property *property, 430d7721ca7SSinclair Yeh uint64_t *val); 4319a69a9acSMaarten Lankhorst int vmw_du_connector_dpms(struct drm_connector *connector, int mode); 432626ab771SJakob Bornecrantz void vmw_du_connector_save(struct drm_connector *connector); 433626ab771SJakob Bornecrantz void vmw_du_connector_restore(struct drm_connector *connector); 434626ab771SJakob Bornecrantz enum drm_connector_status 435626ab771SJakob Bornecrantz vmw_du_connector_detect(struct drm_connector *connector, bool force); 436626ab771SJakob Bornecrantz int vmw_du_connector_fill_modes(struct drm_connector *connector, 437626ab771SJakob Bornecrantz uint32_t max_width, uint32_t max_height); 4381a4b172aSThomas Hellstrom int vmw_kms_helper_dirty(struct vmw_private *dev_priv, 4391a4b172aSThomas Hellstrom struct vmw_framebuffer *framebuffer, 4401a4b172aSThomas Hellstrom const struct drm_clip_rect *clips, 4411a4b172aSThomas Hellstrom const struct drm_vmw_rect *vclips, 4421a4b172aSThomas Hellstrom s32 dest_x, s32 dest_y, 4431a4b172aSThomas Hellstrom int num_clips, 4441a4b172aSThomas Hellstrom int increment, 4451a4b172aSThomas Hellstrom struct vmw_kms_dirty *dirty); 446cd2b89e7SThomas Hellstrom 4472724b2d5SThomas Hellstrom void vmw_kms_helper_validation_finish(struct vmw_private *dev_priv, 4481a4b172aSThomas Hellstrom struct drm_file *file_priv, 4492724b2d5SThomas Hellstrom struct vmw_validation_context *ctx, 4501a4b172aSThomas Hellstrom struct vmw_fence_obj **out_fence, 4511a4b172aSThomas Hellstrom struct drm_vmw_fence_rep __user * 4521a4b172aSThomas Hellstrom user_fence_rep); 45310b1e0caSThomas Hellstrom int vmw_kms_readback(struct vmw_private *dev_priv, 45410b1e0caSThomas Hellstrom struct drm_file *file_priv, 45510b1e0caSThomas Hellstrom struct vmw_framebuffer *vfb, 45610b1e0caSThomas Hellstrom struct drm_vmw_fence_rep __user *user_fence_rep, 45710b1e0caSThomas Hellstrom struct drm_vmw_rect *vclips, 45810b1e0caSThomas Hellstrom uint32_t num_clips); 459fd006a43SThomas Hellstrom struct vmw_framebuffer * 460fd006a43SThomas Hellstrom vmw_kms_new_framebuffer(struct vmw_private *dev_priv, 461f1d34bfdSThomas Hellstrom struct vmw_buffer_object *bo, 462fd006a43SThomas Hellstrom struct vmw_surface *surface, 463fd006a43SThomas Hellstrom bool only_2d, 464dabdcdc9SDaniel Vetter const struct drm_mode_fb_cmd2 *mode_cmd); 465a278724aSThomas Hellstrom int vmw_kms_fbdev_init_data(struct vmw_private *dev_priv, 466a278724aSThomas Hellstrom unsigned unit, 467a278724aSThomas Hellstrom u32 max_width, 468a278724aSThomas Hellstrom u32 max_height, 469a278724aSThomas Hellstrom struct drm_connector **p_con, 470a278724aSThomas Hellstrom struct drm_crtc **p_crtc, 471a278724aSThomas Hellstrom struct drm_display_mode **p_mode); 472a278724aSThomas Hellstrom void vmw_guess_mode_timing(struct drm_display_mode *mode); 4739d9486e4SThomas Hellstrom void vmw_kms_update_implicit_fb(struct vmw_private *dev_priv); 4749d9486e4SThomas Hellstrom void vmw_kms_create_implicit_placement_property(struct vmw_private *dev_priv); 47575c06855SThomas Hellstrom 47636cc79bcSSinclair Yeh /* Universal Plane Helpers */ 47736cc79bcSSinclair Yeh void vmw_du_primary_plane_destroy(struct drm_plane *plane); 47836cc79bcSSinclair Yeh void vmw_du_cursor_plane_destroy(struct drm_plane *plane); 47936cc79bcSSinclair Yeh 48006ec4190SSinclair Yeh /* Atomic Helpers */ 481060e2ad5SSinclair Yeh int vmw_du_primary_plane_atomic_check(struct drm_plane *plane, 4827c11b99aSMaxime Ripard struct drm_atomic_state *state); 483060e2ad5SSinclair Yeh int vmw_du_cursor_plane_atomic_check(struct drm_plane *plane, 4847c11b99aSMaxime Ripard struct drm_atomic_state *state); 485060e2ad5SSinclair Yeh void vmw_du_cursor_plane_atomic_update(struct drm_plane *plane, 486977697e2SMaxime Ripard struct drm_atomic_state *state); 487060e2ad5SSinclair Yeh int vmw_du_cursor_plane_prepare_fb(struct drm_plane *plane, 488060e2ad5SSinclair Yeh struct drm_plane_state *new_state); 489485d98d4SMartin Krastev void vmw_du_cursor_plane_cleanup_fb(struct drm_plane *plane, 490485d98d4SMartin Krastev struct drm_plane_state *old_state); 491060e2ad5SSinclair Yeh void vmw_du_plane_cleanup_fb(struct drm_plane *plane, 492060e2ad5SSinclair Yeh struct drm_plane_state *old_state); 493cc5ec459SSinclair Yeh void vmw_du_plane_reset(struct drm_plane *plane); 494cc5ec459SSinclair Yeh struct drm_plane_state *vmw_du_plane_duplicate_state(struct drm_plane *plane); 495cc5ec459SSinclair Yeh void vmw_du_plane_destroy_state(struct drm_plane *plane, 496cc5ec459SSinclair Yeh struct drm_plane_state *state); 497060e2ad5SSinclair Yeh void vmw_du_plane_unpin_surf(struct vmw_plane_state *vps, 498060e2ad5SSinclair Yeh bool unreference); 499060e2ad5SSinclair Yeh 50006ec4190SSinclair Yeh int vmw_du_crtc_atomic_check(struct drm_crtc *crtc, 50129b77ad7SMaxime Ripard struct drm_atomic_state *state); 50206ec4190SSinclair Yeh void vmw_du_crtc_atomic_begin(struct drm_crtc *crtc, 503f6ebe9f9SMaxime Ripard struct drm_atomic_state *state); 50406ec4190SSinclair Yeh void vmw_du_crtc_atomic_flush(struct drm_crtc *crtc, 505f6ebe9f9SMaxime Ripard struct drm_atomic_state *state); 5069c2542a4SSinclair Yeh void vmw_du_crtc_reset(struct drm_crtc *crtc); 5079c2542a4SSinclair Yeh struct drm_crtc_state *vmw_du_crtc_duplicate_state(struct drm_crtc *crtc); 5089c2542a4SSinclair Yeh void vmw_du_crtc_destroy_state(struct drm_crtc *crtc, 5099c2542a4SSinclair Yeh struct drm_crtc_state *state); 510d7721ca7SSinclair Yeh void vmw_du_connector_reset(struct drm_connector *connector); 511d7721ca7SSinclair Yeh struct drm_connector_state * 512d7721ca7SSinclair Yeh vmw_du_connector_duplicate_state(struct drm_connector *connector); 513d7721ca7SSinclair Yeh 514d7721ca7SSinclair Yeh void vmw_du_connector_destroy_state(struct drm_connector *connector, 515d7721ca7SSinclair Yeh struct drm_connector_state *state); 516fb1d9738SJakob Bornecrantz 517fb1d9738SJakob Bornecrantz /* 518d8bd19d2SJakob Bornecrantz * Legacy display unit functions - vmwgfx_ldu.c 519fb1d9738SJakob Bornecrantz */ 520c8261a96SSinclair Yeh int vmw_kms_ldu_init_display(struct vmw_private *dev_priv); 521c8261a96SSinclair Yeh int vmw_kms_ldu_close_display(struct vmw_private *dev_priv); 522f1d34bfdSThomas Hellstrom int vmw_kms_ldu_do_bo_dirty(struct vmw_private *dev_priv, 523c8261a96SSinclair Yeh struct vmw_framebuffer *framebuffer, 524f1d34bfdSThomas Hellstrom unsigned int flags, unsigned int color, 525c8261a96SSinclair Yeh struct drm_clip_rect *clips, 526f1d34bfdSThomas Hellstrom unsigned int num_clips, int increment); 5276bf6bf03SThomas Hellstrom int vmw_kms_update_proxy(struct vmw_resource *res, 5286bf6bf03SThomas Hellstrom const struct drm_clip_rect *clips, 5296bf6bf03SThomas Hellstrom unsigned num_clips, 5306bf6bf03SThomas Hellstrom int increment); 531fb1d9738SJakob Bornecrantz 53256d1c78dSJakob Bornecrantz /* 53356d1c78dSJakob Bornecrantz * Screen Objects display functions - vmwgfx_scrn.c 53456d1c78dSJakob Bornecrantz */ 535c8261a96SSinclair Yeh int vmw_kms_sou_init_display(struct vmw_private *dev_priv); 536c8261a96SSinclair Yeh int vmw_kms_sou_do_surface_dirty(struct vmw_private *dev_priv, 537c8261a96SSinclair Yeh struct vmw_framebuffer *framebuffer, 538c8261a96SSinclair Yeh struct drm_clip_rect *clips, 53910b1e0caSThomas Hellstrom struct drm_vmw_rect *vclips, 54010b1e0caSThomas Hellstrom struct vmw_resource *srf, 54110b1e0caSThomas Hellstrom s32 dest_x, 54210b1e0caSThomas Hellstrom s32 dest_y, 543c8261a96SSinclair Yeh unsigned num_clips, int inc, 54491e9f352SDeepak Rawat struct vmw_fence_obj **out_fence, 54591e9f352SDeepak Rawat struct drm_crtc *crtc); 546f1d34bfdSThomas Hellstrom int vmw_kms_sou_do_bo_dirty(struct vmw_private *dev_priv, 547c8261a96SSinclair Yeh struct vmw_framebuffer *framebuffer, 548c8261a96SSinclair Yeh struct drm_clip_rect *clips, 549897b8180SThomas Hellstrom struct drm_vmw_rect *vclips, 550f1d34bfdSThomas Hellstrom unsigned int num_clips, int increment, 55110b1e0caSThomas Hellstrom bool interruptible, 55291e9f352SDeepak Rawat struct vmw_fence_obj **out_fence, 55391e9f352SDeepak Rawat struct drm_crtc *crtc); 55410b1e0caSThomas Hellstrom int vmw_kms_sou_readback(struct vmw_private *dev_priv, 55510b1e0caSThomas Hellstrom struct drm_file *file_priv, 55610b1e0caSThomas Hellstrom struct vmw_framebuffer *vfb, 55710b1e0caSThomas Hellstrom struct drm_vmw_fence_rep __user *user_fence_rep, 55810b1e0caSThomas Hellstrom struct drm_vmw_rect *vclips, 55991e9f352SDeepak Rawat uint32_t num_clips, 56091e9f352SDeepak Rawat struct drm_crtc *crtc); 56135c05125SSinclair Yeh 56235c05125SSinclair Yeh /* 56335c05125SSinclair Yeh * Screen Target Display Unit functions - vmwgfx_stdu.c 56435c05125SSinclair Yeh */ 56535c05125SSinclair Yeh int vmw_kms_stdu_init_display(struct vmw_private *dev_priv); 5666bf6bf03SThomas Hellstrom int vmw_kms_stdu_surface_dirty(struct vmw_private *dev_priv, 56735c05125SSinclair Yeh struct vmw_framebuffer *framebuffer, 56835c05125SSinclair Yeh struct drm_clip_rect *clips, 5696bf6bf03SThomas Hellstrom struct drm_vmw_rect *vclips, 5706bf6bf03SThomas Hellstrom struct vmw_resource *srf, 5716bf6bf03SThomas Hellstrom s32 dest_x, 5726bf6bf03SThomas Hellstrom s32 dest_y, 5736bf6bf03SThomas Hellstrom unsigned num_clips, int inc, 57491e9f352SDeepak Rawat struct vmw_fence_obj **out_fence, 57591e9f352SDeepak Rawat struct drm_crtc *crtc); 5766bf6bf03SThomas Hellstrom int vmw_kms_stdu_dma(struct vmw_private *dev_priv, 57735c05125SSinclair Yeh struct drm_file *file_priv, 57835c05125SSinclair Yeh struct vmw_framebuffer *vfb, 5796bf6bf03SThomas Hellstrom struct drm_vmw_fence_rep __user *user_fence_rep, 5806bf6bf03SThomas Hellstrom struct drm_clip_rect *clips, 5816bf6bf03SThomas Hellstrom struct drm_vmw_rect *vclips, 5826bf6bf03SThomas Hellstrom uint32_t num_clips, 5836bf6bf03SThomas Hellstrom int increment, 5846bf6bf03SThomas Hellstrom bool to_surface, 58591e9f352SDeepak Rawat bool interruptible, 58691e9f352SDeepak Rawat struct drm_crtc *crtc); 587b5ec427eSJakob Bornecrantz 588e41774c0SDeepak Rawat int vmw_du_helper_plane_update(struct vmw_du_update_plane *update); 589e41774c0SDeepak Rawat 590e41774c0SDeepak Rawat /** 591e41774c0SDeepak Rawat * vmw_du_translate_to_crtc - Translate a rect from framebuffer to crtc 592e41774c0SDeepak Rawat * @state: Plane state. 593e41774c0SDeepak Rawat * @r: Rectangle to translate. 594e41774c0SDeepak Rawat */ 595e41774c0SDeepak Rawat static inline void vmw_du_translate_to_crtc(struct drm_plane_state *state, 596e41774c0SDeepak Rawat struct drm_rect *r) 597e41774c0SDeepak Rawat { 598e41774c0SDeepak Rawat int translate_crtc_x = -((state->src_x >> 16) - state->crtc_x); 599e41774c0SDeepak Rawat int translate_crtc_y = -((state->src_y >> 16) - state->crtc_y); 600e41774c0SDeepak Rawat 601e41774c0SDeepak Rawat drm_rect_translate(r, translate_crtc_x, translate_crtc_y); 602e41774c0SDeepak Rawat } 603e41774c0SDeepak Rawat 604fb1d9738SJakob Bornecrantz #endif 605