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