Home | History | Annotate | Line # | Download | only in vmwgfx
vmwgfx_kms.h revision 1.1.1.2.28.1
      1 /*	$NetBSD: vmwgfx_kms.h,v 1.1.1.2.28.1 2018/09/06 06:56:34 pgoyette Exp $	*/
      2 
      3 /**************************************************************************
      4  *
      5  * Copyright  2009-2015 VMware, Inc., Palo Alto, CA., USA
      6  * All Rights Reserved.
      7  *
      8  * Permission is hereby granted, free of charge, to any person obtaining a
      9  * copy of this software and associated documentation files (the
     10  * "Software"), to deal in the Software without restriction, including
     11  * without limitation the rights to use, copy, modify, merge, publish,
     12  * distribute, sub license, and/or sell copies of the Software, and to
     13  * permit persons to whom the Software is furnished to do so, subject to
     14  * the following conditions:
     15  *
     16  * The above copyright notice and this permission notice (including the
     17  * next paragraph) shall be included in all copies or substantial portions
     18  * of the Software.
     19  *
     20  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
     21  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
     22  * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
     23  * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
     24  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
     25  * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
     26  * USE OR OTHER DEALINGS IN THE SOFTWARE.
     27  *
     28  **************************************************************************/
     29 
     30 #ifndef VMWGFX_KMS_H_
     31 #define VMWGFX_KMS_H_
     32 
     33 #include <drm/drmP.h>
     34 #include <drm/drm_crtc_helper.h>
     35 #include "vmwgfx_drv.h"
     36 
     37 /**
     38  * struct vmw_kms_dirty - closure structure for the vmw_kms_helper_dirty
     39  * function.
     40  *
     41  * @fifo_commit: Callback that is called once for each display unit after
     42  * all clip rects. This function must commit the fifo space reserved by the
     43  * helper. Set up by the caller.
     44  * @clip: Callback that is called for each cliprect on each display unit.
     45  * Set up by the caller.
     46  * @fifo_reserve_size: Fifo size that the helper should try to allocat for
     47  * each display unit. Set up by the caller.
     48  * @dev_priv: Pointer to the device private. Set up by the helper.
     49  * @unit: The current display unit. Set up by the helper before a call to @clip.
     50  * @cmd: The allocated fifo space. Set up by the helper before the first @clip
     51  * call.
     52  * @num_hits: Number of clip rect commands for this display unit.
     53  * Cleared by the helper before the first @clip call. Updated by the @clip
     54  * callback.
     55  * @fb_x: Clip rect left side in framebuffer coordinates.
     56  * @fb_y: Clip rect right side in framebuffer coordinates.
     57  * @unit_x1: Clip rect left side in crtc coordinates.
     58  * @unit_y1: Clip rect top side in crtc coordinates.
     59  * @unit_x2: Clip rect right side in crtc coordinates.
     60  * @unit_y2: Clip rect bottom side in crtc coordinates.
     61  *
     62  * The clip rect coordinates are updated by the helper for each @clip call.
     63  * Note that this may be derived from if more info needs to be passed between
     64  * helper caller and helper callbacks.
     65  */
     66 struct vmw_kms_dirty {
     67 	void (*fifo_commit)(struct vmw_kms_dirty *);
     68 	void (*clip)(struct vmw_kms_dirty *);
     69 	size_t fifo_reserve_size;
     70 	struct vmw_private *dev_priv;
     71 	struct vmw_display_unit *unit;
     72 	void *cmd;
     73 	u32 num_hits;
     74 	s32 fb_x;
     75 	s32 fb_y;
     76 	s32 unit_x1;
     77 	s32 unit_y1;
     78 	s32 unit_x2;
     79 	s32 unit_y2;
     80 };
     81 
     82 #define VMWGFX_NUM_DISPLAY_UNITS 8
     83 
     84 
     85 #define vmw_framebuffer_to_vfb(x) \
     86 	container_of(x, struct vmw_framebuffer, base)
     87 #define vmw_framebuffer_to_vfbs(x) \
     88 	container_of(x, struct vmw_framebuffer_surface, base.base)
     89 #define vmw_framebuffer_to_vfbd(x) \
     90 	container_of(x, struct vmw_framebuffer_dmabuf, base.base)
     91 
     92 /**
     93  * Base class for framebuffers
     94  *
     95  * @pin is called the when ever a crtc uses this framebuffer
     96  * @unpin is called
     97  */
     98 struct vmw_framebuffer {
     99 	struct drm_framebuffer base;
    100 	int (*pin)(struct vmw_framebuffer *fb);
    101 	int (*unpin)(struct vmw_framebuffer *fb);
    102 	bool dmabuf;
    103 	struct ttm_base_object *user_obj;
    104 	uint32_t user_handle;
    105 };
    106 
    107 /*
    108  * Clip rectangle
    109  */
    110 struct vmw_clip_rect {
    111 	int x1, x2, y1, y2;
    112 };
    113 
    114 struct vmw_framebuffer_surface {
    115 	struct vmw_framebuffer base;
    116 	struct vmw_surface *surface;
    117 	struct vmw_dma_buffer *buffer;
    118 	struct list_head head;
    119 	bool is_dmabuf_proxy;  /* true if this is proxy surface for DMA buf */
    120 };
    121 
    122 
    123 struct vmw_framebuffer_dmabuf {
    124 	struct vmw_framebuffer base;
    125 	struct vmw_dma_buffer *buffer;
    126 };
    127 
    128 
    129 /*
    130  * Basic cursor manipulation
    131  */
    132 int vmw_cursor_update_image(struct vmw_private *dev_priv,
    133 			    u32 *image, u32 width, u32 height,
    134 			    u32 hotspotX, u32 hotspotY);
    135 int vmw_cursor_update_dmabuf(struct vmw_private *dev_priv,
    136 			     struct vmw_dma_buffer *dmabuf,
    137 			     u32 width, u32 height,
    138 			     u32 hotspotX, u32 hotspotY);
    139 void vmw_cursor_update_position(struct vmw_private *dev_priv,
    140 				bool show, int x, int y);
    141 
    142 
    143 /**
    144  * Base class display unit.
    145  *
    146  * Since the SVGA hw doesn't have a concept of a crtc, encoder or connector
    147  * so the display unit is all of them at the same time. This is true for both
    148  * legacy multimon and screen objects.
    149  */
    150 struct vmw_display_unit {
    151 	struct drm_crtc crtc;
    152 	struct drm_encoder encoder;
    153 	struct drm_connector connector;
    154 
    155 	struct vmw_surface *cursor_surface;
    156 	struct vmw_dma_buffer *cursor_dmabuf;
    157 	size_t cursor_age;
    158 
    159 	int cursor_x;
    160 	int cursor_y;
    161 
    162 	int hotspot_x;
    163 	int hotspot_y;
    164 	s32 core_hotspot_x;
    165 	s32 core_hotspot_y;
    166 
    167 	unsigned unit;
    168 
    169 	/*
    170 	 * Prefered mode tracking.
    171 	 */
    172 	unsigned pref_width;
    173 	unsigned pref_height;
    174 	bool pref_active;
    175 	struct drm_display_mode *pref_mode;
    176 
    177 	/*
    178 	 * Gui positioning
    179 	 */
    180 	int gui_x;
    181 	int gui_y;
    182 	bool is_implicit;
    183 };
    184 
    185 struct vmw_validation_ctx {
    186 	struct vmw_resource *res;
    187 	struct vmw_dma_buffer *buf;
    188 };
    189 
    190 #define vmw_crtc_to_du(x) \
    191 	container_of(x, struct vmw_display_unit, crtc)
    192 #define vmw_connector_to_du(x) \
    193 	container_of(x, struct vmw_display_unit, connector)
    194 
    195 
    196 /*
    197  * Shared display unit functions - vmwgfx_kms.c
    198  */
    199 void vmw_du_cleanup(struct vmw_display_unit *du);
    200 void vmw_du_crtc_save(struct drm_crtc *crtc);
    201 void vmw_du_crtc_restore(struct drm_crtc *crtc);
    202 void vmw_du_crtc_gamma_set(struct drm_crtc *crtc,
    203 			   u16 *r, u16 *g, u16 *b,
    204 			   uint32_t start, uint32_t size);
    205 int vmw_du_crtc_cursor_set2(struct drm_crtc *crtc, struct drm_file *file_priv,
    206 			    uint32_t handle, uint32_t width, uint32_t height,
    207 			    int32_t hot_x, int32_t hot_y);
    208 int vmw_du_crtc_cursor_move(struct drm_crtc *crtc, int x, int y);
    209 int vmw_du_connector_dpms(struct drm_connector *connector, int mode);
    210 void vmw_du_connector_save(struct drm_connector *connector);
    211 void vmw_du_connector_restore(struct drm_connector *connector);
    212 enum drm_connector_status
    213 vmw_du_connector_detect(struct drm_connector *connector, bool force);
    214 int vmw_du_connector_fill_modes(struct drm_connector *connector,
    215 				uint32_t max_width, uint32_t max_height);
    216 int vmw_du_connector_set_property(struct drm_connector *connector,
    217 				  struct drm_property *property,
    218 				  uint64_t val);
    219 int vmw_kms_helper_dirty(struct vmw_private *dev_priv,
    220 			 struct vmw_framebuffer *framebuffer,
    221 			 const struct drm_clip_rect *clips,
    222 			 const struct drm_vmw_rect *vclips,
    223 			 s32 dest_x, s32 dest_y,
    224 			 int num_clips,
    225 			 int increment,
    226 			 struct vmw_kms_dirty *dirty);
    227 
    228 int vmw_kms_helper_buffer_prepare(struct vmw_private *dev_priv,
    229 				  struct vmw_dma_buffer *buf,
    230 				  bool interruptible,
    231 				  bool validate_as_mob);
    232 void vmw_kms_helper_buffer_revert(struct vmw_dma_buffer *buf);
    233 void vmw_kms_helper_buffer_finish(struct vmw_private *dev_priv,
    234 				  struct drm_file *file_priv,
    235 				  struct vmw_dma_buffer *buf,
    236 				  struct vmw_fence_obj **out_fence,
    237 				  struct drm_vmw_fence_rep __user *
    238 				  user_fence_rep);
    239 int vmw_kms_helper_resource_prepare(struct vmw_resource *res,
    240 				    bool interruptible,
    241 				    struct vmw_validation_ctx *ctx);
    242 void vmw_kms_helper_resource_revert(struct vmw_validation_ctx *ctx);
    243 void vmw_kms_helper_resource_finish(struct vmw_validation_ctx *ctx,
    244 				    struct vmw_fence_obj **out_fence);
    245 int vmw_kms_readback(struct vmw_private *dev_priv,
    246 		     struct drm_file *file_priv,
    247 		     struct vmw_framebuffer *vfb,
    248 		     struct drm_vmw_fence_rep __user *user_fence_rep,
    249 		     struct drm_vmw_rect *vclips,
    250 		     uint32_t num_clips);
    251 struct vmw_framebuffer *
    252 vmw_kms_new_framebuffer(struct vmw_private *dev_priv,
    253 			struct vmw_dma_buffer *dmabuf,
    254 			struct vmw_surface *surface,
    255 			bool only_2d,
    256 			const struct drm_mode_fb_cmd *mode_cmd);
    257 int vmw_kms_fbdev_init_data(struct vmw_private *dev_priv,
    258 			    unsigned unit,
    259 			    u32 max_width,
    260 			    u32 max_height,
    261 			    struct drm_connector **p_con,
    262 			    struct drm_crtc **p_crtc,
    263 			    struct drm_display_mode **p_mode);
    264 void vmw_guess_mode_timing(struct drm_display_mode *mode);
    265 
    266 /*
    267  * Legacy display unit functions - vmwgfx_ldu.c
    268  */
    269 int vmw_kms_ldu_init_display(struct vmw_private *dev_priv);
    270 int vmw_kms_ldu_close_display(struct vmw_private *dev_priv);
    271 int vmw_kms_ldu_do_dmabuf_dirty(struct vmw_private *dev_priv,
    272 				struct vmw_framebuffer *framebuffer,
    273 				unsigned flags, unsigned color,
    274 				struct drm_clip_rect *clips,
    275 				unsigned num_clips, int increment);
    276 int vmw_kms_update_proxy(struct vmw_resource *res,
    277 			 const struct drm_clip_rect *clips,
    278 			 unsigned num_clips,
    279 			 int increment);
    280 
    281 /*
    282  * Screen Objects display functions - vmwgfx_scrn.c
    283  */
    284 int vmw_kms_sou_init_display(struct vmw_private *dev_priv);
    285 int vmw_kms_sou_close_display(struct vmw_private *dev_priv);
    286 int vmw_kms_sou_do_surface_dirty(struct vmw_private *dev_priv,
    287 				 struct vmw_framebuffer *framebuffer,
    288 				 struct drm_clip_rect *clips,
    289 				 struct drm_vmw_rect *vclips,
    290 				 struct vmw_resource *srf,
    291 				 s32 dest_x,
    292 				 s32 dest_y,
    293 				 unsigned num_clips, int inc,
    294 				 struct vmw_fence_obj **out_fence);
    295 int vmw_kms_sou_do_dmabuf_dirty(struct vmw_private *dev_priv,
    296 				struct vmw_framebuffer *framebuffer,
    297 				struct drm_clip_rect *clips,
    298 				unsigned num_clips, int increment,
    299 				bool interruptible,
    300 				struct vmw_fence_obj **out_fence);
    301 int vmw_kms_sou_readback(struct vmw_private *dev_priv,
    302 			 struct drm_file *file_priv,
    303 			 struct vmw_framebuffer *vfb,
    304 			 struct drm_vmw_fence_rep __user *user_fence_rep,
    305 			 struct drm_vmw_rect *vclips,
    306 			 uint32_t num_clips);
    307 
    308 /*
    309  * Screen Target Display Unit functions - vmwgfx_stdu.c
    310  */
    311 int vmw_kms_stdu_init_display(struct vmw_private *dev_priv);
    312 int vmw_kms_stdu_close_display(struct vmw_private *dev_priv);
    313 int vmw_kms_stdu_surface_dirty(struct vmw_private *dev_priv,
    314 			       struct vmw_framebuffer *framebuffer,
    315 			       struct drm_clip_rect *clips,
    316 			       struct drm_vmw_rect *vclips,
    317 			       struct vmw_resource *srf,
    318 			       s32 dest_x,
    319 			       s32 dest_y,
    320 			       unsigned num_clips, int inc,
    321 			       struct vmw_fence_obj **out_fence);
    322 int vmw_kms_stdu_dma(struct vmw_private *dev_priv,
    323 		     struct drm_file *file_priv,
    324 		     struct vmw_framebuffer *vfb,
    325 		     struct drm_vmw_fence_rep __user *user_fence_rep,
    326 		     struct drm_clip_rect *clips,
    327 		     struct drm_vmw_rect *vclips,
    328 		     uint32_t num_clips,
    329 		     int increment,
    330 		     bool to_surface,
    331 		     bool interruptible);
    332 
    333 
    334 #endif
    335