Commit | Line | Data |
---|---|---|
35c05125 SY |
1 | /****************************************************************************** |
2 | * | |
54fbde8a | 3 | * COPYRIGHT © 2014-2015 VMware, Inc., Palo Alto, CA., USA |
35c05125 SY |
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 | #include "vmwgfx_kms.h" | |
8ce75f8a | 29 | #include "device_include/svga3d_surfacedefs.h" |
35c05125 SY |
30 | #include <drm/drm_plane_helper.h> |
31 | ||
32 | #define vmw_crtc_to_stdu(x) \ | |
33 | container_of(x, struct vmw_screen_target_display_unit, base.crtc) | |
34 | #define vmw_encoder_to_stdu(x) \ | |
35 | container_of(x, struct vmw_screen_target_display_unit, base.encoder) | |
36 | #define vmw_connector_to_stdu(x) \ | |
37 | container_of(x, struct vmw_screen_target_display_unit, base.connector) | |
38 | ||
39 | ||
40 | ||
41 | enum stdu_content_type { | |
42 | SAME_AS_DISPLAY = 0, | |
43 | SEPARATE_SURFACE, | |
44 | SEPARATE_DMA | |
45 | }; | |
46 | ||
6bf6bf03 TH |
47 | /** |
48 | * struct vmw_stdu_dirty - closure structure for the update functions | |
49 | * | |
50 | * @base: The base type we derive from. Used by vmw_kms_helper_dirty(). | |
51 | * @transfer: Transfer direction for DMA command. | |
52 | * @left: Left side of bounding box. | |
53 | * @right: Right side of bounding box. | |
54 | * @top: Top side of bounding box. | |
55 | * @bottom: Bottom side of bounding box. | |
56 | * @buf: DMA buffer when DMA-ing between buffer and screen targets. | |
57 | * @sid: Surface ID when copying between surface and screen targets. | |
58 | */ | |
59 | struct vmw_stdu_dirty { | |
60 | struct vmw_kms_dirty base; | |
61 | SVGA3dTransferType transfer; | |
62 | s32 left, right, top, bottom; | |
63 | u32 pitch; | |
64 | union { | |
65 | struct vmw_dma_buffer *buf; | |
66 | u32 sid; | |
67 | }; | |
68 | }; | |
69 | ||
70 | /* | |
71 | * SVGA commands that are used by this code. Please see the device headers | |
72 | * for explanation. | |
73 | */ | |
74 | struct vmw_stdu_update { | |
75 | SVGA3dCmdHeader header; | |
76 | SVGA3dCmdUpdateGBScreenTarget body; | |
77 | }; | |
78 | ||
79 | struct vmw_stdu_dma { | |
80 | SVGA3dCmdHeader header; | |
81 | SVGA3dCmdSurfaceDMA body; | |
82 | }; | |
83 | ||
84 | struct vmw_stdu_surface_copy { | |
85 | SVGA3dCmdHeader header; | |
86 | SVGA3dCmdSurfaceCopy body; | |
87 | }; | |
35c05125 SY |
88 | |
89 | ||
90 | /** | |
91 | * struct vmw_screen_target_display_unit | |
92 | * | |
93 | * @base: VMW specific DU structure | |
94 | * @display_srf: surface to be displayed. The dimension of this will always | |
95 | * match the display mode. If the display mode matches | |
96 | * content_vfbs dimensions, then this is a pointer into the | |
97 | * corresponding field in content_vfbs. If not, then this | |
98 | * is a separate buffer to which content_vfbs will blit to. | |
35c05125 SY |
99 | * @content_type: content_fb type |
100 | * @defined: true if the current display unit has been initialized | |
101 | */ | |
102 | struct vmw_screen_target_display_unit { | |
103 | struct vmw_display_unit base; | |
104 | ||
105 | struct vmw_surface *display_srf; | |
35c05125 SY |
106 | enum stdu_content_type content_fb_type; |
107 | ||
108 | bool defined; | |
109 | }; | |
110 | ||
111 | ||
112 | ||
113 | static void vmw_stdu_destroy(struct vmw_screen_target_display_unit *stdu); | |
114 | ||
115 | ||
116 | ||
117 | /****************************************************************************** | |
118 | * Screen Target Display Unit helper Functions | |
119 | *****************************************************************************/ | |
120 | ||
35c05125 SY |
121 | /** |
122 | * vmw_stdu_unpin_display - unpins the resource associated with display surface | |
123 | * | |
124 | * @stdu: contains the display surface | |
125 | * | |
126 | * If the display surface was privatedly allocated by | |
127 | * vmw_surface_gb_priv_define() and not registered as a framebuffer, then it | |
128 | * won't be automatically cleaned up when all the framebuffers are freed. As | |
129 | * such, we have to explicitly call vmw_resource_unreference() to get it freed. | |
130 | */ | |
131 | static void vmw_stdu_unpin_display(struct vmw_screen_target_display_unit *stdu) | |
132 | { | |
133 | if (stdu->display_srf) { | |
134 | struct vmw_resource *res = &stdu->display_srf->res; | |
135 | ||
136 | vmw_resource_unpin(res); | |
b1097aeb | 137 | vmw_surface_unreference(&stdu->display_srf); |
35c05125 SY |
138 | } |
139 | } | |
140 | ||
141 | ||
142 | ||
143 | /****************************************************************************** | |
144 | * Screen Target Display Unit CRTC Functions | |
145 | *****************************************************************************/ | |
146 | ||
147 | ||
148 | /** | |
149 | * vmw_stdu_crtc_destroy - cleans up the STDU | |
150 | * | |
151 | * @crtc: used to get a reference to the containing STDU | |
152 | */ | |
153 | static void vmw_stdu_crtc_destroy(struct drm_crtc *crtc) | |
154 | { | |
155 | vmw_stdu_destroy(vmw_crtc_to_stdu(crtc)); | |
156 | } | |
157 | ||
35c05125 SY |
158 | /** |
159 | * vmw_stdu_define_st - Defines a Screen Target | |
160 | * | |
161 | * @dev_priv: VMW DRM device | |
162 | * @stdu: display unit to create a Screen Target for | |
b1097aeb TH |
163 | * @mode: The mode to set. |
164 | * @crtc_x: X coordinate of screen target relative to framebuffer origin. | |
165 | * @crtc_y: Y coordinate of screen target relative to framebuffer origin. | |
35c05125 SY |
166 | * |
167 | * Creates a STDU that we can used later. This function is called whenever the | |
168 | * framebuffer size changes. | |
169 | * | |
170 | * RETURNs: | |
171 | * 0 on success, error code on failure | |
172 | */ | |
173 | static int vmw_stdu_define_st(struct vmw_private *dev_priv, | |
b1097aeb TH |
174 | struct vmw_screen_target_display_unit *stdu, |
175 | struct drm_display_mode *mode, | |
176 | int crtc_x, int crtc_y) | |
35c05125 SY |
177 | { |
178 | struct { | |
179 | SVGA3dCmdHeader header; | |
180 | SVGA3dCmdDefineGBScreenTarget body; | |
181 | } *cmd; | |
182 | ||
183 | cmd = vmw_fifo_reserve(dev_priv, sizeof(*cmd)); | |
184 | ||
185 | if (unlikely(cmd == NULL)) { | |
186 | DRM_ERROR("Out of FIFO space defining Screen Target\n"); | |
187 | return -ENOMEM; | |
188 | } | |
189 | ||
190 | cmd->header.id = SVGA_3D_CMD_DEFINE_GB_SCREENTARGET; | |
191 | cmd->header.size = sizeof(cmd->body); | |
192 | ||
193 | cmd->body.stid = stdu->base.unit; | |
b1097aeb TH |
194 | cmd->body.width = mode->hdisplay; |
195 | cmd->body.height = mode->vdisplay; | |
35c05125 SY |
196 | cmd->body.flags = (0 == cmd->body.stid) ? SVGA_STFLAG_PRIMARY : 0; |
197 | cmd->body.dpi = 0; | |
b1097aeb TH |
198 | if (stdu->base.is_implicit) { |
199 | cmd->body.xRoot = crtc_x; | |
200 | cmd->body.yRoot = crtc_y; | |
201 | } else { | |
35c05125 SY |
202 | cmd->body.xRoot = stdu->base.gui_x; |
203 | cmd->body.yRoot = stdu->base.gui_y; | |
204 | } | |
205 | ||
206 | vmw_fifo_commit(dev_priv, sizeof(*cmd)); | |
207 | ||
208 | stdu->defined = true; | |
209 | ||
210 | return 0; | |
211 | } | |
212 | ||
213 | ||
214 | ||
215 | /** | |
216 | * vmw_stdu_bind_st - Binds a surface to a Screen Target | |
217 | * | |
218 | * @dev_priv: VMW DRM device | |
219 | * @stdu: display unit affected | |
220 | * @res: Buffer to bind to the screen target. Set to NULL to blank screen. | |
221 | * | |
222 | * Binding a surface to a Screen Target the same as flipping | |
223 | */ | |
224 | static int vmw_stdu_bind_st(struct vmw_private *dev_priv, | |
225 | struct vmw_screen_target_display_unit *stdu, | |
226 | struct vmw_resource *res) | |
227 | { | |
228 | SVGA3dSurfaceImageId image; | |
229 | ||
230 | struct { | |
231 | SVGA3dCmdHeader header; | |
232 | SVGA3dCmdBindGBScreenTarget body; | |
233 | } *cmd; | |
234 | ||
235 | ||
236 | if (!stdu->defined) { | |
237 | DRM_ERROR("No screen target defined\n"); | |
238 | return -EINVAL; | |
239 | } | |
240 | ||
241 | /* Set up image using information in vfb */ | |
242 | memset(&image, 0, sizeof(image)); | |
243 | image.sid = res ? res->id : SVGA3D_INVALID_ID; | |
244 | ||
245 | cmd = vmw_fifo_reserve(dev_priv, sizeof(*cmd)); | |
246 | ||
247 | if (unlikely(cmd == NULL)) { | |
248 | DRM_ERROR("Out of FIFO space binding a screen target\n"); | |
249 | return -ENOMEM; | |
250 | } | |
251 | ||
252 | cmd->header.id = SVGA_3D_CMD_BIND_GB_SCREENTARGET; | |
253 | cmd->header.size = sizeof(cmd->body); | |
254 | ||
255 | cmd->body.stid = stdu->base.unit; | |
256 | cmd->body.image = image; | |
257 | ||
258 | vmw_fifo_commit(dev_priv, sizeof(*cmd)); | |
259 | ||
260 | return 0; | |
261 | } | |
262 | ||
6bf6bf03 TH |
263 | /** |
264 | * vmw_stdu_populate_update - populate an UPDATE_GB_SCREENTARGET command with a | |
265 | * bounding box. | |
266 | * | |
267 | * @cmd: Pointer to command stream. | |
268 | * @unit: Screen target unit. | |
269 | * @left: Left side of bounding box. | |
270 | * @right: Right side of bounding box. | |
271 | * @top: Top side of bounding box. | |
272 | * @bottom: Bottom side of bounding box. | |
273 | */ | |
274 | static void vmw_stdu_populate_update(void *cmd, int unit, | |
275 | s32 left, s32 right, s32 top, s32 bottom) | |
276 | { | |
277 | struct vmw_stdu_update *update = cmd; | |
278 | ||
279 | update->header.id = SVGA_3D_CMD_UPDATE_GB_SCREENTARGET; | |
280 | update->header.size = sizeof(update->body); | |
35c05125 | 281 | |
6bf6bf03 TH |
282 | update->body.stid = unit; |
283 | update->body.rect.x = left; | |
284 | update->body.rect.y = top; | |
285 | update->body.rect.w = right - left; | |
286 | update->body.rect.h = bottom - top; | |
287 | } | |
35c05125 SY |
288 | |
289 | /** | |
6bf6bf03 | 290 | * vmw_stdu_update_st - Full update of a Screen Target |
35c05125 SY |
291 | * |
292 | * @dev_priv: VMW DRM device | |
35c05125 | 293 | * @stdu: display unit affected |
35c05125 SY |
294 | * |
295 | * This function needs to be called whenever the content of a screen | |
6bf6bf03 TH |
296 | * target has changed completely. Typically as a result of a backing |
297 | * surface change. | |
35c05125 SY |
298 | * |
299 | * RETURNS: | |
300 | * 0 on success, error code on failure | |
301 | */ | |
302 | static int vmw_stdu_update_st(struct vmw_private *dev_priv, | |
6bf6bf03 | 303 | struct vmw_screen_target_display_unit *stdu) |
35c05125 | 304 | { |
6bf6bf03 TH |
305 | struct vmw_stdu_update *cmd; |
306 | struct drm_crtc *crtc = &stdu->base.crtc; | |
35c05125 SY |
307 | |
308 | if (!stdu->defined) { | |
309 | DRM_ERROR("No screen target defined"); | |
310 | return -EINVAL; | |
311 | } | |
312 | ||
35c05125 SY |
313 | cmd = vmw_fifo_reserve(dev_priv, sizeof(*cmd)); |
314 | ||
315 | if (unlikely(cmd == NULL)) { | |
316 | DRM_ERROR("Out of FIFO space updating a Screen Target\n"); | |
317 | return -ENOMEM; | |
318 | } | |
319 | ||
6bf6bf03 TH |
320 | vmw_stdu_populate_update(cmd, stdu->base.unit, 0, crtc->mode.hdisplay, |
321 | 0, crtc->mode.vdisplay); | |
35c05125 SY |
322 | |
323 | vmw_fifo_commit(dev_priv, sizeof(*cmd)); | |
324 | ||
325 | return 0; | |
326 | } | |
327 | ||
328 | ||
329 | ||
330 | /** | |
331 | * vmw_stdu_destroy_st - Destroy a Screen Target | |
332 | * | |
333 | * @dev_priv: VMW DRM device | |
334 | * @stdu: display unit to destroy | |
335 | */ | |
336 | static int vmw_stdu_destroy_st(struct vmw_private *dev_priv, | |
337 | struct vmw_screen_target_display_unit *stdu) | |
338 | { | |
339 | int ret; | |
340 | ||
341 | struct { | |
342 | SVGA3dCmdHeader header; | |
343 | SVGA3dCmdDestroyGBScreenTarget body; | |
344 | } *cmd; | |
345 | ||
346 | ||
347 | /* Nothing to do if not successfully defined */ | |
348 | if (unlikely(!stdu->defined)) | |
349 | return 0; | |
350 | ||
351 | cmd = vmw_fifo_reserve(dev_priv, sizeof(*cmd)); | |
352 | ||
353 | if (unlikely(cmd == NULL)) { | |
354 | DRM_ERROR("Out of FIFO space, screen target not destroyed\n"); | |
355 | return -ENOMEM; | |
356 | } | |
357 | ||
358 | cmd->header.id = SVGA_3D_CMD_DESTROY_GB_SCREENTARGET; | |
359 | cmd->header.size = sizeof(cmd->body); | |
360 | ||
361 | cmd->body.stid = stdu->base.unit; | |
362 | ||
363 | vmw_fifo_commit(dev_priv, sizeof(*cmd)); | |
364 | ||
365 | /* Force sync */ | |
366 | ret = vmw_fallback_wait(dev_priv, false, true, 0, false, 3*HZ); | |
367 | if (unlikely(ret != 0)) | |
368 | DRM_ERROR("Failed to sync with HW"); | |
369 | ||
370 | stdu->defined = false; | |
371 | ||
372 | return ret; | |
373 | } | |
374 | ||
35c05125 | 375 | /** |
b1097aeb | 376 | * vmw_stdu_bind_fb - Bind an fb to a defined screen target |
35c05125 | 377 | * |
b1097aeb TH |
378 | * @dev_priv: Pointer to a device private struct. |
379 | * @crtc: The crtc holding the screen target. | |
380 | * @mode: The mode currently used by the screen target. Must be non-NULL. | |
381 | * @new_fb: The new framebuffer to bind. Must be non-NULL. | |
35c05125 SY |
382 | * |
383 | * RETURNS: | |
b1097aeb | 384 | * 0 on success, error code on failure. |
35c05125 | 385 | */ |
b1097aeb TH |
386 | static int vmw_stdu_bind_fb(struct vmw_private *dev_priv, |
387 | struct drm_crtc *crtc, | |
388 | struct drm_display_mode *mode, | |
389 | struct drm_framebuffer *new_fb) | |
35c05125 | 390 | { |
b1097aeb TH |
391 | struct vmw_screen_target_display_unit *stdu = vmw_crtc_to_stdu(crtc); |
392 | struct vmw_framebuffer *vfb = vmw_framebuffer_to_vfb(new_fb); | |
393 | struct vmw_surface *new_display_srf = NULL; | |
394 | enum stdu_content_type new_content_type; | |
35c05125 | 395 | struct vmw_framebuffer_surface *new_vfbs; |
b1097aeb | 396 | int ret; |
35c05125 | 397 | |
b1097aeb | 398 | WARN_ON_ONCE(!stdu->defined); |
35c05125 | 399 | |
b1097aeb TH |
400 | if (!vfb->dmabuf && new_fb->width == mode->hdisplay && |
401 | new_fb->height == mode->vdisplay) | |
402 | new_content_type = SAME_AS_DISPLAY; | |
403 | else if (vfb->dmabuf) | |
404 | new_content_type = SEPARATE_DMA; | |
405 | else | |
406 | new_content_type = SEPARATE_SURFACE; | |
35c05125 | 407 | |
b1097aeb TH |
408 | if (new_content_type != SAME_AS_DISPLAY && |
409 | !stdu->display_srf) { | |
35c05125 SY |
410 | struct vmw_surface content_srf; |
411 | struct drm_vmw_size display_base_size = {0}; | |
35c05125 SY |
412 | |
413 | display_base_size.width = mode->hdisplay; | |
414 | display_base_size.height = mode->vdisplay; | |
415 | display_base_size.depth = 1; | |
416 | ||
417 | /* | |
418 | * If content buffer is a DMA buf, then we have to construct | |
419 | * surface info | |
420 | */ | |
b1097aeb | 421 | if (new_content_type == SEPARATE_DMA) { |
35c05125 SY |
422 | |
423 | switch (new_fb->bits_per_pixel) { | |
424 | case 32: | |
425 | content_srf.format = SVGA3D_X8R8G8B8; | |
426 | break; | |
427 | ||
428 | case 16: | |
429 | content_srf.format = SVGA3D_R5G6B5; | |
430 | break; | |
431 | ||
432 | case 8: | |
433 | content_srf.format = SVGA3D_P8; | |
434 | break; | |
435 | ||
436 | default: | |
437 | DRM_ERROR("Invalid format\n"); | |
b1097aeb | 438 | return -EINVAL; |
35c05125 SY |
439 | } |
440 | ||
441 | content_srf.flags = 0; | |
442 | content_srf.mip_levels[0] = 1; | |
443 | content_srf.multisample_count = 0; | |
444 | } else { | |
35c05125 SY |
445 | new_vfbs = vmw_framebuffer_to_vfbs(new_fb); |
446 | content_srf = *new_vfbs->surface; | |
447 | } | |
448 | ||
449 | ||
450 | ret = vmw_surface_gb_priv_define(crtc->dev, | |
451 | 0, /* because kernel visible only */ | |
452 | content_srf.flags, | |
453 | content_srf.format, | |
454 | true, /* a scanout buffer */ | |
455 | content_srf.mip_levels[0], | |
456 | content_srf.multisample_count, | |
d80efd5c | 457 | 0, |
35c05125 | 458 | display_base_size, |
b1097aeb | 459 | &new_display_srf); |
35c05125 | 460 | if (unlikely(ret != 0)) { |
b1097aeb TH |
461 | DRM_ERROR("Could not allocate screen target surface.\n"); |
462 | return ret; | |
35c05125 | 463 | } |
b1097aeb | 464 | } else if (new_content_type == SAME_AS_DISPLAY) { |
35c05125 | 465 | new_vfbs = vmw_framebuffer_to_vfbs(new_fb); |
b1097aeb | 466 | new_display_srf = vmw_surface_reference(new_vfbs->surface); |
35c05125 SY |
467 | } |
468 | ||
b1097aeb TH |
469 | if (new_display_srf) { |
470 | /* Pin new surface before flipping */ | |
471 | ret = vmw_resource_pin(&new_display_srf->res, false); | |
472 | if (ret) | |
473 | goto out_srf_unref; | |
474 | ||
475 | ret = vmw_stdu_bind_st(dev_priv, stdu, &new_display_srf->res); | |
476 | if (ret) | |
477 | goto out_srf_unpin; | |
478 | ||
479 | /* Unpin and unreference old surface */ | |
480 | vmw_stdu_unpin_display(stdu); | |
35c05125 | 481 | |
b1097aeb TH |
482 | /* Transfer the reference */ |
483 | stdu->display_srf = new_display_srf; | |
484 | new_display_srf = NULL; | |
35c05125 SY |
485 | } |
486 | ||
b1097aeb TH |
487 | crtc->primary->fb = new_fb; |
488 | stdu->content_fb_type = new_content_type; | |
489 | return 0; | |
490 | ||
491 | out_srf_unpin: | |
492 | vmw_resource_unpin(&new_display_srf->res); | |
493 | out_srf_unref: | |
494 | vmw_surface_unreference(&new_display_srf); | |
495 | return ret; | |
496 | } | |
497 | ||
498 | /** | |
499 | * vmw_stdu_crtc_set_config - Sets a mode | |
500 | * | |
501 | * @set: mode parameters | |
502 | * | |
503 | * This function is the device-specific portion of the DRM CRTC mode set. | |
504 | * For the SVGA device, we do this by defining a Screen Target, binding a | |
505 | * GB Surface to that target, and finally update the screen target. | |
506 | * | |
507 | * RETURNS: | |
508 | * 0 on success, error code otherwise | |
509 | */ | |
510 | static int vmw_stdu_crtc_set_config(struct drm_mode_set *set) | |
511 | { | |
512 | struct vmw_private *dev_priv; | |
4d492a07 | 513 | struct vmw_framebuffer *vfb; |
b1097aeb TH |
514 | struct vmw_screen_target_display_unit *stdu; |
515 | struct drm_display_mode *mode; | |
516 | struct drm_framebuffer *new_fb; | |
517 | struct drm_crtc *crtc; | |
518 | struct drm_encoder *encoder; | |
519 | struct drm_connector *connector; | |
520 | bool turning_off; | |
521 | int ret; | |
522 | ||
523 | ||
524 | if (!set || !set->crtc) | |
525 | return -EINVAL; | |
526 | ||
527 | crtc = set->crtc; | |
528 | stdu = vmw_crtc_to_stdu(crtc); | |
529 | mode = set->mode; | |
530 | new_fb = set->fb; | |
531 | dev_priv = vmw_priv(crtc->dev); | |
532 | turning_off = set->num_connectors == 0 || !mode || !new_fb; | |
4d492a07 | 533 | vfb = (new_fb) ? vmw_framebuffer_to_vfb(new_fb) : NULL; |
b1097aeb TH |
534 | |
535 | if (set->num_connectors > 1) { | |
536 | DRM_ERROR("Too many connectors\n"); | |
537 | return -EINVAL; | |
538 | } | |
539 | ||
540 | if (set->num_connectors == 1 && | |
541 | set->connectors[0] != &stdu->base.connector) { | |
542 | DRM_ERROR("Connectors don't match %p %p\n", | |
543 | set->connectors[0], &stdu->base.connector); | |
544 | return -EINVAL; | |
545 | } | |
546 | ||
547 | if (!turning_off && (set->x + mode->hdisplay > new_fb->width || | |
548 | set->y + mode->vdisplay > new_fb->height)) { | |
549 | DRM_ERROR("Set outside of framebuffer\n"); | |
550 | return -EINVAL; | |
551 | } | |
552 | ||
4d492a07 TH |
553 | /* Only one active implicit frame-buffer at a time. */ |
554 | if (!turning_off && stdu->base.is_implicit && dev_priv->implicit_fb && | |
555 | !(dev_priv->num_implicit == 1 && stdu->base.active_implicit) | |
556 | && dev_priv->implicit_fb != vfb) { | |
557 | DRM_ERROR("Multiple implicit framebuffers not supported.\n"); | |
558 | return -EINVAL; | |
559 | } | |
560 | ||
b1097aeb TH |
561 | /* Since they always map one to one these are safe */ |
562 | connector = &stdu->base.connector; | |
563 | encoder = &stdu->base.encoder; | |
564 | ||
565 | if (stdu->defined) { | |
566 | ret = vmw_stdu_bind_st(dev_priv, stdu, NULL); | |
567 | if (ret) | |
568 | return ret; | |
569 | ||
570 | vmw_stdu_unpin_display(stdu); | |
571 | (void) vmw_stdu_update_st(dev_priv, stdu); | |
4d492a07 | 572 | vmw_kms_del_active(dev_priv, &stdu->base); |
b1097aeb TH |
573 | |
574 | ret = vmw_stdu_destroy_st(dev_priv, stdu); | |
575 | if (ret) | |
576 | return ret; | |
577 | ||
578 | crtc->primary->fb = NULL; | |
579 | crtc->enabled = false; | |
580 | encoder->crtc = NULL; | |
581 | connector->encoder = NULL; | |
582 | stdu->content_fb_type = SAME_AS_DISPLAY; | |
583 | crtc->x = set->x; | |
584 | crtc->y = set->y; | |
585 | } | |
586 | ||
587 | if (turning_off) | |
588 | return 0; | |
35c05125 SY |
589 | |
590 | /* | |
591 | * Steps to displaying a surface, assume surface is already | |
592 | * bound: | |
593 | * 1. define a screen target | |
594 | * 2. bind a fb to the screen target | |
595 | * 3. update that screen target (this is done later by | |
596 | * vmw_kms_stdu_do_surface_dirty_or_present) | |
597 | */ | |
b1097aeb TH |
598 | /* |
599 | * Note on error handling: We can't really restore the crtc to | |
600 | * it's original state on error, but we at least update the | |
601 | * current state to what's submitted to hardware to enable | |
602 | * future recovery. | |
603 | */ | |
604 | vmw_svga_enable(dev_priv); | |
605 | ret = vmw_stdu_define_st(dev_priv, stdu, mode, set->x, set->y); | |
606 | if (ret) | |
607 | return ret; | |
35c05125 | 608 | |
b1097aeb TH |
609 | crtc->x = set->x; |
610 | crtc->y = set->y; | |
611 | crtc->mode = *mode; | |
35c05125 | 612 | |
b1097aeb TH |
613 | ret = vmw_stdu_bind_fb(dev_priv, crtc, mode, new_fb); |
614 | if (ret) | |
615 | return ret; | |
35c05125 | 616 | |
4d492a07 | 617 | vmw_kms_add_active(dev_priv, &stdu->base, vfb); |
b1097aeb | 618 | crtc->enabled = true; |
35c05125 SY |
619 | connector->encoder = encoder; |
620 | encoder->crtc = crtc; | |
621 | ||
b1097aeb | 622 | return 0; |
35c05125 SY |
623 | } |
624 | ||
35c05125 SY |
625 | /** |
626 | * vmw_stdu_crtc_page_flip - Binds a buffer to a screen target | |
627 | * | |
628 | * @crtc: CRTC to attach FB to | |
629 | * @fb: FB to attach | |
630 | * @event: Event to be posted. This event should've been alloced | |
631 | * using k[mz]alloc, and should've been completely initialized. | |
632 | * @page_flip_flags: Input flags. | |
633 | * | |
634 | * If the STDU uses the same display and content buffers, i.e. a true flip, | |
635 | * this function will replace the existing display buffer with the new content | |
636 | * buffer. | |
637 | * | |
638 | * If the STDU uses different display and content buffers, i.e. a blit, then | |
639 | * only the content buffer will be updated. | |
640 | * | |
641 | * RETURNS: | |
642 | * 0 on success, error code on failure | |
643 | */ | |
644 | static int vmw_stdu_crtc_page_flip(struct drm_crtc *crtc, | |
645 | struct drm_framebuffer *new_fb, | |
646 | struct drm_pending_vblank_event *event, | |
647 | uint32_t flags) | |
648 | ||
649 | { | |
650 | struct vmw_private *dev_priv = vmw_priv(crtc->dev); | |
651 | struct vmw_screen_target_display_unit *stdu; | |
b1097aeb TH |
652 | struct drm_vmw_rect vclips; |
653 | struct vmw_framebuffer *vfb = vmw_framebuffer_to_vfb(new_fb); | |
35c05125 SY |
654 | int ret; |
655 | ||
35c05125 SY |
656 | dev_priv = vmw_priv(crtc->dev); |
657 | stdu = vmw_crtc_to_stdu(crtc); | |
35c05125 | 658 | |
4d492a07 | 659 | if (!stdu->defined || !vmw_kms_crtc_flippable(dev_priv, crtc)) |
b1097aeb | 660 | return -EINVAL; |
35c05125 | 661 | |
b1097aeb TH |
662 | ret = vmw_stdu_bind_fb(dev_priv, crtc, &crtc->mode, new_fb); |
663 | if (ret) | |
664 | return ret; | |
35c05125 | 665 | |
4d492a07 TH |
666 | if (stdu->base.is_implicit) |
667 | vmw_kms_update_implicit_fb(dev_priv, crtc); | |
668 | ||
b1097aeb TH |
669 | vclips.x = crtc->x; |
670 | vclips.y = crtc->y; | |
671 | vclips.w = crtc->mode.hdisplay; | |
672 | vclips.h = crtc->mode.vdisplay; | |
673 | if (vfb->dmabuf) | |
674 | ret = vmw_kms_stdu_dma(dev_priv, NULL, vfb, NULL, NULL, &vclips, | |
675 | 1, 1, true, false); | |
676 | else | |
677 | ret = vmw_kms_stdu_surface_dirty(dev_priv, vfb, NULL, &vclips, | |
678 | NULL, 0, 0, 1, 1, NULL); | |
679 | if (ret) | |
35c05125 SY |
680 | return ret; |
681 | ||
682 | if (event) { | |
683 | struct vmw_fence_obj *fence = NULL; | |
6bf6bf03 | 684 | struct drm_file *file_priv = event->base.file_priv; |
35c05125 SY |
685 | |
686 | vmw_execbuf_fence_commands(NULL, dev_priv, &fence, NULL); | |
687 | if (!fence) | |
688 | return -ENOMEM; | |
689 | ||
690 | ret = vmw_event_fence_action_queue(file_priv, fence, | |
691 | &event->base, | |
692 | &event->event.tv_sec, | |
693 | &event->event.tv_usec, | |
694 | true); | |
695 | vmw_fence_obj_unreference(&fence); | |
4e0858a6 TH |
696 | } else { |
697 | vmw_fifo_flush(dev_priv, false); | |
35c05125 SY |
698 | } |
699 | ||
b1097aeb | 700 | return 0; |
35c05125 SY |
701 | } |
702 | ||
703 | ||
6bf6bf03 TH |
704 | /** |
705 | * vmw_stdu_dmabuf_clip - Callback to encode a suface DMA command cliprect | |
706 | * | |
707 | * @dirty: The closure structure. | |
708 | * | |
709 | * Encodes a surface DMA command cliprect and updates the bounding box | |
710 | * for the DMA. | |
711 | */ | |
712 | static void vmw_stdu_dmabuf_clip(struct vmw_kms_dirty *dirty) | |
713 | { | |
714 | struct vmw_stdu_dirty *ddirty = | |
715 | container_of(dirty, struct vmw_stdu_dirty, base); | |
716 | struct vmw_stdu_dma *cmd = dirty->cmd; | |
717 | struct SVGA3dCopyBox *blit = (struct SVGA3dCopyBox *) &cmd[1]; | |
718 | ||
719 | blit += dirty->num_hits; | |
720 | blit->srcx = dirty->fb_x; | |
721 | blit->srcy = dirty->fb_y; | |
722 | blit->x = dirty->unit_x1; | |
723 | blit->y = dirty->unit_y1; | |
724 | blit->d = 1; | |
725 | blit->w = dirty->unit_x2 - dirty->unit_x1; | |
726 | blit->h = dirty->unit_y2 - dirty->unit_y1; | |
727 | dirty->num_hits++; | |
728 | ||
729 | if (ddirty->transfer != SVGA3D_WRITE_HOST_VRAM) | |
730 | return; | |
731 | ||
732 | /* Destination bounding box */ | |
733 | ddirty->left = min_t(s32, ddirty->left, dirty->unit_x1); | |
734 | ddirty->top = min_t(s32, ddirty->top, dirty->unit_y1); | |
735 | ddirty->right = max_t(s32, ddirty->right, dirty->unit_x2); | |
736 | ddirty->bottom = max_t(s32, ddirty->bottom, dirty->unit_y2); | |
737 | } | |
738 | ||
739 | /** | |
740 | * vmw_stdu_dmabuf_fifo_commit - Callback to fill in and submit a DMA command. | |
741 | * | |
742 | * @dirty: The closure structure. | |
743 | * | |
744 | * Fills in the missing fields in a DMA command, and optionally encodes | |
745 | * a screen target update command, depending on transfer direction. | |
746 | */ | |
747 | static void vmw_stdu_dmabuf_fifo_commit(struct vmw_kms_dirty *dirty) | |
748 | { | |
749 | struct vmw_stdu_dirty *ddirty = | |
750 | container_of(dirty, struct vmw_stdu_dirty, base); | |
751 | struct vmw_screen_target_display_unit *stdu = | |
752 | container_of(dirty->unit, typeof(*stdu), base); | |
753 | struct vmw_stdu_dma *cmd = dirty->cmd; | |
754 | struct SVGA3dCopyBox *blit = (struct SVGA3dCopyBox *) &cmd[1]; | |
755 | SVGA3dCmdSurfaceDMASuffix *suffix = | |
756 | (SVGA3dCmdSurfaceDMASuffix *) &blit[dirty->num_hits]; | |
757 | size_t blit_size = sizeof(*blit) * dirty->num_hits + sizeof(*suffix); | |
758 | ||
759 | if (!dirty->num_hits) { | |
760 | vmw_fifo_commit(dirty->dev_priv, 0); | |
761 | return; | |
762 | } | |
763 | ||
764 | cmd->header.id = SVGA_3D_CMD_SURFACE_DMA; | |
765 | cmd->header.size = sizeof(cmd->body) + blit_size; | |
766 | vmw_bo_get_guest_ptr(&ddirty->buf->base, &cmd->body.guest.ptr); | |
767 | cmd->body.guest.pitch = ddirty->pitch; | |
768 | cmd->body.host.sid = stdu->display_srf->res.id; | |
769 | cmd->body.host.face = 0; | |
770 | cmd->body.host.mipmap = 0; | |
771 | cmd->body.transfer = ddirty->transfer; | |
772 | suffix->suffixSize = sizeof(*suffix); | |
773 | suffix->maximumOffset = ddirty->buf->base.num_pages * PAGE_SIZE; | |
774 | ||
775 | if (ddirty->transfer == SVGA3D_WRITE_HOST_VRAM) { | |
776 | blit_size += sizeof(struct vmw_stdu_update); | |
777 | ||
778 | vmw_stdu_populate_update(&suffix[1], stdu->base.unit, | |
779 | ddirty->left, ddirty->right, | |
780 | ddirty->top, ddirty->bottom); | |
781 | } | |
782 | ||
783 | vmw_fifo_commit(dirty->dev_priv, sizeof(*cmd) + blit_size); | |
784 | ||
785 | ddirty->left = ddirty->top = S32_MAX; | |
786 | ddirty->right = ddirty->bottom = S32_MIN; | |
787 | } | |
788 | ||
789 | /** | |
790 | * vmw_kms_stdu_dma - Perform a DMA transfer between a dma-buffer backed | |
791 | * framebuffer and the screen target system. | |
792 | * | |
793 | * @dev_priv: Pointer to the device private structure. | |
794 | * @file_priv: Pointer to a struct drm-file identifying the caller. May be | |
795 | * set to NULL, but then @user_fence_rep must also be set to NULL. | |
796 | * @vfb: Pointer to the dma-buffer backed framebuffer. | |
797 | * @clips: Array of clip rects. Either @clips or @vclips must be NULL. | |
798 | * @vclips: Alternate array of clip rects. Either @clips or @vclips must | |
799 | * be NULL. | |
800 | * @num_clips: Number of clip rects in @clips or @vclips. | |
801 | * @increment: Increment to use when looping over @clips or @vclips. | |
802 | * @to_surface: Whether to DMA to the screen target system as opposed to | |
803 | * from the screen target system. | |
804 | * @interruptible: Whether to perform waits interruptible if possible. | |
805 | * | |
806 | * If DMA-ing till the screen target system, the function will also notify | |
807 | * the screen target system that a bounding box of the cliprects has been | |
808 | * updated. | |
809 | * Returns 0 on success, negative error code on failure. -ERESTARTSYS if | |
810 | * interrupted. | |
811 | */ | |
812 | int vmw_kms_stdu_dma(struct vmw_private *dev_priv, | |
813 | struct drm_file *file_priv, | |
814 | struct vmw_framebuffer *vfb, | |
815 | struct drm_vmw_fence_rep __user *user_fence_rep, | |
816 | struct drm_clip_rect *clips, | |
817 | struct drm_vmw_rect *vclips, | |
818 | uint32_t num_clips, | |
819 | int increment, | |
820 | bool to_surface, | |
821 | bool interruptible) | |
822 | { | |
823 | struct vmw_dma_buffer *buf = | |
824 | container_of(vfb, struct vmw_framebuffer_dmabuf, base)->buffer; | |
825 | struct vmw_stdu_dirty ddirty; | |
826 | int ret; | |
827 | ||
828 | ret = vmw_kms_helper_buffer_prepare(dev_priv, buf, interruptible, | |
829 | false); | |
830 | if (ret) | |
831 | return ret; | |
832 | ||
833 | ddirty.transfer = (to_surface) ? SVGA3D_WRITE_HOST_VRAM : | |
834 | SVGA3D_READ_HOST_VRAM; | |
835 | ddirty.left = ddirty.top = S32_MAX; | |
836 | ddirty.right = ddirty.bottom = S32_MIN; | |
837 | ddirty.pitch = vfb->base.pitches[0]; | |
838 | ddirty.buf = buf; | |
839 | ddirty.base.fifo_commit = vmw_stdu_dmabuf_fifo_commit; | |
840 | ddirty.base.clip = vmw_stdu_dmabuf_clip; | |
841 | ddirty.base.fifo_reserve_size = sizeof(struct vmw_stdu_dma) + | |
842 | num_clips * sizeof(SVGA3dCopyBox) + | |
843 | sizeof(SVGA3dCmdSurfaceDMASuffix); | |
844 | if (to_surface) | |
845 | ddirty.base.fifo_reserve_size += sizeof(struct vmw_stdu_update); | |
846 | ||
847 | ret = vmw_kms_helper_dirty(dev_priv, vfb, clips, vclips, | |
848 | 0, 0, num_clips, increment, &ddirty.base); | |
849 | vmw_kms_helper_buffer_finish(dev_priv, file_priv, buf, NULL, | |
850 | user_fence_rep); | |
851 | ||
852 | return ret; | |
853 | } | |
854 | ||
855 | /** | |
856 | * vmw_stdu_surface_clip - Callback to encode a surface copy command cliprect | |
857 | * | |
858 | * @dirty: The closure structure. | |
859 | * | |
860 | * Encodes a surface copy command cliprect and updates the bounding box | |
861 | * for the copy. | |
862 | */ | |
863 | static void vmw_kms_stdu_surface_clip(struct vmw_kms_dirty *dirty) | |
864 | { | |
865 | struct vmw_stdu_dirty *sdirty = | |
866 | container_of(dirty, struct vmw_stdu_dirty, base); | |
867 | struct vmw_stdu_surface_copy *cmd = dirty->cmd; | |
868 | struct vmw_screen_target_display_unit *stdu = | |
869 | container_of(dirty->unit, typeof(*stdu), base); | |
870 | ||
871 | if (sdirty->sid != stdu->display_srf->res.id) { | |
872 | struct SVGA3dCopyBox *blit = (struct SVGA3dCopyBox *) &cmd[1]; | |
873 | ||
874 | blit += dirty->num_hits; | |
875 | blit->srcx = dirty->fb_x; | |
876 | blit->srcy = dirty->fb_y; | |
877 | blit->x = dirty->unit_x1; | |
878 | blit->y = dirty->unit_y1; | |
879 | blit->d = 1; | |
880 | blit->w = dirty->unit_x2 - dirty->unit_x1; | |
881 | blit->h = dirty->unit_y2 - dirty->unit_y1; | |
882 | } | |
883 | ||
884 | dirty->num_hits++; | |
885 | ||
886 | /* Destination bounding box */ | |
887 | sdirty->left = min_t(s32, sdirty->left, dirty->unit_x1); | |
888 | sdirty->top = min_t(s32, sdirty->top, dirty->unit_y1); | |
889 | sdirty->right = max_t(s32, sdirty->right, dirty->unit_x2); | |
890 | sdirty->bottom = max_t(s32, sdirty->bottom, dirty->unit_y2); | |
891 | } | |
892 | ||
893 | /** | |
894 | * vmw_stdu_surface_fifo_commit - Callback to fill in and submit a surface | |
895 | * copy command. | |
896 | * | |
897 | * @dirty: The closure structure. | |
898 | * | |
899 | * Fills in the missing fields in a surface copy command, and encodes a screen | |
900 | * target update command. | |
901 | */ | |
902 | static void vmw_kms_stdu_surface_fifo_commit(struct vmw_kms_dirty *dirty) | |
903 | { | |
904 | struct vmw_stdu_dirty *sdirty = | |
905 | container_of(dirty, struct vmw_stdu_dirty, base); | |
906 | struct vmw_screen_target_display_unit *stdu = | |
907 | container_of(dirty->unit, typeof(*stdu), base); | |
908 | struct vmw_stdu_surface_copy *cmd = dirty->cmd; | |
909 | struct vmw_stdu_update *update; | |
910 | size_t blit_size = sizeof(SVGA3dCopyBox) * dirty->num_hits; | |
911 | size_t commit_size; | |
912 | ||
913 | if (!dirty->num_hits) { | |
914 | vmw_fifo_commit(dirty->dev_priv, 0); | |
915 | return; | |
916 | } | |
917 | ||
918 | if (sdirty->sid != stdu->display_srf->res.id) { | |
919 | struct SVGA3dCopyBox *blit = (struct SVGA3dCopyBox *) &cmd[1]; | |
920 | ||
921 | cmd->header.id = SVGA_3D_CMD_SURFACE_COPY; | |
922 | cmd->header.size = sizeof(cmd->body) + blit_size; | |
923 | cmd->body.src.sid = sdirty->sid; | |
924 | cmd->body.dest.sid = stdu->display_srf->res.id; | |
925 | update = (struct vmw_stdu_update *) &blit[dirty->num_hits]; | |
926 | commit_size = sizeof(*cmd) + blit_size + sizeof(*update); | |
927 | } else { | |
928 | update = dirty->cmd; | |
929 | commit_size = sizeof(*update); | |
930 | } | |
931 | ||
932 | vmw_stdu_populate_update(update, stdu->base.unit, sdirty->left, | |
933 | sdirty->right, sdirty->top, sdirty->bottom); | |
934 | ||
935 | vmw_fifo_commit(dirty->dev_priv, commit_size); | |
936 | ||
937 | sdirty->left = sdirty->top = S32_MAX; | |
938 | sdirty->right = sdirty->bottom = S32_MIN; | |
939 | } | |
940 | ||
941 | /** | |
942 | * vmw_kms_stdu_surface_dirty - Dirty part of a surface backed framebuffer | |
943 | * | |
944 | * @dev_priv: Pointer to the device private structure. | |
945 | * @framebuffer: Pointer to the surface-buffer backed framebuffer. | |
946 | * @clips: Array of clip rects. Either @clips or @vclips must be NULL. | |
947 | * @vclips: Alternate array of clip rects. Either @clips or @vclips must | |
948 | * be NULL. | |
949 | * @srf: Pointer to surface to blit from. If NULL, the surface attached | |
950 | * to @framebuffer will be used. | |
951 | * @dest_x: X coordinate offset to align @srf with framebuffer coordinates. | |
952 | * @dest_y: Y coordinate offset to align @srf with framebuffer coordinates. | |
953 | * @num_clips: Number of clip rects in @clips. | |
954 | * @inc: Increment to use when looping over @clips. | |
955 | * @out_fence: If non-NULL, will return a ref-counted pointer to a | |
956 | * struct vmw_fence_obj. The returned fence pointer may be NULL in which | |
957 | * case the device has already synchronized. | |
958 | * | |
959 | * Returns 0 on success, negative error code on failure. -ERESTARTSYS if | |
960 | * interrupted. | |
961 | */ | |
962 | int vmw_kms_stdu_surface_dirty(struct vmw_private *dev_priv, | |
963 | struct vmw_framebuffer *framebuffer, | |
964 | struct drm_clip_rect *clips, | |
965 | struct drm_vmw_rect *vclips, | |
966 | struct vmw_resource *srf, | |
967 | s32 dest_x, | |
968 | s32 dest_y, | |
969 | unsigned num_clips, int inc, | |
970 | struct vmw_fence_obj **out_fence) | |
971 | { | |
972 | struct vmw_framebuffer_surface *vfbs = | |
973 | container_of(framebuffer, typeof(*vfbs), base); | |
974 | struct vmw_stdu_dirty sdirty; | |
975 | int ret; | |
976 | ||
977 | if (!srf) | |
978 | srf = &vfbs->surface->res; | |
979 | ||
980 | ret = vmw_kms_helper_resource_prepare(srf, true); | |
981 | if (ret) | |
982 | return ret; | |
983 | ||
984 | if (vfbs->is_dmabuf_proxy) { | |
985 | ret = vmw_kms_update_proxy(srf, clips, num_clips, inc); | |
986 | if (ret) | |
987 | goto out_finish; | |
988 | } | |
989 | ||
990 | sdirty.base.fifo_commit = vmw_kms_stdu_surface_fifo_commit; | |
991 | sdirty.base.clip = vmw_kms_stdu_surface_clip; | |
992 | sdirty.base.fifo_reserve_size = sizeof(struct vmw_stdu_surface_copy) + | |
993 | sizeof(SVGA3dCopyBox) * num_clips + | |
994 | sizeof(struct vmw_stdu_update); | |
995 | sdirty.sid = srf->id; | |
996 | sdirty.left = sdirty.top = S32_MAX; | |
997 | sdirty.right = sdirty.bottom = S32_MIN; | |
998 | ||
999 | ret = vmw_kms_helper_dirty(dev_priv, framebuffer, clips, vclips, | |
1000 | dest_x, dest_y, num_clips, inc, | |
1001 | &sdirty.base); | |
1002 | out_finish: | |
1003 | vmw_kms_helper_resource_finish(srf, out_fence); | |
1004 | ||
1005 | return ret; | |
1006 | } | |
1007 | ||
35c05125 SY |
1008 | |
1009 | /* | |
1010 | * Screen Target CRTC dispatch table | |
1011 | */ | |
d7955fcf | 1012 | static const struct drm_crtc_funcs vmw_stdu_crtc_funcs = { |
8fbf9d92 | 1013 | .cursor_set2 = vmw_du_crtc_cursor_set2, |
35c05125 SY |
1014 | .cursor_move = vmw_du_crtc_cursor_move, |
1015 | .gamma_set = vmw_du_crtc_gamma_set, | |
1016 | .destroy = vmw_stdu_crtc_destroy, | |
1017 | .set_config = vmw_stdu_crtc_set_config, | |
1018 | .page_flip = vmw_stdu_crtc_page_flip, | |
1019 | }; | |
1020 | ||
1021 | ||
1022 | ||
1023 | /****************************************************************************** | |
1024 | * Screen Target Display Unit Encoder Functions | |
1025 | *****************************************************************************/ | |
1026 | ||
1027 | /** | |
1028 | * vmw_stdu_encoder_destroy - cleans up the STDU | |
1029 | * | |
1030 | * @encoder: used the get the containing STDU | |
1031 | * | |
1032 | * vmwgfx cleans up crtc/encoder/connector all at the same time so technically | |
1033 | * this can be a no-op. Nevertheless, it doesn't hurt of have this in case | |
1034 | * the common KMS code changes and somehow vmw_stdu_crtc_destroy() doesn't | |
1035 | * get called. | |
1036 | */ | |
1037 | static void vmw_stdu_encoder_destroy(struct drm_encoder *encoder) | |
1038 | { | |
1039 | vmw_stdu_destroy(vmw_encoder_to_stdu(encoder)); | |
1040 | } | |
1041 | ||
d7955fcf | 1042 | static const struct drm_encoder_funcs vmw_stdu_encoder_funcs = { |
35c05125 SY |
1043 | .destroy = vmw_stdu_encoder_destroy, |
1044 | }; | |
1045 | ||
1046 | ||
1047 | ||
1048 | /****************************************************************************** | |
1049 | * Screen Target Display Unit Connector Functions | |
1050 | *****************************************************************************/ | |
1051 | ||
1052 | /** | |
1053 | * vmw_stdu_connector_destroy - cleans up the STDU | |
1054 | * | |
1055 | * @connector: used to get the containing STDU | |
1056 | * | |
1057 | * vmwgfx cleans up crtc/encoder/connector all at the same time so technically | |
1058 | * this can be a no-op. Nevertheless, it doesn't hurt of have this in case | |
1059 | * the common KMS code changes and somehow vmw_stdu_crtc_destroy() doesn't | |
1060 | * get called. | |
1061 | */ | |
1062 | static void vmw_stdu_connector_destroy(struct drm_connector *connector) | |
1063 | { | |
1064 | vmw_stdu_destroy(vmw_connector_to_stdu(connector)); | |
1065 | } | |
1066 | ||
1067 | ||
1068 | ||
d7955fcf | 1069 | static const struct drm_connector_funcs vmw_stdu_connector_funcs = { |
35c05125 | 1070 | .dpms = vmw_du_connector_dpms, |
35c05125 SY |
1071 | .detect = vmw_du_connector_detect, |
1072 | .fill_modes = vmw_du_connector_fill_modes, | |
1073 | .set_property = vmw_du_connector_set_property, | |
1074 | .destroy = vmw_stdu_connector_destroy, | |
1075 | }; | |
1076 | ||
1077 | ||
1078 | ||
1079 | /** | |
1080 | * vmw_stdu_init - Sets up a Screen Target Display Unit | |
1081 | * | |
1082 | * @dev_priv: VMW DRM device | |
1083 | * @unit: unit number range from 0 to VMWGFX_NUM_DISPLAY_UNITS | |
1084 | * | |
1085 | * This function is called once per CRTC, and allocates one Screen Target | |
1086 | * display unit to represent that CRTC. Since the SVGA device does not separate | |
1087 | * out encoder and connector, they are represented as part of the STDU as well. | |
1088 | */ | |
1089 | static int vmw_stdu_init(struct vmw_private *dev_priv, unsigned unit) | |
1090 | { | |
1091 | struct vmw_screen_target_display_unit *stdu; | |
1092 | struct drm_device *dev = dev_priv->dev; | |
1093 | struct drm_connector *connector; | |
1094 | struct drm_encoder *encoder; | |
1095 | struct drm_crtc *crtc; | |
1096 | ||
1097 | ||
1098 | stdu = kzalloc(sizeof(*stdu), GFP_KERNEL); | |
1099 | if (!stdu) | |
1100 | return -ENOMEM; | |
1101 | ||
1102 | stdu->base.unit = unit; | |
1103 | crtc = &stdu->base.crtc; | |
1104 | encoder = &stdu->base.encoder; | |
1105 | connector = &stdu->base.connector; | |
1106 | ||
1107 | stdu->base.pref_active = (unit == 0); | |
1108 | stdu->base.pref_width = dev_priv->initial_width; | |
1109 | stdu->base.pref_height = dev_priv->initial_height; | |
35c05125 SY |
1110 | stdu->base.is_implicit = true; |
1111 | ||
1112 | drm_connector_init(dev, connector, &vmw_stdu_connector_funcs, | |
1113 | DRM_MODE_CONNECTOR_VIRTUAL); | |
1114 | connector->status = vmw_du_connector_detect(connector, false); | |
1115 | ||
1116 | drm_encoder_init(dev, encoder, &vmw_stdu_encoder_funcs, | |
13a3d91f | 1117 | DRM_MODE_ENCODER_VIRTUAL, NULL); |
35c05125 SY |
1118 | drm_mode_connector_attach_encoder(connector, encoder); |
1119 | encoder->possible_crtcs = (1 << unit); | |
1120 | encoder->possible_clones = 0; | |
1121 | ||
1122 | (void) drm_connector_register(connector); | |
1123 | ||
1124 | drm_crtc_init(dev, crtc, &vmw_stdu_crtc_funcs); | |
1125 | ||
1126 | drm_mode_crtc_set_gamma_size(crtc, 256); | |
1127 | ||
1128 | drm_object_attach_property(&connector->base, | |
1129 | dev->mode_config.dirty_info_property, | |
1130 | 1); | |
578e609a TH |
1131 | drm_object_attach_property(&connector->base, |
1132 | dev_priv->hotplug_mode_update_property, 1); | |
1133 | drm_object_attach_property(&connector->base, | |
1134 | dev->mode_config.suggested_x_property, 0); | |
1135 | drm_object_attach_property(&connector->base, | |
1136 | dev->mode_config.suggested_y_property, 0); | |
76404ac0 TH |
1137 | if (dev_priv->implicit_placement_property) |
1138 | drm_object_attach_property | |
1139 | (&connector->base, | |
1140 | dev_priv->implicit_placement_property, | |
1141 | stdu->base.is_implicit); | |
35c05125 SY |
1142 | return 0; |
1143 | } | |
1144 | ||
1145 | ||
1146 | ||
1147 | /** | |
1148 | * vmw_stdu_destroy - Cleans up a vmw_screen_target_display_unit | |
1149 | * | |
1150 | * @stdu: Screen Target Display Unit to be destroyed | |
1151 | * | |
1152 | * Clean up after vmw_stdu_init | |
1153 | */ | |
1154 | static void vmw_stdu_destroy(struct vmw_screen_target_display_unit *stdu) | |
1155 | { | |
1156 | vmw_stdu_unpin_display(stdu); | |
1157 | ||
1158 | vmw_du_cleanup(&stdu->base); | |
1159 | kfree(stdu); | |
1160 | } | |
1161 | ||
1162 | ||
1163 | ||
1164 | /****************************************************************************** | |
1165 | * Screen Target Display KMS Functions | |
1166 | * | |
1167 | * These functions are called by the common KMS code in vmwgfx_kms.c | |
1168 | *****************************************************************************/ | |
1169 | ||
1170 | /** | |
1171 | * vmw_kms_stdu_init_display - Initializes a Screen Target based display | |
1172 | * | |
1173 | * @dev_priv: VMW DRM device | |
1174 | * | |
1175 | * This function initialize a Screen Target based display device. It checks | |
1176 | * the capability bits to make sure the underlying hardware can support | |
1177 | * screen targets, and then creates the maximum number of CRTCs, a.k.a Display | |
1178 | * Units, as supported by the display hardware. | |
1179 | * | |
1180 | * RETURNS: | |
1181 | * 0 on success, error code otherwise | |
1182 | */ | |
1183 | int vmw_kms_stdu_init_display(struct vmw_private *dev_priv) | |
1184 | { | |
1185 | struct drm_device *dev = dev_priv->dev; | |
1186 | int i, ret; | |
1187 | ||
1188 | ||
1189 | /* Do nothing if Screen Target support is turned off */ | |
1190 | if (!VMWGFX_ENABLE_SCREEN_TARGET_OTABLE) | |
1191 | return -ENOSYS; | |
1192 | ||
f89c6c32 | 1193 | if (!(dev_priv->capabilities & SVGA_CAP_GBOBJECTS)) |
35c05125 SY |
1194 | return -ENOSYS; |
1195 | ||
1196 | ret = drm_vblank_init(dev, VMWGFX_NUM_DISPLAY_UNITS); | |
1197 | if (unlikely(ret != 0)) | |
1198 | return ret; | |
1199 | ||
1200 | ret = drm_mode_create_dirty_info_property(dev); | |
1201 | if (unlikely(ret != 0)) | |
1202 | goto err_vblank_cleanup; | |
1203 | ||
6bf6bf03 TH |
1204 | dev_priv->active_display_unit = vmw_du_screen_target; |
1205 | ||
76404ac0 TH |
1206 | vmw_kms_create_implicit_placement_property(dev_priv, false); |
1207 | ||
35c05125 SY |
1208 | for (i = 0; i < VMWGFX_NUM_DISPLAY_UNITS; ++i) { |
1209 | ret = vmw_stdu_init(dev_priv, i); | |
1210 | ||
1211 | if (unlikely(ret != 0)) { | |
1212 | DRM_ERROR("Failed to initialize STDU %d", i); | |
1213 | goto err_vblank_cleanup; | |
1214 | } | |
1215 | } | |
1216 | ||
35c05125 SY |
1217 | DRM_INFO("Screen Target Display device initialized\n"); |
1218 | ||
1219 | return 0; | |
1220 | ||
1221 | err_vblank_cleanup: | |
1222 | drm_vblank_cleanup(dev); | |
1223 | return ret; | |
1224 | } | |
1225 | ||
1226 | ||
1227 | ||
1228 | /** | |
1229 | * vmw_kms_stdu_close_display - Cleans up after vmw_kms_stdu_init_display | |
1230 | * | |
1231 | * @dev_priv: VMW DRM device | |
1232 | * | |
1233 | * Frees up any resources allocated by vmw_kms_stdu_init_display | |
1234 | * | |
1235 | * RETURNS: | |
1236 | * 0 on success | |
1237 | */ | |
1238 | int vmw_kms_stdu_close_display(struct vmw_private *dev_priv) | |
1239 | { | |
1240 | struct drm_device *dev = dev_priv->dev; | |
1241 | ||
1242 | drm_vblank_cleanup(dev); | |
1243 | ||
1244 | return 0; | |
1245 | } |