]> git.karo-electronics.de Git - karo-tx-linux.git/blob - drivers/gpu/drm/vmwgfx/vmwgfx_kms.h
drm: Don't include <drm/drm_encoder.h> in <drm/drm_crtc.h>
[karo-tx-linux.git] / drivers / gpu / drm / vmwgfx / vmwgfx_kms.h
1 /**************************************************************************
2  *
3  * Copyright © 2009-2015 VMware, Inc., Palo Alto, CA., USA
4  * All Rights Reserved.
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/drmP.h>
32 #include <drm/drm_crtc_helper.h>
33 #include <drm/drm_encoder.h>
34 #include "vmwgfx_drv.h"
35
36 /**
37  * struct vmw_kms_dirty - closure structure for the vmw_kms_helper_dirty
38  * function.
39  *
40  * @fifo_commit: Callback that is called once for each display unit after
41  * all clip rects. This function must commit the fifo space reserved by the
42  * helper. Set up by the caller.
43  * @clip: Callback that is called for each cliprect on each display unit.
44  * Set up by the caller.
45  * @fifo_reserve_size: Fifo size that the helper should try to allocat for
46  * each display unit. Set up by the caller.
47  * @dev_priv: Pointer to the device private. Set up by the helper.
48  * @unit: The current display unit. Set up by the helper before a call to @clip.
49  * @cmd: The allocated fifo space. Set up by the helper before the first @clip
50  * call.
51  * @num_hits: Number of clip rect commands for this display unit.
52  * Cleared by the helper before the first @clip call. Updated by the @clip
53  * callback.
54  * @fb_x: Clip rect left side in framebuffer coordinates.
55  * @fb_y: Clip rect right side in framebuffer coordinates.
56  * @unit_x1: Clip rect left side in crtc coordinates.
57  * @unit_y1: Clip rect top side in crtc coordinates.
58  * @unit_x2: Clip rect right side in crtc coordinates.
59  * @unit_y2: Clip rect bottom side in crtc coordinates.
60  *
61  * The clip rect coordinates are updated by the helper for each @clip call.
62  * Note that this may be derived from if more info needs to be passed between
63  * helper caller and helper callbacks.
64  */
65 struct vmw_kms_dirty {
66         void (*fifo_commit)(struct vmw_kms_dirty *);
67         void (*clip)(struct vmw_kms_dirty *);
68         size_t fifo_reserve_size;
69         struct vmw_private *dev_priv;
70         struct vmw_display_unit *unit;
71         void *cmd;
72         u32 num_hits;
73         s32 fb_x;
74         s32 fb_y;
75         s32 unit_x1;
76         s32 unit_y1;
77         s32 unit_x2;
78         s32 unit_y2;
79 };
80
81 #define VMWGFX_NUM_DISPLAY_UNITS 8
82
83
84 #define vmw_framebuffer_to_vfb(x) \
85         container_of(x, struct vmw_framebuffer, base)
86 #define vmw_framebuffer_to_vfbs(x) \
87         container_of(x, struct vmw_framebuffer_surface, base.base)
88 #define vmw_framebuffer_to_vfbd(x) \
89         container_of(x, struct vmw_framebuffer_dmabuf, base.base)
90
91 /**
92  * Base class for framebuffers
93  *
94  * @pin is called the when ever a crtc uses this framebuffer
95  * @unpin is called
96  */
97 struct vmw_framebuffer {
98         struct drm_framebuffer base;
99         int (*pin)(struct vmw_framebuffer *fb);
100         int (*unpin)(struct vmw_framebuffer *fb);
101         bool dmabuf;
102         struct ttm_base_object *user_obj;
103         uint32_t user_handle;
104 };
105
106 /*
107  * Clip rectangle
108  */
109 struct vmw_clip_rect {
110         int x1, x2, y1, y2;
111 };
112
113 struct vmw_framebuffer_surface {
114         struct vmw_framebuffer base;
115         struct vmw_surface *surface;
116         struct vmw_dma_buffer *buffer;
117         struct list_head head;
118         bool is_dmabuf_proxy;  /* true if this is proxy surface for DMA buf */
119 };
120
121
122 struct vmw_framebuffer_dmabuf {
123         struct vmw_framebuffer base;
124         struct vmw_dma_buffer *buffer;
125 };
126
127
128 /*
129  * Basic cursor manipulation
130  */
131 int vmw_cursor_update_image(struct vmw_private *dev_priv,
132                             u32 *image, u32 width, u32 height,
133                             u32 hotspotX, u32 hotspotY);
134 int vmw_cursor_update_dmabuf(struct vmw_private *dev_priv,
135                              struct vmw_dma_buffer *dmabuf,
136                              u32 width, u32 height,
137                              u32 hotspotX, u32 hotspotY);
138 void vmw_cursor_update_position(struct vmw_private *dev_priv,
139                                 bool show, int x, int y);
140
141
142 /**
143  * Base class display unit.
144  *
145  * Since the SVGA hw doesn't have a concept of a crtc, encoder or connector
146  * so the display unit is all of them at the same time. This is true for both
147  * legacy multimon and screen objects.
148  */
149 struct vmw_display_unit {
150         struct drm_crtc crtc;
151         struct drm_encoder encoder;
152         struct drm_connector connector;
153
154         struct vmw_surface *cursor_surface;
155         struct vmw_dma_buffer *cursor_dmabuf;
156         size_t cursor_age;
157
158         int cursor_x;
159         int cursor_y;
160
161         int hotspot_x;
162         int hotspot_y;
163         s32 core_hotspot_x;
164         s32 core_hotspot_y;
165
166         unsigned unit;
167
168         /*
169          * Prefered mode tracking.
170          */
171         unsigned pref_width;
172         unsigned pref_height;
173         bool pref_active;
174         struct drm_display_mode *pref_mode;
175
176         /*
177          * Gui positioning
178          */
179         int gui_x;
180         int gui_y;
181         bool is_implicit;
182         bool active_implicit;
183         int set_gui_x;
184         int set_gui_y;
185 };
186
187 #define vmw_crtc_to_du(x) \
188         container_of(x, struct vmw_display_unit, crtc)
189 #define vmw_connector_to_du(x) \
190         container_of(x, struct vmw_display_unit, connector)
191
192
193 /*
194  * Shared display unit functions - vmwgfx_kms.c
195  */
196 void vmw_du_cleanup(struct vmw_display_unit *du);
197 void vmw_du_crtc_save(struct drm_crtc *crtc);
198 void vmw_du_crtc_restore(struct drm_crtc *crtc);
199 int vmw_du_crtc_gamma_set(struct drm_crtc *crtc,
200                            u16 *r, u16 *g, u16 *b,
201                            uint32_t size);
202 int vmw_du_crtc_cursor_set2(struct drm_crtc *crtc, struct drm_file *file_priv,
203                             uint32_t handle, uint32_t width, uint32_t height,
204                             int32_t hot_x, int32_t hot_y);
205 int vmw_du_crtc_cursor_move(struct drm_crtc *crtc, int x, int y);
206 int vmw_du_connector_dpms(struct drm_connector *connector, int mode);
207 void vmw_du_connector_save(struct drm_connector *connector);
208 void vmw_du_connector_restore(struct drm_connector *connector);
209 enum drm_connector_status
210 vmw_du_connector_detect(struct drm_connector *connector, bool force);
211 int vmw_du_connector_fill_modes(struct drm_connector *connector,
212                                 uint32_t max_width, uint32_t max_height);
213 int vmw_du_connector_set_property(struct drm_connector *connector,
214                                   struct drm_property *property,
215                                   uint64_t val);
216 int vmw_kms_helper_dirty(struct vmw_private *dev_priv,
217                          struct vmw_framebuffer *framebuffer,
218                          const struct drm_clip_rect *clips,
219                          const struct drm_vmw_rect *vclips,
220                          s32 dest_x, s32 dest_y,
221                          int num_clips,
222                          int increment,
223                          struct vmw_kms_dirty *dirty);
224
225 int vmw_kms_helper_buffer_prepare(struct vmw_private *dev_priv,
226                                   struct vmw_dma_buffer *buf,
227                                   bool interruptible,
228                                   bool validate_as_mob);
229 void vmw_kms_helper_buffer_revert(struct vmw_dma_buffer *buf);
230 void vmw_kms_helper_buffer_finish(struct vmw_private *dev_priv,
231                                   struct drm_file *file_priv,
232                                   struct vmw_dma_buffer *buf,
233                                   struct vmw_fence_obj **out_fence,
234                                   struct drm_vmw_fence_rep __user *
235                                   user_fence_rep);
236 int vmw_kms_helper_resource_prepare(struct vmw_resource *res,
237                                     bool interruptible);
238 void vmw_kms_helper_resource_revert(struct vmw_resource *res);
239 void vmw_kms_helper_resource_finish(struct vmw_resource *res,
240                                     struct vmw_fence_obj **out_fence);
241 int vmw_kms_readback(struct vmw_private *dev_priv,
242                      struct drm_file *file_priv,
243                      struct vmw_framebuffer *vfb,
244                      struct drm_vmw_fence_rep __user *user_fence_rep,
245                      struct drm_vmw_rect *vclips,
246                      uint32_t num_clips);
247 struct vmw_framebuffer *
248 vmw_kms_new_framebuffer(struct vmw_private *dev_priv,
249                         struct vmw_dma_buffer *dmabuf,
250                         struct vmw_surface *surface,
251                         bool only_2d,
252                         const struct drm_mode_fb_cmd2 *mode_cmd);
253 int vmw_kms_fbdev_init_data(struct vmw_private *dev_priv,
254                             unsigned unit,
255                             u32 max_width,
256                             u32 max_height,
257                             struct drm_connector **p_con,
258                             struct drm_crtc **p_crtc,
259                             struct drm_display_mode **p_mode);
260 void vmw_guess_mode_timing(struct drm_display_mode *mode);
261 void vmw_kms_del_active(struct vmw_private *dev_priv,
262                         struct vmw_display_unit *du);
263 void vmw_kms_add_active(struct vmw_private *dev_priv,
264                         struct vmw_display_unit *du,
265                         struct vmw_framebuffer *vfb);
266 bool vmw_kms_crtc_flippable(struct vmw_private *dev_priv,
267                             struct drm_crtc *crtc);
268 void vmw_kms_update_implicit_fb(struct vmw_private *dev_priv,
269                                 struct drm_crtc *crtc);
270 void vmw_kms_create_implicit_placement_property(struct vmw_private *dev_priv,
271                                                 bool immutable);
272
273
274 /*
275  * Legacy display unit functions - vmwgfx_ldu.c
276  */
277 int vmw_kms_ldu_init_display(struct vmw_private *dev_priv);
278 int vmw_kms_ldu_close_display(struct vmw_private *dev_priv);
279 int vmw_kms_ldu_do_dmabuf_dirty(struct vmw_private *dev_priv,
280                                 struct vmw_framebuffer *framebuffer,
281                                 unsigned flags, unsigned color,
282                                 struct drm_clip_rect *clips,
283                                 unsigned num_clips, int increment);
284 int vmw_kms_update_proxy(struct vmw_resource *res,
285                          const struct drm_clip_rect *clips,
286                          unsigned num_clips,
287                          int increment);
288
289 /*
290  * Screen Objects display functions - vmwgfx_scrn.c
291  */
292 int vmw_kms_sou_init_display(struct vmw_private *dev_priv);
293 int vmw_kms_sou_close_display(struct vmw_private *dev_priv);
294 int vmw_kms_sou_do_surface_dirty(struct vmw_private *dev_priv,
295                                  struct vmw_framebuffer *framebuffer,
296                                  struct drm_clip_rect *clips,
297                                  struct drm_vmw_rect *vclips,
298                                  struct vmw_resource *srf,
299                                  s32 dest_x,
300                                  s32 dest_y,
301                                  unsigned num_clips, int inc,
302                                  struct vmw_fence_obj **out_fence);
303 int vmw_kms_sou_do_dmabuf_dirty(struct vmw_private *dev_priv,
304                                 struct vmw_framebuffer *framebuffer,
305                                 struct drm_clip_rect *clips,
306                                 struct drm_vmw_rect *vclips,
307                                 unsigned num_clips, int increment,
308                                 bool interruptible,
309                                 struct vmw_fence_obj **out_fence);
310 int vmw_kms_sou_readback(struct vmw_private *dev_priv,
311                          struct drm_file *file_priv,
312                          struct vmw_framebuffer *vfb,
313                          struct drm_vmw_fence_rep __user *user_fence_rep,
314                          struct drm_vmw_rect *vclips,
315                          uint32_t num_clips);
316
317 /*
318  * Screen Target Display Unit functions - vmwgfx_stdu.c
319  */
320 int vmw_kms_stdu_init_display(struct vmw_private *dev_priv);
321 int vmw_kms_stdu_close_display(struct vmw_private *dev_priv);
322 int vmw_kms_stdu_surface_dirty(struct vmw_private *dev_priv,
323                                struct vmw_framebuffer *framebuffer,
324                                struct drm_clip_rect *clips,
325                                struct drm_vmw_rect *vclips,
326                                struct vmw_resource *srf,
327                                s32 dest_x,
328                                s32 dest_y,
329                                unsigned num_clips, int inc,
330                                struct vmw_fence_obj **out_fence);
331 int vmw_kms_stdu_dma(struct vmw_private *dev_priv,
332                      struct drm_file *file_priv,
333                      struct vmw_framebuffer *vfb,
334                      struct drm_vmw_fence_rep __user *user_fence_rep,
335                      struct drm_clip_rect *clips,
336                      struct drm_vmw_rect *vclips,
337                      uint32_t num_clips,
338                      int increment,
339                      bool to_surface,
340                      bool interruptible);
341
342
343 #endif