Dirk Hohndel (VMware) | dff9688 | 2018-05-07 01:16:26 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 OR MIT |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 2 | /************************************************************************** |
| 3 | * |
Dirk Hohndel (VMware) | dff9688 | 2018-05-07 01:16:26 +0200 | [diff] [blame] | 4 | * Copyright 2009-2015 VMware, Inc., Palo Alto, CA., USA |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 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 | |
Sinclair Yeh | 9c2542a | 2017-03-23 11:33:39 -0700 | [diff] [blame] | 28 | #include <drm/drm_atomic.h> |
| 29 | #include <drm/drm_atomic_helper.h> |
Deepak Rawat | e41774c | 2018-07-11 15:42:45 -0700 | [diff] [blame] | 30 | #include <drm/drm_damage_helper.h> |
Sam Ravnborg | d5c1f01 | 2019-06-23 12:23:33 +0200 | [diff] [blame] | 31 | #include <drm/drm_fourcc.h> |
| 32 | #include <drm/drm_plane_helper.h> |
| 33 | #include <drm/drm_rect.h> |
| 34 | #include <drm/drm_sysfs.h> |
| 35 | #include <drm/drm_vblank.h> |
| 36 | |
| 37 | #include "vmwgfx_kms.h" |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 38 | |
Sinclair Yeh | c8261a9 | 2015-06-26 01:23:42 -0700 | [diff] [blame] | 39 | void vmw_du_cleanup(struct vmw_display_unit *du) |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 40 | { |
Sinclair Yeh | 36cc79b | 2017-03-23 11:28:11 -0700 | [diff] [blame] | 41 | drm_plane_cleanup(&du->primary); |
| 42 | drm_plane_cleanup(&du->cursor); |
| 43 | |
Thomas Wood | 34ea3d3 | 2014-05-29 16:57:41 +0100 | [diff] [blame] | 44 | drm_connector_unregister(&du->connector); |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 45 | drm_crtc_cleanup(&du->crtc); |
| 46 | drm_encoder_cleanup(&du->encoder); |
| 47 | drm_connector_cleanup(&du->connector); |
| 48 | } |
| 49 | |
| 50 | /* |
| 51 | * Display Unit Cursor functions |
| 52 | */ |
| 53 | |
Sinclair Yeh | 36cc79b | 2017-03-23 11:28:11 -0700 | [diff] [blame] | 54 | static int vmw_cursor_update_image(struct vmw_private *dev_priv, |
| 55 | u32 *image, u32 width, u32 height, |
| 56 | u32 hotspotX, u32 hotspotY) |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 57 | { |
| 58 | struct { |
| 59 | u32 cmd; |
| 60 | SVGAFifoCmdDefineAlphaCursor cursor; |
| 61 | } *cmd; |
| 62 | u32 image_size = width * height * 4; |
| 63 | u32 cmd_size = sizeof(*cmd) + image_size; |
| 64 | |
| 65 | if (!image) |
| 66 | return -EINVAL; |
| 67 | |
Zack Rusin | 8426ed9 | 2020-11-18 12:54:19 -0500 | [diff] [blame] | 68 | cmd = VMW_CMD_RESERVE(dev_priv, cmd_size); |
Deepak Rawat | 11c4541 | 2019-02-14 16:15:39 -0800 | [diff] [blame] | 69 | if (unlikely(cmd == NULL)) |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 70 | return -ENOMEM; |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 71 | |
| 72 | memset(cmd, 0, sizeof(*cmd)); |
| 73 | |
| 74 | memcpy(&cmd[1], image, image_size); |
| 75 | |
Thomas Hellstrom | b9eb1a6 | 2015-04-02 02:39:45 -0700 | [diff] [blame] | 76 | cmd->cmd = SVGA_CMD_DEFINE_ALPHA_CURSOR; |
| 77 | cmd->cursor.id = 0; |
| 78 | cmd->cursor.width = width; |
| 79 | cmd->cursor.height = height; |
| 80 | cmd->cursor.hotspotX = hotspotX; |
| 81 | cmd->cursor.hotspotY = hotspotY; |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 82 | |
Zack Rusin | 8426ed9 | 2020-11-18 12:54:19 -0500 | [diff] [blame] | 83 | vmw_cmd_commit_flush(dev_priv, cmd_size); |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 84 | |
| 85 | return 0; |
| 86 | } |
| 87 | |
Thomas Hellstrom | f1d34bf | 2018-06-19 15:02:16 +0200 | [diff] [blame] | 88 | static int vmw_cursor_update_bo(struct vmw_private *dev_priv, |
| 89 | struct vmw_buffer_object *bo, |
| 90 | u32 width, u32 height, |
| 91 | u32 hotspotX, u32 hotspotY) |
Jakob Bornecrantz | 6a91d97 | 2011-11-28 13:19:10 +0100 | [diff] [blame] | 92 | { |
| 93 | struct ttm_bo_kmap_obj map; |
| 94 | unsigned long kmap_offset; |
| 95 | unsigned long kmap_num; |
| 96 | void *virtual; |
| 97 | bool dummy; |
| 98 | int ret; |
| 99 | |
| 100 | kmap_offset = 0; |
| 101 | kmap_num = (width*height*4 + PAGE_SIZE - 1) >> PAGE_SHIFT; |
| 102 | |
Thomas Hellstrom | f1d34bf | 2018-06-19 15:02:16 +0200 | [diff] [blame] | 103 | ret = ttm_bo_reserve(&bo->base, true, false, NULL); |
Jakob Bornecrantz | 6a91d97 | 2011-11-28 13:19:10 +0100 | [diff] [blame] | 104 | if (unlikely(ret != 0)) { |
| 105 | DRM_ERROR("reserve failed\n"); |
| 106 | return -EINVAL; |
| 107 | } |
| 108 | |
Thomas Hellstrom | f1d34bf | 2018-06-19 15:02:16 +0200 | [diff] [blame] | 109 | ret = ttm_bo_kmap(&bo->base, kmap_offset, kmap_num, &map); |
Jakob Bornecrantz | 6a91d97 | 2011-11-28 13:19:10 +0100 | [diff] [blame] | 110 | if (unlikely(ret != 0)) |
| 111 | goto err_unreserve; |
| 112 | |
| 113 | virtual = ttm_kmap_obj_virtual(&map, &dummy); |
| 114 | ret = vmw_cursor_update_image(dev_priv, virtual, width, height, |
| 115 | hotspotX, hotspotY); |
| 116 | |
| 117 | ttm_bo_kunmap(&map); |
| 118 | err_unreserve: |
Thomas Hellstrom | f1d34bf | 2018-06-19 15:02:16 +0200 | [diff] [blame] | 119 | ttm_bo_unreserve(&bo->base); |
Jakob Bornecrantz | 6a91d97 | 2011-11-28 13:19:10 +0100 | [diff] [blame] | 120 | |
| 121 | return ret; |
| 122 | } |
| 123 | |
| 124 | |
Sinclair Yeh | 36cc79b | 2017-03-23 11:28:11 -0700 | [diff] [blame] | 125 | static void vmw_cursor_update_position(struct vmw_private *dev_priv, |
| 126 | bool show, int x, int y) |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 127 | { |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 128 | uint32_t count; |
| 129 | |
Sinclair Yeh | 36cc79b | 2017-03-23 11:28:11 -0700 | [diff] [blame] | 130 | spin_lock(&dev_priv->cursor_lock); |
Zack Rusin | be4f77a | 2020-11-04 13:46:09 -0500 | [diff] [blame] | 131 | vmw_fifo_mem_write(dev_priv, SVGA_FIFO_CURSOR_ON, show ? 1 : 0); |
| 132 | vmw_fifo_mem_write(dev_priv, SVGA_FIFO_CURSOR_X, x); |
| 133 | vmw_fifo_mem_write(dev_priv, SVGA_FIFO_CURSOR_Y, y); |
| 134 | count = vmw_fifo_mem_read(dev_priv, SVGA_FIFO_CURSOR_COUNT); |
| 135 | vmw_fifo_mem_write(dev_priv, SVGA_FIFO_CURSOR_COUNT, ++count); |
Sinclair Yeh | 36cc79b | 2017-03-23 11:28:11 -0700 | [diff] [blame] | 136 | spin_unlock(&dev_priv->cursor_lock); |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 137 | } |
| 138 | |
Thomas Hellstrom | 8fbf9d9 | 2015-11-26 19:45:16 +0100 | [diff] [blame] | 139 | |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 140 | void vmw_kms_cursor_snoop(struct vmw_surface *srf, |
| 141 | struct ttm_object_file *tfile, |
| 142 | struct ttm_buffer_object *bo, |
| 143 | SVGA3dCmdHeader *header) |
| 144 | { |
| 145 | struct ttm_bo_kmap_obj map; |
| 146 | unsigned long kmap_offset; |
| 147 | unsigned long kmap_num; |
| 148 | SVGA3dCopyBox *box; |
| 149 | unsigned box_count; |
| 150 | void *virtual; |
| 151 | bool dummy; |
| 152 | struct vmw_dma_cmd { |
| 153 | SVGA3dCmdHeader header; |
| 154 | SVGA3dCmdSurfaceDMA dma; |
| 155 | } *cmd; |
Jakob Bornecrantz | 2ac8637 | 2011-11-03 21:03:08 +0100 | [diff] [blame] | 156 | int i, ret; |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 157 | |
| 158 | cmd = container_of(header, struct vmw_dma_cmd, header); |
| 159 | |
| 160 | /* No snooper installed */ |
| 161 | if (!srf->snooper.image) |
| 162 | return; |
| 163 | |
| 164 | if (cmd->dma.host.face != 0 || cmd->dma.host.mipmap != 0) { |
| 165 | DRM_ERROR("face and mipmap for cursors should never != 0\n"); |
| 166 | return; |
| 167 | } |
| 168 | |
| 169 | if (cmd->header.size < 64) { |
| 170 | DRM_ERROR("at least one full copy box must be given\n"); |
| 171 | return; |
| 172 | } |
| 173 | |
| 174 | box = (SVGA3dCopyBox *)&cmd[1]; |
| 175 | box_count = (cmd->header.size - sizeof(SVGA3dCmdSurfaceDMA)) / |
| 176 | sizeof(SVGA3dCopyBox); |
| 177 | |
Jakob Bornecrantz | 2ac8637 | 2011-11-03 21:03:08 +0100 | [diff] [blame] | 178 | if (cmd->dma.guest.ptr.offset % PAGE_SIZE || |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 179 | box->x != 0 || box->y != 0 || box->z != 0 || |
| 180 | box->srcx != 0 || box->srcy != 0 || box->srcz != 0 || |
Jakob Bornecrantz | 2ac8637 | 2011-11-03 21:03:08 +0100 | [diff] [blame] | 181 | box->d != 1 || box_count != 1) { |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 182 | /* TODO handle none page aligned offsets */ |
Jakob Bornecrantz | 2ac8637 | 2011-11-03 21:03:08 +0100 | [diff] [blame] | 183 | /* TODO handle more dst & src != 0 */ |
| 184 | /* TODO handle more then one copy */ |
Colin Ian King | e97644e | 2020-08-10 11:04:01 +0100 | [diff] [blame] | 185 | DRM_ERROR("Can't snoop dma request for cursor!\n"); |
Jakob Bornecrantz | 2ac8637 | 2011-11-03 21:03:08 +0100 | [diff] [blame] | 186 | DRM_ERROR("(%u, %u, %u) (%u, %u, %u) (%ux%ux%u) %u %u\n", |
| 187 | box->srcx, box->srcy, box->srcz, |
| 188 | box->x, box->y, box->z, |
| 189 | box->w, box->h, box->d, box_count, |
| 190 | cmd->dma.guest.ptr.offset); |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 191 | return; |
| 192 | } |
| 193 | |
| 194 | kmap_offset = cmd->dma.guest.ptr.offset >> PAGE_SHIFT; |
| 195 | kmap_num = (64*64*4) >> PAGE_SHIFT; |
| 196 | |
Christian König | dfd5e50 | 2016-04-06 11:12:03 +0200 | [diff] [blame] | 197 | ret = ttm_bo_reserve(bo, true, false, NULL); |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 198 | if (unlikely(ret != 0)) { |
| 199 | DRM_ERROR("reserve failed\n"); |
| 200 | return; |
| 201 | } |
| 202 | |
| 203 | ret = ttm_bo_kmap(bo, kmap_offset, kmap_num, &map); |
| 204 | if (unlikely(ret != 0)) |
| 205 | goto err_unreserve; |
| 206 | |
| 207 | virtual = ttm_kmap_obj_virtual(&map, &dummy); |
| 208 | |
Jakob Bornecrantz | 2ac8637 | 2011-11-03 21:03:08 +0100 | [diff] [blame] | 209 | if (box->w == 64 && cmd->dma.guest.pitch == 64*4) { |
| 210 | memcpy(srf->snooper.image, virtual, 64*64*4); |
| 211 | } else { |
| 212 | /* Image is unsigned pointer. */ |
| 213 | for (i = 0; i < box->h; i++) |
| 214 | memcpy(srf->snooper.image + i * 64, |
| 215 | virtual + i * cmd->dma.guest.pitch, |
| 216 | box->w * 4); |
| 217 | } |
| 218 | |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 219 | srf->snooper.age++; |
| 220 | |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 221 | ttm_bo_kunmap(&map); |
| 222 | err_unreserve: |
| 223 | ttm_bo_unreserve(bo); |
| 224 | } |
| 225 | |
Thomas Hellstrom | 8fbf9d9 | 2015-11-26 19:45:16 +0100 | [diff] [blame] | 226 | /** |
| 227 | * vmw_kms_legacy_hotspot_clear - Clear legacy hotspots |
| 228 | * |
| 229 | * @dev_priv: Pointer to the device private struct. |
| 230 | * |
| 231 | * Clears all legacy hotspots. |
| 232 | */ |
| 233 | void vmw_kms_legacy_hotspot_clear(struct vmw_private *dev_priv) |
| 234 | { |
Zack Rusin | 9703bb3 | 2020-11-03 22:21:34 -0500 | [diff] [blame] | 235 | struct drm_device *dev = &dev_priv->drm; |
Thomas Hellstrom | 8fbf9d9 | 2015-11-26 19:45:16 +0100 | [diff] [blame] | 236 | struct vmw_display_unit *du; |
| 237 | struct drm_crtc *crtc; |
| 238 | |
| 239 | drm_modeset_lock_all(dev); |
| 240 | drm_for_each_crtc(crtc, dev) { |
| 241 | du = vmw_crtc_to_du(crtc); |
| 242 | |
| 243 | du->hotspot_x = 0; |
| 244 | du->hotspot_y = 0; |
| 245 | } |
| 246 | drm_modeset_unlock_all(dev); |
| 247 | } |
| 248 | |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 249 | void vmw_kms_cursor_post_execbuf(struct vmw_private *dev_priv) |
| 250 | { |
Zack Rusin | 9703bb3 | 2020-11-03 22:21:34 -0500 | [diff] [blame] | 251 | struct drm_device *dev = &dev_priv->drm; |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 252 | struct vmw_display_unit *du; |
| 253 | struct drm_crtc *crtc; |
| 254 | |
| 255 | mutex_lock(&dev->mode_config.mutex); |
| 256 | |
| 257 | list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) { |
| 258 | du = vmw_crtc_to_du(crtc); |
| 259 | if (!du->cursor_surface || |
| 260 | du->cursor_age == du->cursor_surface->snooper.age) |
| 261 | continue; |
| 262 | |
| 263 | du->cursor_age = du->cursor_surface->snooper.age; |
| 264 | vmw_cursor_update_image(dev_priv, |
| 265 | du->cursor_surface->snooper.image, |
Thomas Hellstrom | 8fbf9d9 | 2015-11-26 19:45:16 +0100 | [diff] [blame] | 266 | 64, 64, |
| 267 | du->hotspot_x + du->core_hotspot_x, |
| 268 | du->hotspot_y + du->core_hotspot_y); |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 269 | } |
| 270 | |
| 271 | mutex_unlock(&dev->mode_config.mutex); |
| 272 | } |
| 273 | |
Sinclair Yeh | 36cc79b | 2017-03-23 11:28:11 -0700 | [diff] [blame] | 274 | |
Sinclair Yeh | 36cc79b | 2017-03-23 11:28:11 -0700 | [diff] [blame] | 275 | void vmw_du_cursor_plane_destroy(struct drm_plane *plane) |
| 276 | { |
| 277 | vmw_cursor_update_position(plane->dev->dev_private, false, 0, 0); |
| 278 | |
| 279 | drm_plane_cleanup(plane); |
| 280 | } |
| 281 | |
| 282 | |
| 283 | void vmw_du_primary_plane_destroy(struct drm_plane *plane) |
| 284 | { |
| 285 | drm_plane_cleanup(plane); |
| 286 | |
| 287 | /* Planes are static in our case so we don't free it */ |
| 288 | } |
| 289 | |
| 290 | |
Sinclair Yeh | 060e2ad | 2017-03-23 14:18:32 -0700 | [diff] [blame] | 291 | /** |
| 292 | * vmw_du_vps_unpin_surf - unpins resource associated with a framebuffer surface |
| 293 | * |
| 294 | * @vps: plane state associated with the display surface |
| 295 | * @unreference: true if we also want to unreference the display. |
| 296 | */ |
| 297 | void vmw_du_plane_unpin_surf(struct vmw_plane_state *vps, |
| 298 | bool unreference) |
| 299 | { |
| 300 | if (vps->surf) { |
| 301 | if (vps->pinned) { |
| 302 | vmw_resource_unpin(&vps->surf->res); |
| 303 | vps->pinned--; |
| 304 | } |
| 305 | |
| 306 | if (unreference) { |
| 307 | if (vps->pinned) |
| 308 | DRM_ERROR("Surface still pinned\n"); |
| 309 | vmw_surface_unreference(&vps->surf); |
| 310 | } |
| 311 | } |
| 312 | } |
| 313 | |
| 314 | |
| 315 | /** |
| 316 | * vmw_du_plane_cleanup_fb - Unpins the cursor |
| 317 | * |
| 318 | * @plane: display plane |
| 319 | * @old_state: Contains the FB to clean up |
| 320 | * |
| 321 | * Unpins the framebuffer surface |
| 322 | * |
| 323 | * Returns 0 on success |
| 324 | */ |
| 325 | void |
| 326 | vmw_du_plane_cleanup_fb(struct drm_plane *plane, |
| 327 | struct drm_plane_state *old_state) |
| 328 | { |
| 329 | struct vmw_plane_state *vps = vmw_plane_state_to_vps(old_state); |
| 330 | |
| 331 | vmw_du_plane_unpin_surf(vps, false); |
| 332 | } |
| 333 | |
| 334 | |
| 335 | /** |
| 336 | * vmw_du_cursor_plane_prepare_fb - Readies the cursor by referencing it |
| 337 | * |
| 338 | * @plane: display plane |
| 339 | * @new_state: info on the new plane state, including the FB |
| 340 | * |
| 341 | * Returns 0 on success |
| 342 | */ |
| 343 | int |
| 344 | vmw_du_cursor_plane_prepare_fb(struct drm_plane *plane, |
| 345 | struct drm_plane_state *new_state) |
| 346 | { |
| 347 | struct drm_framebuffer *fb = new_state->fb; |
| 348 | struct vmw_plane_state *vps = vmw_plane_state_to_vps(new_state); |
| 349 | |
| 350 | |
| 351 | if (vps->surf) |
| 352 | vmw_surface_unreference(&vps->surf); |
| 353 | |
Thomas Hellstrom | f1d34bf | 2018-06-19 15:02:16 +0200 | [diff] [blame] | 354 | if (vps->bo) |
| 355 | vmw_bo_unreference(&vps->bo); |
Sinclair Yeh | 060e2ad | 2017-03-23 14:18:32 -0700 | [diff] [blame] | 356 | |
| 357 | if (fb) { |
Thomas Hellstrom | f1d34bf | 2018-06-19 15:02:16 +0200 | [diff] [blame] | 358 | if (vmw_framebuffer_to_vfb(fb)->bo) { |
| 359 | vps->bo = vmw_framebuffer_to_vfbd(fb)->buffer; |
| 360 | vmw_bo_reference(vps->bo); |
Sinclair Yeh | 060e2ad | 2017-03-23 14:18:32 -0700 | [diff] [blame] | 361 | } else { |
| 362 | vps->surf = vmw_framebuffer_to_vfbs(fb)->surface; |
| 363 | vmw_surface_reference(vps->surf); |
| 364 | } |
| 365 | } |
| 366 | |
| 367 | return 0; |
| 368 | } |
| 369 | |
| 370 | |
| 371 | void |
Sinclair Yeh | 060e2ad | 2017-03-23 14:18:32 -0700 | [diff] [blame] | 372 | vmw_du_cursor_plane_atomic_update(struct drm_plane *plane, |
| 373 | struct drm_plane_state *old_state) |
| 374 | { |
| 375 | struct drm_crtc *crtc = plane->state->crtc ?: old_state->crtc; |
| 376 | struct vmw_private *dev_priv = vmw_priv(crtc->dev); |
| 377 | struct vmw_display_unit *du = vmw_crtc_to_du(crtc); |
| 378 | struct vmw_plane_state *vps = vmw_plane_state_to_vps(plane->state); |
| 379 | s32 hotspot_x, hotspot_y; |
| 380 | int ret = 0; |
| 381 | |
| 382 | |
| 383 | hotspot_x = du->hotspot_x; |
| 384 | hotspot_y = du->hotspot_y; |
Sinclair Yeh | 14979ad | 2017-07-17 23:26:21 -0700 | [diff] [blame] | 385 | |
Ville Syrjälä | 2bb01c4 | 2018-03-22 17:23:02 +0200 | [diff] [blame] | 386 | if (plane->state->fb) { |
| 387 | hotspot_x += plane->state->fb->hot_x; |
| 388 | hotspot_y += plane->state->fb->hot_y; |
Sinclair Yeh | 14979ad | 2017-07-17 23:26:21 -0700 | [diff] [blame] | 389 | } |
| 390 | |
Sinclair Yeh | 060e2ad | 2017-03-23 14:18:32 -0700 | [diff] [blame] | 391 | du->cursor_surface = vps->surf; |
Thomas Hellstrom | f1d34bf | 2018-06-19 15:02:16 +0200 | [diff] [blame] | 392 | du->cursor_bo = vps->bo; |
Sinclair Yeh | 060e2ad | 2017-03-23 14:18:32 -0700 | [diff] [blame] | 393 | |
Sinclair Yeh | 060e2ad | 2017-03-23 14:18:32 -0700 | [diff] [blame] | 394 | if (vps->surf) { |
| 395 | du->cursor_age = du->cursor_surface->snooper.age; |
| 396 | |
| 397 | ret = vmw_cursor_update_image(dev_priv, |
| 398 | vps->surf->snooper.image, |
Thomas Hellstrom | 25db875 | 2018-01-16 08:54:30 +0100 | [diff] [blame] | 399 | 64, 64, hotspot_x, |
| 400 | hotspot_y); |
Thomas Hellstrom | f1d34bf | 2018-06-19 15:02:16 +0200 | [diff] [blame] | 401 | } else if (vps->bo) { |
| 402 | ret = vmw_cursor_update_bo(dev_priv, vps->bo, |
| 403 | plane->state->crtc_w, |
| 404 | plane->state->crtc_h, |
| 405 | hotspot_x, hotspot_y); |
Sinclair Yeh | 060e2ad | 2017-03-23 14:18:32 -0700 | [diff] [blame] | 406 | } else { |
| 407 | vmw_cursor_update_position(dev_priv, false, 0, 0); |
| 408 | return; |
| 409 | } |
| 410 | |
| 411 | if (!ret) { |
| 412 | du->cursor_x = plane->state->crtc_x + du->set_gui_x; |
| 413 | du->cursor_y = plane->state->crtc_y + du->set_gui_y; |
| 414 | |
| 415 | vmw_cursor_update_position(dev_priv, true, |
| 416 | du->cursor_x + hotspot_x, |
| 417 | du->cursor_y + hotspot_y); |
Sinclair Yeh | 14979ad | 2017-07-17 23:26:21 -0700 | [diff] [blame] | 418 | |
| 419 | du->core_hotspot_x = hotspot_x - du->hotspot_x; |
| 420 | du->core_hotspot_y = hotspot_y - du->hotspot_y; |
Sinclair Yeh | 060e2ad | 2017-03-23 14:18:32 -0700 | [diff] [blame] | 421 | } else { |
| 422 | DRM_ERROR("Failed to update cursor image\n"); |
| 423 | } |
| 424 | } |
| 425 | |
| 426 | |
| 427 | /** |
| 428 | * vmw_du_primary_plane_atomic_check - check if the new state is okay |
| 429 | * |
| 430 | * @plane: display plane |
| 431 | * @state: info on the new plane state, including the FB |
| 432 | * |
| 433 | * Check if the new state is settable given the current state. Other |
| 434 | * than what the atomic helper checks, we care about crtc fitting |
| 435 | * the FB and maintaining one active framebuffer. |
| 436 | * |
| 437 | * Returns 0 on success |
| 438 | */ |
| 439 | int vmw_du_primary_plane_atomic_check(struct drm_plane *plane, |
Maxime Ripard | 7c11b99 | 2021-02-19 13:00:24 +0100 | [diff] [blame] | 440 | struct drm_atomic_state *state) |
Sinclair Yeh | 060e2ad | 2017-03-23 14:18:32 -0700 | [diff] [blame] | 441 | { |
Maxime Ripard | 7c11b99 | 2021-02-19 13:00:24 +0100 | [diff] [blame] | 442 | struct drm_plane_state *new_state = drm_atomic_get_new_plane_state(state, |
| 443 | plane); |
Ville Syrjälä | 58a275aa9 | 2017-11-01 20:29:18 +0200 | [diff] [blame] | 444 | struct drm_crtc_state *crtc_state = NULL; |
Maxime Ripard | ba5c164 | 2021-02-19 13:00:22 +0100 | [diff] [blame] | 445 | struct drm_framebuffer *new_fb = new_state->fb; |
Sinclair Yeh | 060e2ad | 2017-03-23 14:18:32 -0700 | [diff] [blame] | 446 | int ret; |
| 447 | |
Maxime Ripard | ba5c164 | 2021-02-19 13:00:22 +0100 | [diff] [blame] | 448 | if (new_state->crtc) |
Maxime Ripard | dec9202 | 2021-02-19 13:00:25 +0100 | [diff] [blame^] | 449 | crtc_state = drm_atomic_get_new_crtc_state(state, |
Maxime Ripard | ba5c164 | 2021-02-19 13:00:22 +0100 | [diff] [blame] | 450 | new_state->crtc); |
Sinclair Yeh | 060e2ad | 2017-03-23 14:18:32 -0700 | [diff] [blame] | 451 | |
Maxime Ripard | ba5c164 | 2021-02-19 13:00:22 +0100 | [diff] [blame] | 452 | ret = drm_atomic_helper_check_plane_state(new_state, crtc_state, |
Ville Syrjälä | a01cb8b | 2017-11-01 22:16:19 +0200 | [diff] [blame] | 453 | DRM_PLANE_HELPER_NO_SCALING, |
| 454 | DRM_PLANE_HELPER_NO_SCALING, |
| 455 | false, true); |
Sinclair Yeh | 060e2ad | 2017-03-23 14:18:32 -0700 | [diff] [blame] | 456 | |
| 457 | if (!ret && new_fb) { |
Maxime Ripard | ba5c164 | 2021-02-19 13:00:22 +0100 | [diff] [blame] | 458 | struct drm_crtc *crtc = new_state->crtc; |
Sinclair Yeh | 060e2ad | 2017-03-23 14:18:32 -0700 | [diff] [blame] | 459 | struct vmw_display_unit *du = vmw_crtc_to_du(crtc); |
Sinclair Yeh | 060e2ad | 2017-03-23 14:18:32 -0700 | [diff] [blame] | 460 | |
Lee Jones | abd64e5 | 2021-01-15 18:12:37 +0000 | [diff] [blame] | 461 | vmw_connector_state_to_vcs(du->connector.state); |
Sinclair Yeh | 060e2ad | 2017-03-23 14:18:32 -0700 | [diff] [blame] | 462 | } |
| 463 | |
| 464 | |
| 465 | return ret; |
| 466 | } |
| 467 | |
| 468 | |
| 469 | /** |
| 470 | * vmw_du_cursor_plane_atomic_check - check if the new state is okay |
| 471 | * |
| 472 | * @plane: cursor plane |
Lee Jones | c88c25a | 2021-01-15 18:12:53 +0000 | [diff] [blame] | 473 | * @new_state: info on the new plane state |
Sinclair Yeh | 060e2ad | 2017-03-23 14:18:32 -0700 | [diff] [blame] | 474 | * |
| 475 | * This is a chance to fail if the new cursor state does not fit |
| 476 | * our requirements. |
| 477 | * |
| 478 | * Returns 0 on success |
| 479 | */ |
| 480 | int vmw_du_cursor_plane_atomic_check(struct drm_plane *plane, |
Maxime Ripard | 7c11b99 | 2021-02-19 13:00:24 +0100 | [diff] [blame] | 481 | struct drm_atomic_state *state) |
Sinclair Yeh | 060e2ad | 2017-03-23 14:18:32 -0700 | [diff] [blame] | 482 | { |
Maxime Ripard | 7c11b99 | 2021-02-19 13:00:24 +0100 | [diff] [blame] | 483 | struct drm_plane_state *new_state = drm_atomic_get_new_plane_state(state, |
| 484 | plane); |
Sinclair Yeh | 060e2ad | 2017-03-23 14:18:32 -0700 | [diff] [blame] | 485 | int ret = 0; |
Thomas Hellstrom | 40e3def | 2018-10-04 22:24:41 +0200 | [diff] [blame] | 486 | struct drm_crtc_state *crtc_state = NULL; |
Sinclair Yeh | 060e2ad | 2017-03-23 14:18:32 -0700 | [diff] [blame] | 487 | struct vmw_surface *surface = NULL; |
| 488 | struct drm_framebuffer *fb = new_state->fb; |
| 489 | |
Thomas Hellstrom | 40e3def | 2018-10-04 22:24:41 +0200 | [diff] [blame] | 490 | if (new_state->crtc) |
| 491 | crtc_state = drm_atomic_get_new_crtc_state(new_state->state, |
| 492 | new_state->crtc); |
| 493 | |
| 494 | ret = drm_atomic_helper_check_plane_state(new_state, crtc_state, |
| 495 | DRM_PLANE_HELPER_NO_SCALING, |
| 496 | DRM_PLANE_HELPER_NO_SCALING, |
| 497 | true, true); |
| 498 | if (ret) |
| 499 | return ret; |
Sinclair Yeh | 060e2ad | 2017-03-23 14:18:32 -0700 | [diff] [blame] | 500 | |
| 501 | /* Turning off */ |
| 502 | if (!fb) |
Thomas Hellstrom | 40e3def | 2018-10-04 22:24:41 +0200 | [diff] [blame] | 503 | return 0; |
Thomas Hellstrom | 25db875 | 2018-01-16 08:54:30 +0100 | [diff] [blame] | 504 | |
Sinclair Yeh | 060e2ad | 2017-03-23 14:18:32 -0700 | [diff] [blame] | 505 | /* A lot of the code assumes this */ |
| 506 | if (new_state->crtc_w != 64 || new_state->crtc_h != 64) { |
| 507 | DRM_ERROR("Invalid cursor dimensions (%d, %d)\n", |
| 508 | new_state->crtc_w, new_state->crtc_h); |
| 509 | ret = -EINVAL; |
| 510 | } |
| 511 | |
Thomas Hellstrom | f1d34bf | 2018-06-19 15:02:16 +0200 | [diff] [blame] | 512 | if (!vmw_framebuffer_to_vfb(fb)->bo) |
Sinclair Yeh | 060e2ad | 2017-03-23 14:18:32 -0700 | [diff] [blame] | 513 | surface = vmw_framebuffer_to_vfbs(fb)->surface; |
| 514 | |
| 515 | if (surface && !surface->snooper.image) { |
| 516 | DRM_ERROR("surface not suitable for cursor\n"); |
| 517 | ret = -EINVAL; |
| 518 | } |
| 519 | |
| 520 | return ret; |
| 521 | } |
| 522 | |
| 523 | |
Sinclair Yeh | 06ec419 | 2017-03-23 13:14:54 -0700 | [diff] [blame] | 524 | int vmw_du_crtc_atomic_check(struct drm_crtc *crtc, |
Maxime Ripard | 29b77ad | 2020-10-28 13:32:21 +0100 | [diff] [blame] | 525 | struct drm_atomic_state *state) |
Sinclair Yeh | 06ec419 | 2017-03-23 13:14:54 -0700 | [diff] [blame] | 526 | { |
Maxime Ripard | 29b77ad | 2020-10-28 13:32:21 +0100 | [diff] [blame] | 527 | struct drm_crtc_state *new_state = drm_atomic_get_new_crtc_state(state, |
| 528 | crtc); |
Sinclair Yeh | 06ec419 | 2017-03-23 13:14:54 -0700 | [diff] [blame] | 529 | struct vmw_display_unit *du = vmw_crtc_to_du(new_state->crtc); |
Ville Syrjälä | ea63272 | 2018-06-26 22:47:16 +0300 | [diff] [blame] | 530 | int connector_mask = drm_connector_mask(&du->connector); |
Sinclair Yeh | 06ec419 | 2017-03-23 13:14:54 -0700 | [diff] [blame] | 531 | bool has_primary = new_state->plane_mask & |
Ville Syrjälä | ea63272 | 2018-06-26 22:47:16 +0300 | [diff] [blame] | 532 | drm_plane_mask(crtc->primary); |
Sinclair Yeh | 06ec419 | 2017-03-23 13:14:54 -0700 | [diff] [blame] | 533 | |
| 534 | /* We always want to have an active plane with an active CRTC */ |
| 535 | if (has_primary != new_state->enable) |
| 536 | return -EINVAL; |
| 537 | |
| 538 | |
| 539 | if (new_state->connector_mask != connector_mask && |
| 540 | new_state->connector_mask != 0) { |
| 541 | DRM_ERROR("Invalid connectors configuration\n"); |
| 542 | return -EINVAL; |
| 543 | } |
| 544 | |
| 545 | /* |
| 546 | * Our virtual device does not have a dot clock, so use the logical |
| 547 | * clock value as the dot clock. |
| 548 | */ |
| 549 | if (new_state->mode.crtc_clock == 0) |
| 550 | new_state->adjusted_mode.crtc_clock = new_state->mode.clock; |
| 551 | |
| 552 | return 0; |
| 553 | } |
| 554 | |
| 555 | |
| 556 | void vmw_du_crtc_atomic_begin(struct drm_crtc *crtc, |
Maxime Ripard | f6ebe9f | 2020-10-28 13:32:22 +0100 | [diff] [blame] | 557 | struct drm_atomic_state *state) |
Sinclair Yeh | 06ec419 | 2017-03-23 13:14:54 -0700 | [diff] [blame] | 558 | { |
| 559 | } |
| 560 | |
| 561 | |
| 562 | void vmw_du_crtc_atomic_flush(struct drm_crtc *crtc, |
Maxime Ripard | f6ebe9f | 2020-10-28 13:32:22 +0100 | [diff] [blame] | 563 | struct drm_atomic_state *state) |
Sinclair Yeh | 06ec419 | 2017-03-23 13:14:54 -0700 | [diff] [blame] | 564 | { |
| 565 | struct drm_pending_vblank_event *event = crtc->state->event; |
| 566 | |
| 567 | if (event) { |
| 568 | crtc->state->event = NULL; |
| 569 | |
| 570 | spin_lock_irq(&crtc->dev->event_lock); |
Deepak Rawat | 3cbe87f | 2018-01-16 08:27:17 +0100 | [diff] [blame] | 571 | drm_crtc_send_vblank_event(crtc, event); |
Sinclair Yeh | 06ec419 | 2017-03-23 13:14:54 -0700 | [diff] [blame] | 572 | spin_unlock_irq(&crtc->dev->event_lock); |
| 573 | } |
Sinclair Yeh | 06ec419 | 2017-03-23 13:14:54 -0700 | [diff] [blame] | 574 | } |
| 575 | |
| 576 | |
Sinclair Yeh | 9c2542a | 2017-03-23 11:33:39 -0700 | [diff] [blame] | 577 | /** |
| 578 | * vmw_du_crtc_duplicate_state - duplicate crtc state |
| 579 | * @crtc: DRM crtc |
| 580 | * |
| 581 | * Allocates and returns a copy of the crtc state (both common and |
| 582 | * vmw-specific) for the specified crtc. |
| 583 | * |
| 584 | * Returns: The newly allocated crtc state, or NULL on failure. |
| 585 | */ |
| 586 | struct drm_crtc_state * |
| 587 | vmw_du_crtc_duplicate_state(struct drm_crtc *crtc) |
| 588 | { |
| 589 | struct drm_crtc_state *state; |
| 590 | struct vmw_crtc_state *vcs; |
| 591 | |
| 592 | if (WARN_ON(!crtc->state)) |
| 593 | return NULL; |
| 594 | |
| 595 | vcs = kmemdup(crtc->state, sizeof(*vcs), GFP_KERNEL); |
| 596 | |
| 597 | if (!vcs) |
| 598 | return NULL; |
| 599 | |
| 600 | state = &vcs->base; |
| 601 | |
| 602 | __drm_atomic_helper_crtc_duplicate_state(crtc, state); |
| 603 | |
| 604 | return state; |
| 605 | } |
| 606 | |
| 607 | |
| 608 | /** |
| 609 | * vmw_du_crtc_reset - creates a blank vmw crtc state |
| 610 | * @crtc: DRM crtc |
| 611 | * |
| 612 | * Resets the atomic state for @crtc by freeing the state pointer (which |
| 613 | * might be NULL, e.g. at driver load time) and allocating a new empty state |
| 614 | * object. |
| 615 | */ |
| 616 | void vmw_du_crtc_reset(struct drm_crtc *crtc) |
| 617 | { |
| 618 | struct vmw_crtc_state *vcs; |
| 619 | |
| 620 | |
| 621 | if (crtc->state) { |
| 622 | __drm_atomic_helper_crtc_destroy_state(crtc->state); |
| 623 | |
| 624 | kfree(vmw_crtc_state_to_vcs(crtc->state)); |
| 625 | } |
| 626 | |
| 627 | vcs = kzalloc(sizeof(*vcs), GFP_KERNEL); |
| 628 | |
| 629 | if (!vcs) { |
| 630 | DRM_ERROR("Cannot allocate vmw_crtc_state\n"); |
| 631 | return; |
| 632 | } |
| 633 | |
Daniel Vetter | a164347 | 2020-06-12 22:49:40 +0200 | [diff] [blame] | 634 | __drm_atomic_helper_crtc_reset(crtc, &vcs->base); |
Sinclair Yeh | 9c2542a | 2017-03-23 11:33:39 -0700 | [diff] [blame] | 635 | } |
| 636 | |
| 637 | |
| 638 | /** |
| 639 | * vmw_du_crtc_destroy_state - destroy crtc state |
| 640 | * @crtc: DRM crtc |
| 641 | * @state: state object to destroy |
| 642 | * |
| 643 | * Destroys the crtc state (both common and vmw-specific) for the |
| 644 | * specified plane. |
| 645 | */ |
| 646 | void |
| 647 | vmw_du_crtc_destroy_state(struct drm_crtc *crtc, |
| 648 | struct drm_crtc_state *state) |
| 649 | { |
| 650 | drm_atomic_helper_crtc_destroy_state(crtc, state); |
| 651 | } |
| 652 | |
| 653 | |
Sinclair Yeh | cc5ec45 | 2017-03-23 11:36:05 -0700 | [diff] [blame] | 654 | /** |
| 655 | * vmw_du_plane_duplicate_state - duplicate plane state |
| 656 | * @plane: drm plane |
| 657 | * |
| 658 | * Allocates and returns a copy of the plane state (both common and |
| 659 | * vmw-specific) for the specified plane. |
| 660 | * |
| 661 | * Returns: The newly allocated plane state, or NULL on failure. |
| 662 | */ |
| 663 | struct drm_plane_state * |
| 664 | vmw_du_plane_duplicate_state(struct drm_plane *plane) |
| 665 | { |
| 666 | struct drm_plane_state *state; |
| 667 | struct vmw_plane_state *vps; |
| 668 | |
| 669 | vps = kmemdup(plane->state, sizeof(*vps), GFP_KERNEL); |
| 670 | |
| 671 | if (!vps) |
| 672 | return NULL; |
| 673 | |
| 674 | vps->pinned = 0; |
Sinclair Yeh | 810b3e16 | 2017-03-23 15:39:16 -0700 | [diff] [blame] | 675 | vps->cpp = 0; |
| 676 | |
Sinclair Yeh | cc5ec45 | 2017-03-23 11:36:05 -0700 | [diff] [blame] | 677 | /* Each ref counted resource needs to be acquired again */ |
| 678 | if (vps->surf) |
| 679 | (void) vmw_surface_reference(vps->surf); |
| 680 | |
Thomas Hellstrom | f1d34bf | 2018-06-19 15:02:16 +0200 | [diff] [blame] | 681 | if (vps->bo) |
| 682 | (void) vmw_bo_reference(vps->bo); |
Sinclair Yeh | cc5ec45 | 2017-03-23 11:36:05 -0700 | [diff] [blame] | 683 | |
| 684 | state = &vps->base; |
| 685 | |
| 686 | __drm_atomic_helper_plane_duplicate_state(plane, state); |
| 687 | |
| 688 | return state; |
| 689 | } |
| 690 | |
| 691 | |
| 692 | /** |
| 693 | * vmw_du_plane_reset - creates a blank vmw plane state |
| 694 | * @plane: drm plane |
| 695 | * |
| 696 | * Resets the atomic state for @plane by freeing the state pointer (which might |
| 697 | * be NULL, e.g. at driver load time) and allocating a new empty state object. |
| 698 | */ |
| 699 | void vmw_du_plane_reset(struct drm_plane *plane) |
| 700 | { |
| 701 | struct vmw_plane_state *vps; |
| 702 | |
| 703 | |
| 704 | if (plane->state) |
| 705 | vmw_du_plane_destroy_state(plane, plane->state); |
| 706 | |
| 707 | vps = kzalloc(sizeof(*vps), GFP_KERNEL); |
| 708 | |
| 709 | if (!vps) { |
| 710 | DRM_ERROR("Cannot allocate vmw_plane_state\n"); |
| 711 | return; |
| 712 | } |
| 713 | |
Alexandru Gheorghe | e81eb98 | 2018-08-04 17:15:30 +0100 | [diff] [blame] | 714 | __drm_atomic_helper_plane_reset(plane, &vps->base); |
Sinclair Yeh | cc5ec45 | 2017-03-23 11:36:05 -0700 | [diff] [blame] | 715 | } |
| 716 | |
| 717 | |
| 718 | /** |
| 719 | * vmw_du_plane_destroy_state - destroy plane state |
| 720 | * @plane: DRM plane |
| 721 | * @state: state object to destroy |
| 722 | * |
| 723 | * Destroys the plane state (both common and vmw-specific) for the |
| 724 | * specified plane. |
| 725 | */ |
| 726 | void |
| 727 | vmw_du_plane_destroy_state(struct drm_plane *plane, |
| 728 | struct drm_plane_state *state) |
| 729 | { |
| 730 | struct vmw_plane_state *vps = vmw_plane_state_to_vps(state); |
| 731 | |
| 732 | |
Sinclair Yeh | 810b3e16 | 2017-03-23 15:39:16 -0700 | [diff] [blame] | 733 | /* Should have been freed by cleanup_fb */ |
Sinclair Yeh | cc5ec45 | 2017-03-23 11:36:05 -0700 | [diff] [blame] | 734 | if (vps->surf) |
| 735 | vmw_surface_unreference(&vps->surf); |
| 736 | |
Thomas Hellstrom | f1d34bf | 2018-06-19 15:02:16 +0200 | [diff] [blame] | 737 | if (vps->bo) |
| 738 | vmw_bo_unreference(&vps->bo); |
Sinclair Yeh | cc5ec45 | 2017-03-23 11:36:05 -0700 | [diff] [blame] | 739 | |
| 740 | drm_atomic_helper_plane_destroy_state(plane, state); |
| 741 | } |
| 742 | |
| 743 | |
Sinclair Yeh | d7721ca | 2017-03-23 11:48:44 -0700 | [diff] [blame] | 744 | /** |
| 745 | * vmw_du_connector_duplicate_state - duplicate connector state |
| 746 | * @connector: DRM connector |
| 747 | * |
| 748 | * Allocates and returns a copy of the connector state (both common and |
| 749 | * vmw-specific) for the specified connector. |
| 750 | * |
| 751 | * Returns: The newly allocated connector state, or NULL on failure. |
| 752 | */ |
| 753 | struct drm_connector_state * |
| 754 | vmw_du_connector_duplicate_state(struct drm_connector *connector) |
| 755 | { |
| 756 | struct drm_connector_state *state; |
| 757 | struct vmw_connector_state *vcs; |
| 758 | |
| 759 | if (WARN_ON(!connector->state)) |
| 760 | return NULL; |
| 761 | |
| 762 | vcs = kmemdup(connector->state, sizeof(*vcs), GFP_KERNEL); |
| 763 | |
| 764 | if (!vcs) |
| 765 | return NULL; |
| 766 | |
| 767 | state = &vcs->base; |
| 768 | |
| 769 | __drm_atomic_helper_connector_duplicate_state(connector, state); |
| 770 | |
| 771 | return state; |
| 772 | } |
| 773 | |
| 774 | |
| 775 | /** |
| 776 | * vmw_du_connector_reset - creates a blank vmw connector state |
| 777 | * @connector: DRM connector |
| 778 | * |
| 779 | * Resets the atomic state for @connector by freeing the state pointer (which |
| 780 | * might be NULL, e.g. at driver load time) and allocating a new empty state |
| 781 | * object. |
| 782 | */ |
| 783 | void vmw_du_connector_reset(struct drm_connector *connector) |
| 784 | { |
| 785 | struct vmw_connector_state *vcs; |
| 786 | |
| 787 | |
| 788 | if (connector->state) { |
| 789 | __drm_atomic_helper_connector_destroy_state(connector->state); |
| 790 | |
| 791 | kfree(vmw_connector_state_to_vcs(connector->state)); |
| 792 | } |
| 793 | |
| 794 | vcs = kzalloc(sizeof(*vcs), GFP_KERNEL); |
| 795 | |
| 796 | if (!vcs) { |
| 797 | DRM_ERROR("Cannot allocate vmw_connector_state\n"); |
| 798 | return; |
| 799 | } |
| 800 | |
| 801 | __drm_atomic_helper_connector_reset(connector, &vcs->base); |
| 802 | } |
| 803 | |
| 804 | |
| 805 | /** |
| 806 | * vmw_du_connector_destroy_state - destroy connector state |
| 807 | * @connector: DRM connector |
| 808 | * @state: state object to destroy |
| 809 | * |
| 810 | * Destroys the connector state (both common and vmw-specific) for the |
| 811 | * specified plane. |
| 812 | */ |
| 813 | void |
| 814 | vmw_du_connector_destroy_state(struct drm_connector *connector, |
| 815 | struct drm_connector_state *state) |
| 816 | { |
| 817 | drm_atomic_helper_connector_destroy_state(connector, state); |
| 818 | } |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 819 | /* |
| 820 | * Generic framebuffer code |
| 821 | */ |
| 822 | |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 823 | /* |
| 824 | * Surface framebuffer code |
| 825 | */ |
| 826 | |
Rashika Kheria | 847c596 | 2014-01-06 22:18:10 +0530 | [diff] [blame] | 827 | static void vmw_framebuffer_surface_destroy(struct drm_framebuffer *framebuffer) |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 828 | { |
Thomas Hellstrom | 3a939a5 | 2010-10-05 12:43:03 +0200 | [diff] [blame] | 829 | struct vmw_framebuffer_surface *vfbs = |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 830 | vmw_framebuffer_to_vfbs(framebuffer); |
| 831 | |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 832 | drm_framebuffer_cleanup(framebuffer); |
Thomas Hellstrom | 3a939a5 | 2010-10-05 12:43:03 +0200 | [diff] [blame] | 833 | vmw_surface_unreference(&vfbs->surface); |
Thomas Hellstrom | a278724 | 2015-06-29 12:55:07 -0700 | [diff] [blame] | 834 | if (vfbs->base.user_obj) |
| 835 | ttm_base_object_unref(&vfbs->base.user_obj); |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 836 | |
Thomas Hellstrom | 3a939a5 | 2010-10-05 12:43:03 +0200 | [diff] [blame] | 837 | kfree(vfbs); |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 838 | } |
| 839 | |
Thomas Hellstrom | 10b1e0c | 2015-06-26 02:14:27 -0700 | [diff] [blame] | 840 | /** |
| 841 | * vmw_kms_readback - Perform a readback from the screen system to |
Thomas Hellstrom | f1d34bf | 2018-06-19 15:02:16 +0200 | [diff] [blame] | 842 | * a buffer-object backed framebuffer. |
Thomas Hellstrom | 10b1e0c | 2015-06-26 02:14:27 -0700 | [diff] [blame] | 843 | * |
| 844 | * @dev_priv: Pointer to the device private structure. |
| 845 | * @file_priv: Pointer to a struct drm_file identifying the caller. |
| 846 | * Must be set to NULL if @user_fence_rep is NULL. |
Thomas Hellstrom | f1d34bf | 2018-06-19 15:02:16 +0200 | [diff] [blame] | 847 | * @vfb: Pointer to the buffer-object backed framebuffer. |
Thomas Hellstrom | 10b1e0c | 2015-06-26 02:14:27 -0700 | [diff] [blame] | 848 | * @user_fence_rep: User-space provided structure for fence information. |
| 849 | * Must be set to non-NULL if @file_priv is non-NULL. |
| 850 | * @vclips: Array of clip rects. |
| 851 | * @num_clips: Number of clip rects in @vclips. |
| 852 | * |
| 853 | * Returns 0 on success, negative error code on failure. -ERESTARTSYS if |
| 854 | * interrupted. |
| 855 | */ |
| 856 | int vmw_kms_readback(struct vmw_private *dev_priv, |
| 857 | struct drm_file *file_priv, |
| 858 | struct vmw_framebuffer *vfb, |
| 859 | struct drm_vmw_fence_rep __user *user_fence_rep, |
| 860 | struct drm_vmw_rect *vclips, |
| 861 | uint32_t num_clips) |
| 862 | { |
| 863 | switch (dev_priv->active_display_unit) { |
| 864 | case vmw_du_screen_object: |
| 865 | return vmw_kms_sou_readback(dev_priv, file_priv, vfb, |
Deepak Rawat | 91e9f35 | 2018-01-16 08:24:17 +0100 | [diff] [blame] | 866 | user_fence_rep, vclips, num_clips, |
| 867 | NULL); |
Thomas Hellstrom | 6bf6bf0 | 2015-06-26 02:22:40 -0700 | [diff] [blame] | 868 | case vmw_du_screen_target: |
| 869 | return vmw_kms_stdu_dma(dev_priv, file_priv, vfb, |
| 870 | user_fence_rep, NULL, vclips, num_clips, |
Deepak Rawat | 91e9f35 | 2018-01-16 08:24:17 +0100 | [diff] [blame] | 871 | 1, false, true, NULL); |
Thomas Hellstrom | 10b1e0c | 2015-06-26 02:14:27 -0700 | [diff] [blame] | 872 | default: |
| 873 | WARN_ONCE(true, |
| 874 | "Readback called with invalid display system.\n"); |
Thomas Hellstrom | 6bf6bf0 | 2015-06-26 02:22:40 -0700 | [diff] [blame] | 875 | } |
Thomas Hellstrom | 10b1e0c | 2015-06-26 02:14:27 -0700 | [diff] [blame] | 876 | |
| 877 | return -ENOSYS; |
| 878 | } |
| 879 | |
| 880 | |
Ville Syrjälä | d7955fc | 2015-12-15 12:21:15 +0100 | [diff] [blame] | 881 | static const struct drm_framebuffer_funcs vmw_framebuffer_surface_funcs = { |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 882 | .destroy = vmw_framebuffer_surface_destroy, |
Deepak Rawat | 2f5544f | 2018-09-21 14:34:02 -0700 | [diff] [blame] | 883 | .dirty = drm_atomic_helper_dirtyfb, |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 884 | }; |
| 885 | |
Thomas Hellstrom | d3216a0 | 2010-10-05 12:42:59 +0200 | [diff] [blame] | 886 | static int vmw_kms_new_framebuffer_surface(struct vmw_private *dev_priv, |
| 887 | struct vmw_surface *surface, |
| 888 | struct vmw_framebuffer **out, |
Daniel Vetter | dabdcdc | 2016-12-02 08:07:40 +0100 | [diff] [blame] | 889 | const struct drm_mode_fb_cmd2 |
Sinclair Yeh | f89c6c3 | 2015-06-26 01:54:28 -0700 | [diff] [blame] | 890 | *mode_cmd, |
Thomas Hellstrom | f1d34bf | 2018-06-19 15:02:16 +0200 | [diff] [blame] | 891 | bool is_bo_proxy) |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 892 | |
| 893 | { |
Zack Rusin | 9703bb3 | 2020-11-03 22:21:34 -0500 | [diff] [blame] | 894 | struct drm_device *dev = &dev_priv->drm; |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 895 | struct vmw_framebuffer_surface *vfbs; |
Thomas Hellstrom | d3216a0 | 2010-10-05 12:42:59 +0200 | [diff] [blame] | 896 | enum SVGA3dSurfaceFormat format; |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 897 | int ret; |
| 898 | |
Sinclair Yeh | c8261a9 | 2015-06-26 01:23:42 -0700 | [diff] [blame] | 899 | /* 3D is only supported on HWv8 and newer hosts */ |
| 900 | if (dev_priv->active_display_unit == vmw_du_legacy) |
Jakob Bornecrantz | 01e8141 | 2011-10-04 20:13:24 +0200 | [diff] [blame] | 901 | return -ENOSYS; |
| 902 | |
Thomas Hellstrom | d3216a0 | 2010-10-05 12:42:59 +0200 | [diff] [blame] | 903 | /* |
| 904 | * Sanity checks. |
| 905 | */ |
| 906 | |
Jakob Bornecrantz | e7ac921 | 2011-11-28 13:19:12 +0100 | [diff] [blame] | 907 | /* Surface must be marked as a scanout. */ |
Deepak Rawat | 26b8287 | 2019-04-29 11:42:45 -0700 | [diff] [blame] | 908 | if (unlikely(!surface->metadata.scanout)) |
Jakob Bornecrantz | e7ac921 | 2011-11-28 13:19:12 +0100 | [diff] [blame] | 909 | return -EINVAL; |
| 910 | |
Deepak Rawat | 26b8287 | 2019-04-29 11:42:45 -0700 | [diff] [blame] | 911 | if (unlikely(surface->metadata.mip_levels[0] != 1 || |
| 912 | surface->metadata.num_sizes != 1 || |
| 913 | surface->metadata.base_size.width < mode_cmd->width || |
| 914 | surface->metadata.base_size.height < mode_cmd->height || |
| 915 | surface->metadata.base_size.depth != 1)) { |
Thomas Hellstrom | d3216a0 | 2010-10-05 12:42:59 +0200 | [diff] [blame] | 916 | DRM_ERROR("Incompatible surface dimensions " |
| 917 | "for requested mode.\n"); |
| 918 | return -EINVAL; |
| 919 | } |
| 920 | |
Daniel Vetter | dabdcdc | 2016-12-02 08:07:40 +0100 | [diff] [blame] | 921 | switch (mode_cmd->pixel_format) { |
| 922 | case DRM_FORMAT_ARGB8888: |
Thomas Hellstrom | d3216a0 | 2010-10-05 12:42:59 +0200 | [diff] [blame] | 923 | format = SVGA3D_A8R8G8B8; |
| 924 | break; |
Daniel Vetter | dabdcdc | 2016-12-02 08:07:40 +0100 | [diff] [blame] | 925 | case DRM_FORMAT_XRGB8888: |
Thomas Hellstrom | d3216a0 | 2010-10-05 12:42:59 +0200 | [diff] [blame] | 926 | format = SVGA3D_X8R8G8B8; |
| 927 | break; |
Daniel Vetter | dabdcdc | 2016-12-02 08:07:40 +0100 | [diff] [blame] | 928 | case DRM_FORMAT_RGB565: |
Thomas Hellstrom | d3216a0 | 2010-10-05 12:42:59 +0200 | [diff] [blame] | 929 | format = SVGA3D_R5G6B5; |
| 930 | break; |
Daniel Vetter | dabdcdc | 2016-12-02 08:07:40 +0100 | [diff] [blame] | 931 | case DRM_FORMAT_XRGB1555: |
Thomas Hellstrom | d3216a0 | 2010-10-05 12:42:59 +0200 | [diff] [blame] | 932 | format = SVGA3D_A1R5G5B5; |
| 933 | break; |
| 934 | default: |
Sakari Ailus | 92f1d09 | 2021-02-16 17:57:22 +0200 | [diff] [blame] | 935 | DRM_ERROR("Invalid pixel format: %p4cc\n", |
| 936 | &mode_cmd->pixel_format); |
Thomas Hellstrom | d3216a0 | 2010-10-05 12:42:59 +0200 | [diff] [blame] | 937 | return -EINVAL; |
| 938 | } |
| 939 | |
Thomas Hellstrom | d80efd5 | 2015-08-10 10:39:35 -0700 | [diff] [blame] | 940 | /* |
| 941 | * For DX, surface format validation is done when surface->scanout |
| 942 | * is set. |
| 943 | */ |
Deepak Rawat | 26b8287 | 2019-04-29 11:42:45 -0700 | [diff] [blame] | 944 | if (!has_sm4_context(dev_priv) && format != surface->metadata.format) { |
Thomas Hellstrom | d3216a0 | 2010-10-05 12:42:59 +0200 | [diff] [blame] | 945 | DRM_ERROR("Invalid surface format for requested mode.\n"); |
| 946 | return -EINVAL; |
| 947 | } |
| 948 | |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 949 | vfbs = kzalloc(sizeof(*vfbs), GFP_KERNEL); |
| 950 | if (!vfbs) { |
| 951 | ret = -ENOMEM; |
| 952 | goto out_err1; |
| 953 | } |
| 954 | |
Ville Syrjälä | a3f913c | 2016-12-14 22:48:59 +0200 | [diff] [blame] | 955 | drm_helper_mode_fill_fb_struct(dev, &vfbs->base.base, mode_cmd); |
Sinclair Yeh | 05c9501 | 2015-08-11 22:53:39 -0700 | [diff] [blame] | 956 | vfbs->surface = vmw_surface_reference(surface); |
Daniel Vetter | dabdcdc | 2016-12-02 08:07:40 +0100 | [diff] [blame] | 957 | vfbs->base.user_handle = mode_cmd->handles[0]; |
Thomas Hellstrom | f1d34bf | 2018-06-19 15:02:16 +0200 | [diff] [blame] | 958 | vfbs->is_bo_proxy = is_bo_proxy; |
Thomas Hellstrom | 3a939a5 | 2010-10-05 12:43:03 +0200 | [diff] [blame] | 959 | |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 960 | *out = &vfbs->base; |
| 961 | |
Daniel Vetter | 80f0b5a | 2012-12-13 23:39:01 +0100 | [diff] [blame] | 962 | ret = drm_framebuffer_init(dev, &vfbs->base.base, |
| 963 | &vmw_framebuffer_surface_funcs); |
| 964 | if (ret) |
Sinclair Yeh | 05c9501 | 2015-08-11 22:53:39 -0700 | [diff] [blame] | 965 | goto out_err2; |
Daniel Vetter | 80f0b5a | 2012-12-13 23:39:01 +0100 | [diff] [blame] | 966 | |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 967 | return 0; |
| 968 | |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 969 | out_err2: |
Sinclair Yeh | 05c9501 | 2015-08-11 22:53:39 -0700 | [diff] [blame] | 970 | vmw_surface_unreference(&surface); |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 971 | kfree(vfbs); |
| 972 | out_err1: |
| 973 | return ret; |
| 974 | } |
| 975 | |
| 976 | /* |
Thomas Hellstrom | f1d34bf | 2018-06-19 15:02:16 +0200 | [diff] [blame] | 977 | * Buffer-object framebuffer code |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 978 | */ |
| 979 | |
Thomas Hellstrom | f1d34bf | 2018-06-19 15:02:16 +0200 | [diff] [blame] | 980 | static void vmw_framebuffer_bo_destroy(struct drm_framebuffer *framebuffer) |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 981 | { |
Thomas Hellstrom | f1d34bf | 2018-06-19 15:02:16 +0200 | [diff] [blame] | 982 | struct vmw_framebuffer_bo *vfbd = |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 983 | vmw_framebuffer_to_vfbd(framebuffer); |
| 984 | |
| 985 | drm_framebuffer_cleanup(framebuffer); |
Thomas Hellstrom | f1d34bf | 2018-06-19 15:02:16 +0200 | [diff] [blame] | 986 | vmw_bo_unreference(&vfbd->buffer); |
Thomas Hellstrom | a278724 | 2015-06-29 12:55:07 -0700 | [diff] [blame] | 987 | if (vfbd->base.user_obj) |
| 988 | ttm_base_object_unref(&vfbd->base.user_obj); |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 989 | |
| 990 | kfree(vfbd); |
| 991 | } |
| 992 | |
Thomas Hellstrom | f1d34bf | 2018-06-19 15:02:16 +0200 | [diff] [blame] | 993 | static int vmw_framebuffer_bo_dirty(struct drm_framebuffer *framebuffer, |
| 994 | struct drm_file *file_priv, |
| 995 | unsigned int flags, unsigned int color, |
| 996 | struct drm_clip_rect *clips, |
| 997 | unsigned int num_clips) |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 998 | { |
| 999 | struct vmw_private *dev_priv = vmw_priv(framebuffer->dev); |
Thomas Hellstrom | f1d34bf | 2018-06-19 15:02:16 +0200 | [diff] [blame] | 1000 | struct vmw_framebuffer_bo *vfbd = |
Jakob Bornecrantz | 5deb65c | 2011-10-04 20:13:18 +0200 | [diff] [blame] | 1001 | vmw_framebuffer_to_vfbd(framebuffer); |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 1002 | struct drm_clip_rect norect; |
Jakob Bornecrantz | 5deb65c | 2011-10-04 20:13:18 +0200 | [diff] [blame] | 1003 | int ret, increment = 1; |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 1004 | |
Zack Rusin | 9703bb3 | 2020-11-03 22:21:34 -0500 | [diff] [blame] | 1005 | drm_modeset_lock_all(&dev_priv->drm); |
Ville Syrjälä | 73e9efd | 2013-12-04 14:13:58 +0200 | [diff] [blame] | 1006 | |
Thomas Hellstrom | 294adf7 | 2014-02-27 12:34:51 +0100 | [diff] [blame] | 1007 | ret = ttm_read_lock(&dev_priv->reservation_sem, true); |
Ville Syrjälä | 73e9efd | 2013-12-04 14:13:58 +0200 | [diff] [blame] | 1008 | if (unlikely(ret != 0)) { |
Zack Rusin | 9703bb3 | 2020-11-03 22:21:34 -0500 | [diff] [blame] | 1009 | drm_modeset_unlock_all(&dev_priv->drm); |
Thomas Hellstrom | 3a939a5 | 2010-10-05 12:43:03 +0200 | [diff] [blame] | 1010 | return ret; |
Ville Syrjälä | 73e9efd | 2013-12-04 14:13:58 +0200 | [diff] [blame] | 1011 | } |
Thomas Hellstrom | 3a939a5 | 2010-10-05 12:43:03 +0200 | [diff] [blame] | 1012 | |
Thomas Hellstrom | df1c93b | 2010-01-13 22:28:36 +0100 | [diff] [blame] | 1013 | if (!num_clips) { |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 1014 | num_clips = 1; |
| 1015 | clips = &norect; |
| 1016 | norect.x1 = norect.y1 = 0; |
| 1017 | norect.x2 = framebuffer->width; |
| 1018 | norect.y2 = framebuffer->height; |
| 1019 | } else if (flags & DRM_MODE_FB_DIRTY_ANNOTATE_COPY) { |
| 1020 | num_clips /= 2; |
| 1021 | increment = 2; |
| 1022 | } |
| 1023 | |
Thomas Hellstrom | 6bf6bf0 | 2015-06-26 02:22:40 -0700 | [diff] [blame] | 1024 | switch (dev_priv->active_display_unit) { |
Thomas Hellstrom | 352b20dc | 2015-06-29 12:57:37 -0700 | [diff] [blame] | 1025 | case vmw_du_legacy: |
Thomas Hellstrom | f1d34bf | 2018-06-19 15:02:16 +0200 | [diff] [blame] | 1026 | ret = vmw_kms_ldu_do_bo_dirty(dev_priv, &vfbd->base, 0, 0, |
| 1027 | clips, num_clips, increment); |
Thomas Hellstrom | 352b20dc | 2015-06-29 12:57:37 -0700 | [diff] [blame] | 1028 | break; |
Thomas Hellstrom | 6bf6bf0 | 2015-06-26 02:22:40 -0700 | [diff] [blame] | 1029 | default: |
Thomas Hellstrom | 352b20dc | 2015-06-29 12:57:37 -0700 | [diff] [blame] | 1030 | ret = -EINVAL; |
| 1031 | WARN_ONCE(true, "Dirty called with invalid display system.\n"); |
Thomas Hellstrom | 6bf6bf0 | 2015-06-26 02:22:40 -0700 | [diff] [blame] | 1032 | break; |
Jakob Bornecrantz | 56d1c78 | 2011-10-04 20:13:22 +0200 | [diff] [blame] | 1033 | } |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 1034 | |
Zack Rusin | 8426ed9 | 2020-11-18 12:54:19 -0500 | [diff] [blame] | 1035 | vmw_cmd_flush(dev_priv, false); |
Thomas Hellstrom | 294adf7 | 2014-02-27 12:34:51 +0100 | [diff] [blame] | 1036 | ttm_read_unlock(&dev_priv->reservation_sem); |
Ville Syrjälä | 73e9efd | 2013-12-04 14:13:58 +0200 | [diff] [blame] | 1037 | |
Zack Rusin | 9703bb3 | 2020-11-03 22:21:34 -0500 | [diff] [blame] | 1038 | drm_modeset_unlock_all(&dev_priv->drm); |
Ville Syrjälä | 73e9efd | 2013-12-04 14:13:58 +0200 | [diff] [blame] | 1039 | |
Jakob Bornecrantz | 5deb65c | 2011-10-04 20:13:18 +0200 | [diff] [blame] | 1040 | return ret; |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 1041 | } |
| 1042 | |
Deepak Rawat | 2f5544f | 2018-09-21 14:34:02 -0700 | [diff] [blame] | 1043 | static int vmw_framebuffer_bo_dirty_ext(struct drm_framebuffer *framebuffer, |
| 1044 | struct drm_file *file_priv, |
| 1045 | unsigned int flags, unsigned int color, |
| 1046 | struct drm_clip_rect *clips, |
| 1047 | unsigned int num_clips) |
| 1048 | { |
| 1049 | struct vmw_private *dev_priv = vmw_priv(framebuffer->dev); |
| 1050 | |
| 1051 | if (dev_priv->active_display_unit == vmw_du_legacy) |
| 1052 | return vmw_framebuffer_bo_dirty(framebuffer, file_priv, flags, |
| 1053 | color, clips, num_clips); |
| 1054 | |
| 1055 | return drm_atomic_helper_dirtyfb(framebuffer, file_priv, flags, color, |
| 1056 | clips, num_clips); |
| 1057 | } |
| 1058 | |
Thomas Hellstrom | f1d34bf | 2018-06-19 15:02:16 +0200 | [diff] [blame] | 1059 | static const struct drm_framebuffer_funcs vmw_framebuffer_bo_funcs = { |
| 1060 | .destroy = vmw_framebuffer_bo_destroy, |
Deepak Rawat | 2f5544f | 2018-09-21 14:34:02 -0700 | [diff] [blame] | 1061 | .dirty = vmw_framebuffer_bo_dirty_ext, |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 1062 | }; |
| 1063 | |
Lee Jones | c88c25a | 2021-01-15 18:12:53 +0000 | [diff] [blame] | 1064 | /* |
Thomas Hellstrom | f1d34bf | 2018-06-19 15:02:16 +0200 | [diff] [blame] | 1065 | * Pin the bofer in a location suitable for access by the |
Thomas Hellstrom | ef86cfe | 2018-01-16 11:07:30 +0100 | [diff] [blame] | 1066 | * display system. |
Jakob Bornecrantz | 497a3ff | 2011-10-04 20:13:14 +0200 | [diff] [blame] | 1067 | */ |
Thomas Hellstrom | fd006a4 | 2015-06-28 02:50:56 -0700 | [diff] [blame] | 1068 | static int vmw_framebuffer_pin(struct vmw_framebuffer *vfb) |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 1069 | { |
| 1070 | struct vmw_private *dev_priv = vmw_priv(vfb->base.dev); |
Thomas Hellstrom | f1d34bf | 2018-06-19 15:02:16 +0200 | [diff] [blame] | 1071 | struct vmw_buffer_object *buf; |
Thomas Hellstrom | ef86cfe | 2018-01-16 11:07:30 +0100 | [diff] [blame] | 1072 | struct ttm_placement *placement; |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 1073 | int ret; |
| 1074 | |
Thomas Hellstrom | f1d34bf | 2018-06-19 15:02:16 +0200 | [diff] [blame] | 1075 | buf = vfb->bo ? vmw_framebuffer_to_vfbd(&vfb->base)->buffer : |
Thomas Hellstrom | fd006a4 | 2015-06-28 02:50:56 -0700 | [diff] [blame] | 1076 | vmw_framebuffer_to_vfbs(&vfb->base)->surface->res.backup; |
Jakob Bornecrantz | d7e1958 | 2010-05-28 11:21:59 +0200 | [diff] [blame] | 1077 | |
Thomas Hellstrom | fd006a4 | 2015-06-28 02:50:56 -0700 | [diff] [blame] | 1078 | if (!buf) |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 1079 | return 0; |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 1080 | |
Thomas Hellstrom | fd006a4 | 2015-06-28 02:50:56 -0700 | [diff] [blame] | 1081 | switch (dev_priv->active_display_unit) { |
| 1082 | case vmw_du_legacy: |
| 1083 | vmw_overlay_pause_all(dev_priv); |
Thomas Hellstrom | f1d34bf | 2018-06-19 15:02:16 +0200 | [diff] [blame] | 1084 | ret = vmw_bo_pin_in_start_of_vram(dev_priv, buf, false); |
Thomas Hellstrom | fd006a4 | 2015-06-28 02:50:56 -0700 | [diff] [blame] | 1085 | vmw_overlay_resume_all(dev_priv); |
| 1086 | break; |
| 1087 | case vmw_du_screen_object: |
| 1088 | case vmw_du_screen_target: |
Thomas Hellstrom | f1d34bf | 2018-06-19 15:02:16 +0200 | [diff] [blame] | 1089 | if (vfb->bo) { |
Thomas Hellstrom | ef86cfe | 2018-01-16 11:07:30 +0100 | [diff] [blame] | 1090 | if (dev_priv->capabilities & SVGA_CAP_3D) { |
| 1091 | /* |
| 1092 | * Use surface DMA to get content to |
| 1093 | * sreen target surface. |
| 1094 | */ |
| 1095 | placement = &vmw_vram_gmr_placement; |
| 1096 | } else { |
| 1097 | /* Use CPU blit. */ |
| 1098 | placement = &vmw_sys_placement; |
| 1099 | } |
| 1100 | } else { |
| 1101 | /* Use surface / image update */ |
| 1102 | placement = &vmw_mob_placement; |
| 1103 | } |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 1104 | |
Thomas Hellstrom | f1d34bf | 2018-06-19 15:02:16 +0200 | [diff] [blame] | 1105 | return vmw_bo_pin_in_placement(dev_priv, buf, placement, false); |
Thomas Hellstrom | fd006a4 | 2015-06-28 02:50:56 -0700 | [diff] [blame] | 1106 | default: |
| 1107 | return -EINVAL; |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 1108 | } |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 1109 | |
Thomas Hellstrom | fd006a4 | 2015-06-28 02:50:56 -0700 | [diff] [blame] | 1110 | return ret; |
| 1111 | } |
| 1112 | |
| 1113 | static int vmw_framebuffer_unpin(struct vmw_framebuffer *vfb) |
| 1114 | { |
| 1115 | struct vmw_private *dev_priv = vmw_priv(vfb->base.dev); |
Thomas Hellstrom | f1d34bf | 2018-06-19 15:02:16 +0200 | [diff] [blame] | 1116 | struct vmw_buffer_object *buf; |
Thomas Hellstrom | fd006a4 | 2015-06-28 02:50:56 -0700 | [diff] [blame] | 1117 | |
Thomas Hellstrom | f1d34bf | 2018-06-19 15:02:16 +0200 | [diff] [blame] | 1118 | buf = vfb->bo ? vmw_framebuffer_to_vfbd(&vfb->base)->buffer : |
Thomas Hellstrom | fd006a4 | 2015-06-28 02:50:56 -0700 | [diff] [blame] | 1119 | vmw_framebuffer_to_vfbs(&vfb->base)->surface->res.backup; |
| 1120 | |
| 1121 | if (WARN_ON(!buf)) |
| 1122 | return 0; |
| 1123 | |
Thomas Hellstrom | f1d34bf | 2018-06-19 15:02:16 +0200 | [diff] [blame] | 1124 | return vmw_bo_unpin(dev_priv, buf, false); |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 1125 | } |
| 1126 | |
Sinclair Yeh | f89c6c3 | 2015-06-26 01:54:28 -0700 | [diff] [blame] | 1127 | /** |
Thomas Hellstrom | f1d34bf | 2018-06-19 15:02:16 +0200 | [diff] [blame] | 1128 | * vmw_create_bo_proxy - create a proxy surface for the buffer object |
Sinclair Yeh | f89c6c3 | 2015-06-26 01:54:28 -0700 | [diff] [blame] | 1129 | * |
| 1130 | * @dev: DRM device |
| 1131 | * @mode_cmd: parameters for the new surface |
Thomas Hellstrom | f1d34bf | 2018-06-19 15:02:16 +0200 | [diff] [blame] | 1132 | * @bo_mob: MOB backing the buffer object |
Sinclair Yeh | f89c6c3 | 2015-06-26 01:54:28 -0700 | [diff] [blame] | 1133 | * @srf_out: newly created surface |
| 1134 | * |
Thomas Hellstrom | f1d34bf | 2018-06-19 15:02:16 +0200 | [diff] [blame] | 1135 | * When the content FB is a buffer object, we create a surface as a proxy to the |
Sinclair Yeh | f89c6c3 | 2015-06-26 01:54:28 -0700 | [diff] [blame] | 1136 | * same buffer. This way we can do a surface copy rather than a surface DMA. |
| 1137 | * This is a more efficient approach |
| 1138 | * |
| 1139 | * RETURNS: |
| 1140 | * 0 on success, error code otherwise |
| 1141 | */ |
Thomas Hellstrom | f1d34bf | 2018-06-19 15:02:16 +0200 | [diff] [blame] | 1142 | static int vmw_create_bo_proxy(struct drm_device *dev, |
| 1143 | const struct drm_mode_fb_cmd2 *mode_cmd, |
| 1144 | struct vmw_buffer_object *bo_mob, |
| 1145 | struct vmw_surface **srf_out) |
Sinclair Yeh | f89c6c3 | 2015-06-26 01:54:28 -0700 | [diff] [blame] | 1146 | { |
Deepak Rawat | 504901d | 2019-04-29 14:55:44 -0700 | [diff] [blame] | 1147 | struct vmw_surface_metadata metadata = {0}; |
Sinclair Yeh | f89c6c3 | 2015-06-26 01:54:28 -0700 | [diff] [blame] | 1148 | uint32_t format; |
Thomas Hellstrom | 6bf6bf0 | 2015-06-26 02:22:40 -0700 | [diff] [blame] | 1149 | struct vmw_resource *res; |
Thomas Hellstrom | a50e2bf | 2016-01-08 20:29:40 +0100 | [diff] [blame] | 1150 | unsigned int bytes_pp; |
Sinclair Yeh | f89c6c3 | 2015-06-26 01:54:28 -0700 | [diff] [blame] | 1151 | int ret; |
| 1152 | |
Daniel Vetter | dabdcdc | 2016-12-02 08:07:40 +0100 | [diff] [blame] | 1153 | switch (mode_cmd->pixel_format) { |
| 1154 | case DRM_FORMAT_ARGB8888: |
| 1155 | case DRM_FORMAT_XRGB8888: |
Sinclair Yeh | f89c6c3 | 2015-06-26 01:54:28 -0700 | [diff] [blame] | 1156 | format = SVGA3D_X8R8G8B8; |
Thomas Hellstrom | a50e2bf | 2016-01-08 20:29:40 +0100 | [diff] [blame] | 1157 | bytes_pp = 4; |
Sinclair Yeh | f89c6c3 | 2015-06-26 01:54:28 -0700 | [diff] [blame] | 1158 | break; |
| 1159 | |
Daniel Vetter | dabdcdc | 2016-12-02 08:07:40 +0100 | [diff] [blame] | 1160 | case DRM_FORMAT_RGB565: |
| 1161 | case DRM_FORMAT_XRGB1555: |
Sinclair Yeh | f89c6c3 | 2015-06-26 01:54:28 -0700 | [diff] [blame] | 1162 | format = SVGA3D_R5G6B5; |
Thomas Hellstrom | a50e2bf | 2016-01-08 20:29:40 +0100 | [diff] [blame] | 1163 | bytes_pp = 2; |
Sinclair Yeh | f89c6c3 | 2015-06-26 01:54:28 -0700 | [diff] [blame] | 1164 | break; |
| 1165 | |
| 1166 | case 8: |
| 1167 | format = SVGA3D_P8; |
Thomas Hellstrom | a50e2bf | 2016-01-08 20:29:40 +0100 | [diff] [blame] | 1168 | bytes_pp = 1; |
Sinclair Yeh | f89c6c3 | 2015-06-26 01:54:28 -0700 | [diff] [blame] | 1169 | break; |
| 1170 | |
| 1171 | default: |
Sakari Ailus | 92f1d09 | 2021-02-16 17:57:22 +0200 | [diff] [blame] | 1172 | DRM_ERROR("Invalid framebuffer format %p4cc\n", |
| 1173 | &mode_cmd->pixel_format); |
Sinclair Yeh | f89c6c3 | 2015-06-26 01:54:28 -0700 | [diff] [blame] | 1174 | return -EINVAL; |
| 1175 | } |
| 1176 | |
Deepak Rawat | 504901d | 2019-04-29 14:55:44 -0700 | [diff] [blame] | 1177 | metadata.format = format; |
| 1178 | metadata.mip_levels[0] = 1; |
| 1179 | metadata.num_sizes = 1; |
| 1180 | metadata.base_size.width = mode_cmd->pitches[0] / bytes_pp; |
| 1181 | metadata.base_size.height = mode_cmd->height; |
| 1182 | metadata.base_size.depth = 1; |
| 1183 | metadata.scanout = true; |
Sinclair Yeh | f89c6c3 | 2015-06-26 01:54:28 -0700 | [diff] [blame] | 1184 | |
Deepak Rawat | 504901d | 2019-04-29 14:55:44 -0700 | [diff] [blame] | 1185 | ret = vmw_gb_surface_define(vmw_priv(dev), 0, &metadata, srf_out); |
Sinclair Yeh | f89c6c3 | 2015-06-26 01:54:28 -0700 | [diff] [blame] | 1186 | if (ret) { |
| 1187 | DRM_ERROR("Failed to allocate proxy content buffer\n"); |
| 1188 | return ret; |
| 1189 | } |
| 1190 | |
Thomas Hellstrom | 6bf6bf0 | 2015-06-26 02:22:40 -0700 | [diff] [blame] | 1191 | res = &(*srf_out)->res; |
Sinclair Yeh | f89c6c3 | 2015-06-26 01:54:28 -0700 | [diff] [blame] | 1192 | |
Thomas Hellstrom | 6bf6bf0 | 2015-06-26 02:22:40 -0700 | [diff] [blame] | 1193 | /* Reserve and switch the backing mob. */ |
| 1194 | mutex_lock(&res->dev_priv->cmdbuf_mutex); |
| 1195 | (void) vmw_resource_reserve(res, false, true); |
Thomas Hellstrom | f1d34bf | 2018-06-19 15:02:16 +0200 | [diff] [blame] | 1196 | vmw_bo_unreference(&res->backup); |
| 1197 | res->backup = vmw_bo_reference(bo_mob); |
Thomas Hellstrom | 6bf6bf0 | 2015-06-26 02:22:40 -0700 | [diff] [blame] | 1198 | res->backup_offset = 0; |
Thomas Hellstrom | a9f58c4 | 2019-02-20 08:21:26 +0100 | [diff] [blame] | 1199 | vmw_resource_unreserve(res, false, false, false, NULL, 0); |
Thomas Hellstrom | 6bf6bf0 | 2015-06-26 02:22:40 -0700 | [diff] [blame] | 1200 | mutex_unlock(&res->dev_priv->cmdbuf_mutex); |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 1201 | |
| 1202 | return 0; |
| 1203 | } |
| 1204 | |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 1205 | |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 1206 | |
Thomas Hellstrom | f1d34bf | 2018-06-19 15:02:16 +0200 | [diff] [blame] | 1207 | static int vmw_kms_new_framebuffer_bo(struct vmw_private *dev_priv, |
| 1208 | struct vmw_buffer_object *bo, |
| 1209 | struct vmw_framebuffer **out, |
| 1210 | const struct drm_mode_fb_cmd2 |
| 1211 | *mode_cmd) |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 1212 | |
| 1213 | { |
Zack Rusin | 9703bb3 | 2020-11-03 22:21:34 -0500 | [diff] [blame] | 1214 | struct drm_device *dev = &dev_priv->drm; |
Thomas Hellstrom | f1d34bf | 2018-06-19 15:02:16 +0200 | [diff] [blame] | 1215 | struct vmw_framebuffer_bo *vfbd; |
Thomas Hellstrom | d3216a0 | 2010-10-05 12:42:59 +0200 | [diff] [blame] | 1216 | unsigned int requested_size; |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 1217 | int ret; |
| 1218 | |
Daniel Vetter | dabdcdc | 2016-12-02 08:07:40 +0100 | [diff] [blame] | 1219 | requested_size = mode_cmd->height * mode_cmd->pitches[0]; |
Christian König | e11bfb9 | 2020-12-09 15:07:50 +0100 | [diff] [blame] | 1220 | if (unlikely(requested_size > bo->base.base.size)) { |
Thomas Hellstrom | d3216a0 | 2010-10-05 12:42:59 +0200 | [diff] [blame] | 1221 | DRM_ERROR("Screen buffer object size is too small " |
| 1222 | "for requested mode.\n"); |
| 1223 | return -EINVAL; |
| 1224 | } |
| 1225 | |
Jakob Bornecrantz | c337ada | 2011-10-04 20:13:34 +0200 | [diff] [blame] | 1226 | /* Limited framebuffer color depth support for screen objects */ |
Sinclair Yeh | c8261a9 | 2015-06-26 01:23:42 -0700 | [diff] [blame] | 1227 | if (dev_priv->active_display_unit == vmw_du_screen_object) { |
Daniel Vetter | dabdcdc | 2016-12-02 08:07:40 +0100 | [diff] [blame] | 1228 | switch (mode_cmd->pixel_format) { |
| 1229 | case DRM_FORMAT_XRGB8888: |
| 1230 | case DRM_FORMAT_ARGB8888: |
| 1231 | break; |
| 1232 | case DRM_FORMAT_XRGB1555: |
| 1233 | case DRM_FORMAT_RGB565: |
| 1234 | break; |
Jakob Bornecrantz | c337ada | 2011-10-04 20:13:34 +0200 | [diff] [blame] | 1235 | default: |
Sakari Ailus | 92f1d09 | 2021-02-16 17:57:22 +0200 | [diff] [blame] | 1236 | DRM_ERROR("Invalid pixel format: %p4cc\n", |
| 1237 | &mode_cmd->pixel_format); |
Jakob Bornecrantz | c337ada | 2011-10-04 20:13:34 +0200 | [diff] [blame] | 1238 | return -EINVAL; |
| 1239 | } |
| 1240 | } |
| 1241 | |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 1242 | vfbd = kzalloc(sizeof(*vfbd), GFP_KERNEL); |
| 1243 | if (!vfbd) { |
| 1244 | ret = -ENOMEM; |
| 1245 | goto out_err1; |
| 1246 | } |
| 1247 | |
Ville Syrjälä | a3f913c | 2016-12-14 22:48:59 +0200 | [diff] [blame] | 1248 | drm_helper_mode_fill_fb_struct(dev, &vfbd->base.base, mode_cmd); |
Thomas Hellstrom | f1d34bf | 2018-06-19 15:02:16 +0200 | [diff] [blame] | 1249 | vfbd->base.bo = true; |
| 1250 | vfbd->buffer = vmw_bo_reference(bo); |
Daniel Vetter | dabdcdc | 2016-12-02 08:07:40 +0100 | [diff] [blame] | 1251 | vfbd->base.user_handle = mode_cmd->handles[0]; |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 1252 | *out = &vfbd->base; |
| 1253 | |
Daniel Vetter | 80f0b5a | 2012-12-13 23:39:01 +0100 | [diff] [blame] | 1254 | ret = drm_framebuffer_init(dev, &vfbd->base.base, |
Thomas Hellstrom | f1d34bf | 2018-06-19 15:02:16 +0200 | [diff] [blame] | 1255 | &vmw_framebuffer_bo_funcs); |
Daniel Vetter | 80f0b5a | 2012-12-13 23:39:01 +0100 | [diff] [blame] | 1256 | if (ret) |
Sinclair Yeh | 05c9501 | 2015-08-11 22:53:39 -0700 | [diff] [blame] | 1257 | goto out_err2; |
Daniel Vetter | 80f0b5a | 2012-12-13 23:39:01 +0100 | [diff] [blame] | 1258 | |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 1259 | return 0; |
| 1260 | |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 1261 | out_err2: |
Thomas Hellstrom | f1d34bf | 2018-06-19 15:02:16 +0200 | [diff] [blame] | 1262 | vmw_bo_unreference(&bo); |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 1263 | kfree(vfbd); |
| 1264 | out_err1: |
| 1265 | return ret; |
| 1266 | } |
| 1267 | |
Sinclair Yeh | 810b3e16 | 2017-03-23 15:39:16 -0700 | [diff] [blame] | 1268 | |
| 1269 | /** |
| 1270 | * vmw_kms_srf_ok - check if a surface can be created |
| 1271 | * |
Lee Jones | c88c25a | 2021-01-15 18:12:53 +0000 | [diff] [blame] | 1272 | * @dev_priv: Pointer to device private struct. |
Sinclair Yeh | 810b3e16 | 2017-03-23 15:39:16 -0700 | [diff] [blame] | 1273 | * @width: requested width |
| 1274 | * @height: requested height |
| 1275 | * |
| 1276 | * Surfaces need to be less than texture size |
| 1277 | */ |
| 1278 | static bool |
| 1279 | vmw_kms_srf_ok(struct vmw_private *dev_priv, uint32_t width, uint32_t height) |
| 1280 | { |
| 1281 | if (width > dev_priv->texture_max_width || |
| 1282 | height > dev_priv->texture_max_height) |
| 1283 | return false; |
| 1284 | |
| 1285 | return true; |
| 1286 | } |
| 1287 | |
Thomas Hellstrom | fd006a4 | 2015-06-28 02:50:56 -0700 | [diff] [blame] | 1288 | /** |
| 1289 | * vmw_kms_new_framebuffer - Create a new framebuffer. |
| 1290 | * |
| 1291 | * @dev_priv: Pointer to device private struct. |
Thomas Hellstrom | f1d34bf | 2018-06-19 15:02:16 +0200 | [diff] [blame] | 1292 | * @bo: Pointer to buffer object to wrap the kms framebuffer around. |
| 1293 | * Either @bo or @surface must be NULL. |
Thomas Hellstrom | fd006a4 | 2015-06-28 02:50:56 -0700 | [diff] [blame] | 1294 | * @surface: Pointer to a surface to wrap the kms framebuffer around. |
Thomas Hellstrom | f1d34bf | 2018-06-19 15:02:16 +0200 | [diff] [blame] | 1295 | * Either @bo or @surface must be NULL. |
| 1296 | * @only_2d: No presents will occur to this buffer object based framebuffer. |
| 1297 | * This helps the code to do some important optimizations. |
Thomas Hellstrom | fd006a4 | 2015-06-28 02:50:56 -0700 | [diff] [blame] | 1298 | * @mode_cmd: Frame-buffer metadata. |
| 1299 | */ |
| 1300 | struct vmw_framebuffer * |
| 1301 | vmw_kms_new_framebuffer(struct vmw_private *dev_priv, |
Thomas Hellstrom | f1d34bf | 2018-06-19 15:02:16 +0200 | [diff] [blame] | 1302 | struct vmw_buffer_object *bo, |
Thomas Hellstrom | fd006a4 | 2015-06-28 02:50:56 -0700 | [diff] [blame] | 1303 | struct vmw_surface *surface, |
| 1304 | bool only_2d, |
Daniel Vetter | dabdcdc | 2016-12-02 08:07:40 +0100 | [diff] [blame] | 1305 | const struct drm_mode_fb_cmd2 *mode_cmd) |
Thomas Hellstrom | fd006a4 | 2015-06-28 02:50:56 -0700 | [diff] [blame] | 1306 | { |
Sinclair Yeh | 05c9501 | 2015-08-11 22:53:39 -0700 | [diff] [blame] | 1307 | struct vmw_framebuffer *vfb = NULL; |
Thomas Hellstrom | f1d34bf | 2018-06-19 15:02:16 +0200 | [diff] [blame] | 1308 | bool is_bo_proxy = false; |
Thomas Hellstrom | fd006a4 | 2015-06-28 02:50:56 -0700 | [diff] [blame] | 1309 | int ret; |
| 1310 | |
| 1311 | /* |
| 1312 | * We cannot use the SurfaceDMA command in an non-accelerated VM, |
Thomas Hellstrom | f1d34bf | 2018-06-19 15:02:16 +0200 | [diff] [blame] | 1313 | * therefore, wrap the buffer object in a surface so we can use the |
Thomas Hellstrom | fd006a4 | 2015-06-28 02:50:56 -0700 | [diff] [blame] | 1314 | * SurfaceCopy command. |
| 1315 | */ |
Sinclair Yeh | 810b3e16 | 2017-03-23 15:39:16 -0700 | [diff] [blame] | 1316 | if (vmw_kms_srf_ok(dev_priv, mode_cmd->width, mode_cmd->height) && |
Thomas Hellstrom | f1d34bf | 2018-06-19 15:02:16 +0200 | [diff] [blame] | 1317 | bo && only_2d && |
Sinclair Yeh | bbd5fef | 2017-06-02 07:44:53 +0200 | [diff] [blame] | 1318 | mode_cmd->width > 64 && /* Don't create a proxy for cursor */ |
Thomas Hellstrom | fd006a4 | 2015-06-28 02:50:56 -0700 | [diff] [blame] | 1319 | dev_priv->active_display_unit == vmw_du_screen_target) { |
Zack Rusin | 9703bb3 | 2020-11-03 22:21:34 -0500 | [diff] [blame] | 1320 | ret = vmw_create_bo_proxy(&dev_priv->drm, mode_cmd, |
Thomas Hellstrom | f1d34bf | 2018-06-19 15:02:16 +0200 | [diff] [blame] | 1321 | bo, &surface); |
Thomas Hellstrom | fd006a4 | 2015-06-28 02:50:56 -0700 | [diff] [blame] | 1322 | if (ret) |
| 1323 | return ERR_PTR(ret); |
| 1324 | |
Thomas Hellstrom | f1d34bf | 2018-06-19 15:02:16 +0200 | [diff] [blame] | 1325 | is_bo_proxy = true; |
Thomas Hellstrom | fd006a4 | 2015-06-28 02:50:56 -0700 | [diff] [blame] | 1326 | } |
| 1327 | |
| 1328 | /* Create the new framebuffer depending one what we have */ |
Sinclair Yeh | 05c9501 | 2015-08-11 22:53:39 -0700 | [diff] [blame] | 1329 | if (surface) { |
Thomas Hellstrom | fd006a4 | 2015-06-28 02:50:56 -0700 | [diff] [blame] | 1330 | ret = vmw_kms_new_framebuffer_surface(dev_priv, surface, &vfb, |
| 1331 | mode_cmd, |
Thomas Hellstrom | f1d34bf | 2018-06-19 15:02:16 +0200 | [diff] [blame] | 1332 | is_bo_proxy); |
Sinclair Yeh | 05c9501 | 2015-08-11 22:53:39 -0700 | [diff] [blame] | 1333 | |
| 1334 | /* |
Thomas Hellstrom | f1d34bf | 2018-06-19 15:02:16 +0200 | [diff] [blame] | 1335 | * vmw_create_bo_proxy() adds a reference that is no longer |
Sinclair Yeh | 05c9501 | 2015-08-11 22:53:39 -0700 | [diff] [blame] | 1336 | * needed |
| 1337 | */ |
Thomas Hellstrom | f1d34bf | 2018-06-19 15:02:16 +0200 | [diff] [blame] | 1338 | if (is_bo_proxy) |
Sinclair Yeh | 05c9501 | 2015-08-11 22:53:39 -0700 | [diff] [blame] | 1339 | vmw_surface_unreference(&surface); |
Thomas Hellstrom | f1d34bf | 2018-06-19 15:02:16 +0200 | [diff] [blame] | 1340 | } else if (bo) { |
| 1341 | ret = vmw_kms_new_framebuffer_bo(dev_priv, bo, &vfb, |
| 1342 | mode_cmd); |
Sinclair Yeh | 05c9501 | 2015-08-11 22:53:39 -0700 | [diff] [blame] | 1343 | } else { |
Thomas Hellstrom | fd006a4 | 2015-06-28 02:50:56 -0700 | [diff] [blame] | 1344 | BUG(); |
Sinclair Yeh | 05c9501 | 2015-08-11 22:53:39 -0700 | [diff] [blame] | 1345 | } |
Thomas Hellstrom | fd006a4 | 2015-06-28 02:50:56 -0700 | [diff] [blame] | 1346 | |
| 1347 | if (ret) |
| 1348 | return ERR_PTR(ret); |
| 1349 | |
| 1350 | vfb->pin = vmw_framebuffer_pin; |
| 1351 | vfb->unpin = vmw_framebuffer_unpin; |
| 1352 | |
| 1353 | return vfb; |
| 1354 | } |
| 1355 | |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 1356 | /* |
| 1357 | * Generic Kernel modesetting functions |
| 1358 | */ |
| 1359 | |
| 1360 | static struct drm_framebuffer *vmw_kms_fb_create(struct drm_device *dev, |
| 1361 | struct drm_file *file_priv, |
Daniel Vetter | dabdcdc | 2016-12-02 08:07:40 +0100 | [diff] [blame] | 1362 | const struct drm_mode_fb_cmd2 *mode_cmd) |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 1363 | { |
| 1364 | struct vmw_private *dev_priv = vmw_priv(dev); |
| 1365 | struct ttm_object_file *tfile = vmw_fpriv(file_priv)->tfile; |
| 1366 | struct vmw_framebuffer *vfb = NULL; |
| 1367 | struct vmw_surface *surface = NULL; |
Thomas Hellstrom | f1d34bf | 2018-06-19 15:02:16 +0200 | [diff] [blame] | 1368 | struct vmw_buffer_object *bo = NULL; |
Thomas Hellstrom | 90ff18b | 2011-10-04 20:13:32 +0200 | [diff] [blame] | 1369 | struct ttm_base_object *user_obj; |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 1370 | int ret; |
| 1371 | |
Thomas Hellstrom | 90ff18b | 2011-10-04 20:13:32 +0200 | [diff] [blame] | 1372 | /* |
| 1373 | * Take a reference on the user object of the resource |
| 1374 | * backing the kms fb. This ensures that user-space handle |
| 1375 | * lookups on that resource will always work as long as |
| 1376 | * it's registered with a kms framebuffer. This is important, |
| 1377 | * since vmw_execbuf_process identifies resources in the |
| 1378 | * command stream using user-space handles. |
| 1379 | */ |
| 1380 | |
Daniel Vetter | dabdcdc | 2016-12-02 08:07:40 +0100 | [diff] [blame] | 1381 | user_obj = ttm_base_object_lookup(tfile, mode_cmd->handles[0]); |
Thomas Hellstrom | 90ff18b | 2011-10-04 20:13:32 +0200 | [diff] [blame] | 1382 | if (unlikely(user_obj == NULL)) { |
| 1383 | DRM_ERROR("Could not locate requested kms frame buffer.\n"); |
| 1384 | return ERR_PTR(-ENOENT); |
| 1385 | } |
| 1386 | |
Thomas Hellstrom | d3216a0 | 2010-10-05 12:42:59 +0200 | [diff] [blame] | 1387 | /** |
| 1388 | * End conditioned code. |
| 1389 | */ |
| 1390 | |
Thomas Hellstrom | f1d34bf | 2018-06-19 15:02:16 +0200 | [diff] [blame] | 1391 | /* returns either a bo or surface */ |
Jakob Bornecrantz | e7ac921 | 2011-11-28 13:19:12 +0100 | [diff] [blame] | 1392 | ret = vmw_user_lookup_handle(dev_priv, tfile, |
Daniel Vetter | dabdcdc | 2016-12-02 08:07:40 +0100 | [diff] [blame] | 1393 | mode_cmd->handles[0], |
Jakob Bornecrantz | e7ac921 | 2011-11-28 13:19:12 +0100 | [diff] [blame] | 1394 | &surface, &bo); |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 1395 | if (ret) |
Jakob Bornecrantz | e7ac921 | 2011-11-28 13:19:12 +0100 | [diff] [blame] | 1396 | goto err_out; |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 1397 | |
Sinclair Yeh | 810b3e16 | 2017-03-23 15:39:16 -0700 | [diff] [blame] | 1398 | |
| 1399 | if (!bo && |
| 1400 | !vmw_kms_srf_ok(dev_priv, mode_cmd->width, mode_cmd->height)) { |
| 1401 | DRM_ERROR("Surface size cannot exceed %dx%d", |
| 1402 | dev_priv->texture_max_width, |
| 1403 | dev_priv->texture_max_height); |
| 1404 | goto err_out; |
| 1405 | } |
| 1406 | |
| 1407 | |
Thomas Hellstrom | fd006a4 | 2015-06-28 02:50:56 -0700 | [diff] [blame] | 1408 | vfb = vmw_kms_new_framebuffer(dev_priv, bo, surface, |
| 1409 | !(dev_priv->capabilities & SVGA_CAP_3D), |
Daniel Vetter | dabdcdc | 2016-12-02 08:07:40 +0100 | [diff] [blame] | 1410 | mode_cmd); |
Thomas Hellstrom | fd006a4 | 2015-06-28 02:50:56 -0700 | [diff] [blame] | 1411 | if (IS_ERR(vfb)) { |
| 1412 | ret = PTR_ERR(vfb); |
| 1413 | goto err_out; |
| 1414 | } |
Jakob Bornecrantz | 5ffdb65 | 2010-01-30 03:38:08 +0000 | [diff] [blame] | 1415 | |
Jakob Bornecrantz | e7ac921 | 2011-11-28 13:19:12 +0100 | [diff] [blame] | 1416 | err_out: |
| 1417 | /* vmw_user_lookup_handle takes one ref so does new_fb */ |
| 1418 | if (bo) |
Thomas Hellstrom | f1d34bf | 2018-06-19 15:02:16 +0200 | [diff] [blame] | 1419 | vmw_bo_unreference(&bo); |
Jakob Bornecrantz | e7ac921 | 2011-11-28 13:19:12 +0100 | [diff] [blame] | 1420 | if (surface) |
| 1421 | vmw_surface_unreference(&surface); |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 1422 | |
| 1423 | if (ret) { |
| 1424 | DRM_ERROR("failed to create vmw_framebuffer: %i\n", ret); |
Thomas Hellstrom | 90ff18b | 2011-10-04 20:13:32 +0200 | [diff] [blame] | 1425 | ttm_base_object_unref(&user_obj); |
Chris Wilson | cce13ff | 2010-08-08 13:36:38 +0100 | [diff] [blame] | 1426 | return ERR_PTR(ret); |
Thomas Hellstrom | 90ff18b | 2011-10-04 20:13:32 +0200 | [diff] [blame] | 1427 | } else |
| 1428 | vfb->user_obj = user_obj; |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 1429 | |
| 1430 | return &vfb->base; |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 1431 | } |
| 1432 | |
Deepak Rawat | 0a80eb4 | 2018-06-19 19:51:15 +0200 | [diff] [blame] | 1433 | /** |
| 1434 | * vmw_kms_check_display_memory - Validates display memory required for a |
| 1435 | * topology |
| 1436 | * @dev: DRM device |
| 1437 | * @num_rects: number of drm_rect in rects |
| 1438 | * @rects: array of drm_rect representing the topology to validate indexed by |
| 1439 | * crtc index. |
| 1440 | * |
| 1441 | * Returns: |
| 1442 | * 0 on success otherwise negative error code |
| 1443 | */ |
| 1444 | static int vmw_kms_check_display_memory(struct drm_device *dev, |
| 1445 | uint32_t num_rects, |
| 1446 | struct drm_rect *rects) |
| 1447 | { |
| 1448 | struct vmw_private *dev_priv = vmw_priv(dev); |
Deepak Rawat | 0a80eb4 | 2018-06-19 19:51:15 +0200 | [diff] [blame] | 1449 | struct drm_rect bounding_box = {0}; |
| 1450 | u64 total_pixels = 0, pixel_mem, bb_mem; |
| 1451 | int i; |
Sinclair Yeh | c46a306 | 2017-03-23 14:24:53 -0700 | [diff] [blame] | 1452 | |
Deepak Rawat | 0a80eb4 | 2018-06-19 19:51:15 +0200 | [diff] [blame] | 1453 | for (i = 0; i < num_rects; i++) { |
| 1454 | /* |
Deepak Rawat | 0c1b174 | 2018-09-13 12:34:37 +0200 | [diff] [blame] | 1455 | * For STDU only individual screen (screen target) is limited by |
| 1456 | * SCREENTARGET_MAX_WIDTH/HEIGHT registers. |
Deepak Rawat | 0a80eb4 | 2018-06-19 19:51:15 +0200 | [diff] [blame] | 1457 | */ |
Deepak Rawat | 0c1b174 | 2018-09-13 12:34:37 +0200 | [diff] [blame] | 1458 | if (dev_priv->active_display_unit == vmw_du_screen_target && |
| 1459 | (drm_rect_width(&rects[i]) > dev_priv->stdu_max_width || |
| 1460 | drm_rect_height(&rects[i]) > dev_priv->stdu_max_height)) { |
Deepak Rawat | 9bb34e9 | 2019-05-09 12:42:58 -0700 | [diff] [blame] | 1461 | VMW_DEBUG_KMS("Screen size not supported.\n"); |
Deepak Rawat | 0a80eb4 | 2018-06-19 19:51:15 +0200 | [diff] [blame] | 1462 | return -EINVAL; |
| 1463 | } |
| 1464 | |
| 1465 | /* Bounding box upper left is at (0,0). */ |
| 1466 | if (rects[i].x2 > bounding_box.x2) |
| 1467 | bounding_box.x2 = rects[i].x2; |
| 1468 | |
| 1469 | if (rects[i].y2 > bounding_box.y2) |
| 1470 | bounding_box.y2 = rects[i].y2; |
| 1471 | |
| 1472 | total_pixels += (u64) drm_rect_width(&rects[i]) * |
| 1473 | (u64) drm_rect_height(&rects[i]); |
| 1474 | } |
| 1475 | |
| 1476 | /* Virtual svga device primary limits are always in 32-bpp. */ |
| 1477 | pixel_mem = total_pixels * 4; |
| 1478 | |
| 1479 | /* |
| 1480 | * For HV10 and below prim_bb_mem is vram size. When |
| 1481 | * SVGA_REG_MAX_PRIMARY_BOUNDING_BOX_MEM is not present vram size is |
| 1482 | * limit on primary bounding box |
| 1483 | */ |
| 1484 | if (pixel_mem > dev_priv->prim_bb_mem) { |
Deepak Rawat | 9bb34e9 | 2019-05-09 12:42:58 -0700 | [diff] [blame] | 1485 | VMW_DEBUG_KMS("Combined output size too large.\n"); |
Deepak Rawat | 0a80eb4 | 2018-06-19 19:51:15 +0200 | [diff] [blame] | 1486 | return -EINVAL; |
| 1487 | } |
| 1488 | |
| 1489 | /* SVGA_CAP_NO_BB_RESTRICTION is available for STDU only. */ |
| 1490 | if (dev_priv->active_display_unit != vmw_du_screen_target || |
| 1491 | !(dev_priv->capabilities & SVGA_CAP_NO_BB_RESTRICTION)) { |
| 1492 | bb_mem = (u64) bounding_box.x2 * bounding_box.y2 * 4; |
| 1493 | |
| 1494 | if (bb_mem > dev_priv->prim_bb_mem) { |
Deepak Rawat | 9bb34e9 | 2019-05-09 12:42:58 -0700 | [diff] [blame] | 1495 | VMW_DEBUG_KMS("Topology is beyond supported limits.\n"); |
Deepak Rawat | 0a80eb4 | 2018-06-19 19:51:15 +0200 | [diff] [blame] | 1496 | return -EINVAL; |
| 1497 | } |
| 1498 | } |
| 1499 | |
| 1500 | return 0; |
| 1501 | } |
| 1502 | |
| 1503 | /** |
Thomas Hellstrom | 9d9486e | 2018-10-04 22:38:17 +0000 | [diff] [blame] | 1504 | * vmw_crtc_state_and_lock - Return new or current crtc state with locked |
| 1505 | * crtc mutex |
| 1506 | * @state: The atomic state pointer containing the new atomic state |
| 1507 | * @crtc: The crtc |
| 1508 | * |
| 1509 | * This function returns the new crtc state if it's part of the state update. |
| 1510 | * Otherwise returns the current crtc state. It also makes sure that the |
| 1511 | * crtc mutex is locked. |
| 1512 | * |
| 1513 | * Returns: A valid crtc state pointer or NULL. It may also return a |
| 1514 | * pointer error, in particular -EDEADLK if locking needs to be rerun. |
| 1515 | */ |
| 1516 | static struct drm_crtc_state * |
| 1517 | vmw_crtc_state_and_lock(struct drm_atomic_state *state, struct drm_crtc *crtc) |
| 1518 | { |
| 1519 | struct drm_crtc_state *crtc_state; |
| 1520 | |
| 1521 | crtc_state = drm_atomic_get_new_crtc_state(state, crtc); |
| 1522 | if (crtc_state) { |
| 1523 | lockdep_assert_held(&crtc->mutex.mutex.base); |
| 1524 | } else { |
| 1525 | int ret = drm_modeset_lock(&crtc->mutex, state->acquire_ctx); |
| 1526 | |
| 1527 | if (ret != 0 && ret != -EALREADY) |
| 1528 | return ERR_PTR(ret); |
| 1529 | |
| 1530 | crtc_state = crtc->state; |
| 1531 | } |
| 1532 | |
| 1533 | return crtc_state; |
| 1534 | } |
| 1535 | |
| 1536 | /** |
| 1537 | * vmw_kms_check_implicit - Verify that all implicit display units scan out |
| 1538 | * from the same fb after the new state is committed. |
| 1539 | * @dev: The drm_device. |
| 1540 | * @state: The new state to be checked. |
| 1541 | * |
| 1542 | * Returns: |
| 1543 | * Zero on success, |
| 1544 | * -EINVAL on invalid state, |
| 1545 | * -EDEADLK if modeset locking needs to be rerun. |
| 1546 | */ |
| 1547 | static int vmw_kms_check_implicit(struct drm_device *dev, |
| 1548 | struct drm_atomic_state *state) |
| 1549 | { |
| 1550 | struct drm_framebuffer *implicit_fb = NULL; |
| 1551 | struct drm_crtc *crtc; |
| 1552 | struct drm_crtc_state *crtc_state; |
| 1553 | struct drm_plane_state *plane_state; |
| 1554 | |
| 1555 | drm_for_each_crtc(crtc, dev) { |
| 1556 | struct vmw_display_unit *du = vmw_crtc_to_du(crtc); |
| 1557 | |
| 1558 | if (!du->is_implicit) |
| 1559 | continue; |
| 1560 | |
| 1561 | crtc_state = vmw_crtc_state_and_lock(state, crtc); |
| 1562 | if (IS_ERR(crtc_state)) |
| 1563 | return PTR_ERR(crtc_state); |
| 1564 | |
| 1565 | if (!crtc_state || !crtc_state->enable) |
| 1566 | continue; |
| 1567 | |
| 1568 | /* |
| 1569 | * Can't move primary planes across crtcs, so this is OK. |
| 1570 | * It also means we don't need to take the plane mutex. |
| 1571 | */ |
| 1572 | plane_state = du->primary.state; |
| 1573 | if (plane_state->crtc != crtc) |
| 1574 | continue; |
| 1575 | |
| 1576 | if (!implicit_fb) |
| 1577 | implicit_fb = plane_state->fb; |
| 1578 | else if (implicit_fb != plane_state->fb) |
| 1579 | return -EINVAL; |
| 1580 | } |
| 1581 | |
| 1582 | return 0; |
| 1583 | } |
| 1584 | |
| 1585 | /** |
Deepak Rawat | 0a80eb4 | 2018-06-19 19:51:15 +0200 | [diff] [blame] | 1586 | * vmw_kms_check_topology - Validates topology in drm_atomic_state |
| 1587 | * @dev: DRM device |
| 1588 | * @state: the driver state object |
| 1589 | * |
| 1590 | * Returns: |
| 1591 | * 0 on success otherwise negative error code |
| 1592 | */ |
| 1593 | static int vmw_kms_check_topology(struct drm_device *dev, |
| 1594 | struct drm_atomic_state *state) |
| 1595 | { |
| 1596 | struct drm_crtc_state *old_crtc_state, *new_crtc_state; |
| 1597 | struct drm_rect *rects; |
| 1598 | struct drm_crtc *crtc; |
| 1599 | uint32_t i; |
| 1600 | int ret = 0; |
| 1601 | |
| 1602 | rects = kcalloc(dev->mode_config.num_crtc, sizeof(struct drm_rect), |
| 1603 | GFP_KERNEL); |
| 1604 | if (!rects) |
| 1605 | return -ENOMEM; |
| 1606 | |
| 1607 | drm_for_each_crtc(crtc, dev) { |
| 1608 | struct vmw_display_unit *du = vmw_crtc_to_du(crtc); |
Thomas Hellstrom | 9da6e26 | 2018-11-12 15:46:39 +0100 | [diff] [blame] | 1609 | struct drm_crtc_state *crtc_state; |
Deepak Rawat | 0a80eb4 | 2018-06-19 19:51:15 +0200 | [diff] [blame] | 1610 | |
| 1611 | i = drm_crtc_index(crtc); |
| 1612 | |
Thomas Hellstrom | 9da6e26 | 2018-11-12 15:46:39 +0100 | [diff] [blame] | 1613 | crtc_state = vmw_crtc_state_and_lock(state, crtc); |
| 1614 | if (IS_ERR(crtc_state)) { |
| 1615 | ret = PTR_ERR(crtc_state); |
| 1616 | goto clean; |
| 1617 | } |
| 1618 | |
| 1619 | if (!crtc_state) |
| 1620 | continue; |
| 1621 | |
| 1622 | if (crtc_state->enable) { |
Deepak Rawat | 0a80eb4 | 2018-06-19 19:51:15 +0200 | [diff] [blame] | 1623 | rects[i].x1 = du->gui_x; |
| 1624 | rects[i].y1 = du->gui_y; |
| 1625 | rects[i].x2 = du->gui_x + crtc_state->mode.hdisplay; |
| 1626 | rects[i].y2 = du->gui_y + crtc_state->mode.vdisplay; |
Thomas Hellstrom | 9da6e26 | 2018-11-12 15:46:39 +0100 | [diff] [blame] | 1627 | } else { |
| 1628 | rects[i].x1 = 0; |
| 1629 | rects[i].y1 = 0; |
| 1630 | rects[i].x2 = 0; |
| 1631 | rects[i].y2 = 0; |
Deepak Rawat | 0a80eb4 | 2018-06-19 19:51:15 +0200 | [diff] [blame] | 1632 | } |
| 1633 | } |
| 1634 | |
| 1635 | /* Determine change to topology due to new atomic state */ |
| 1636 | for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state, |
| 1637 | new_crtc_state, i) { |
| 1638 | struct vmw_display_unit *du = vmw_crtc_to_du(crtc); |
Deepak Rawat | 3e79ecd | 2018-06-20 11:34:26 +0200 | [diff] [blame] | 1639 | struct drm_connector *connector; |
| 1640 | struct drm_connector_state *conn_state; |
| 1641 | struct vmw_connector_state *vmw_conn_state; |
Deepak Rawat | 0a80eb4 | 2018-06-19 19:51:15 +0200 | [diff] [blame] | 1642 | |
Deepak Rawat | 479d590 | 2018-12-21 14:38:35 -0800 | [diff] [blame] | 1643 | if (!du->pref_active && new_crtc_state->enable) { |
Deepak Rawat | 9bb34e9 | 2019-05-09 12:42:58 -0700 | [diff] [blame] | 1644 | VMW_DEBUG_KMS("Enabling a disabled display unit\n"); |
Deepak Rawat | 3e79ecd | 2018-06-20 11:34:26 +0200 | [diff] [blame] | 1645 | ret = -EINVAL; |
| 1646 | goto clean; |
Deepak Rawat | 0a80eb4 | 2018-06-19 19:51:15 +0200 | [diff] [blame] | 1647 | } |
Deepak Rawat | 3e79ecd | 2018-06-20 11:34:26 +0200 | [diff] [blame] | 1648 | |
| 1649 | /* |
| 1650 | * For vmwgfx each crtc has only one connector attached and it |
| 1651 | * is not changed so don't really need to check the |
| 1652 | * crtc->connector_mask and iterate over it. |
| 1653 | */ |
| 1654 | connector = &du->connector; |
| 1655 | conn_state = drm_atomic_get_connector_state(state, connector); |
| 1656 | if (IS_ERR(conn_state)) { |
| 1657 | ret = PTR_ERR(conn_state); |
| 1658 | goto clean; |
| 1659 | } |
| 1660 | |
| 1661 | vmw_conn_state = vmw_connector_state_to_vcs(conn_state); |
| 1662 | vmw_conn_state->gui_x = du->gui_x; |
| 1663 | vmw_conn_state->gui_y = du->gui_y; |
Deepak Rawat | 0a80eb4 | 2018-06-19 19:51:15 +0200 | [diff] [blame] | 1664 | } |
| 1665 | |
| 1666 | ret = vmw_kms_check_display_memory(dev, dev->mode_config.num_crtc, |
| 1667 | rects); |
| 1668 | |
| 1669 | clean: |
| 1670 | kfree(rects); |
| 1671 | return ret; |
| 1672 | } |
Sinclair Yeh | c46a306 | 2017-03-23 14:24:53 -0700 | [diff] [blame] | 1673 | |
| 1674 | /** |
| 1675 | * vmw_kms_atomic_check_modeset- validate state object for modeset changes |
| 1676 | * |
| 1677 | * @dev: DRM device |
| 1678 | * @state: the driver state object |
| 1679 | * |
| 1680 | * This is a simple wrapper around drm_atomic_helper_check_modeset() for |
| 1681 | * us to assign a value to mode->crtc_clock so that |
| 1682 | * drm_calc_timestamping_constants() won't throw an error message |
| 1683 | * |
Deepak Rawat | 0a80eb4 | 2018-06-19 19:51:15 +0200 | [diff] [blame] | 1684 | * Returns: |
Sinclair Yeh | c46a306 | 2017-03-23 14:24:53 -0700 | [diff] [blame] | 1685 | * Zero for success or -errno |
| 1686 | */ |
Maarten Lankhorst | bdc362f | 2017-07-12 10:13:33 +0200 | [diff] [blame] | 1687 | static int |
Sinclair Yeh | c46a306 | 2017-03-23 14:24:53 -0700 | [diff] [blame] | 1688 | vmw_kms_atomic_check_modeset(struct drm_device *dev, |
| 1689 | struct drm_atomic_state *state) |
| 1690 | { |
Sinclair Yeh | c46a306 | 2017-03-23 14:24:53 -0700 | [diff] [blame] | 1691 | struct drm_crtc *crtc; |
Deepak Rawat | 7e14eab | 2018-06-20 11:23:55 +0200 | [diff] [blame] | 1692 | struct drm_crtc_state *crtc_state; |
| 1693 | bool need_modeset = false; |
| 1694 | int i, ret; |
Sinclair Yeh | c46a306 | 2017-03-23 14:24:53 -0700 | [diff] [blame] | 1695 | |
Sinclair Yeh | b249cb4 | 2018-06-19 19:46:58 +0200 | [diff] [blame] | 1696 | ret = drm_atomic_helper_check(dev, state); |
Deepak Rawat | 0a80eb4 | 2018-06-19 19:51:15 +0200 | [diff] [blame] | 1697 | if (ret) |
Sinclair Yeh | b249cb4 | 2018-06-19 19:46:58 +0200 | [diff] [blame] | 1698 | return ret; |
| 1699 | |
Thomas Hellstrom | 9d9486e | 2018-10-04 22:38:17 +0000 | [diff] [blame] | 1700 | ret = vmw_kms_check_implicit(dev, state); |
Deepak Rawat | 9bb34e9 | 2019-05-09 12:42:58 -0700 | [diff] [blame] | 1701 | if (ret) { |
| 1702 | VMW_DEBUG_KMS("Invalid implicit state\n"); |
Thomas Hellstrom | 9d9486e | 2018-10-04 22:38:17 +0000 | [diff] [blame] | 1703 | return ret; |
Deepak Rawat | 9bb34e9 | 2019-05-09 12:42:58 -0700 | [diff] [blame] | 1704 | } |
Thomas Hellstrom | 9d9486e | 2018-10-04 22:38:17 +0000 | [diff] [blame] | 1705 | |
Maarten Lankhorst | bdc362f | 2017-07-12 10:13:33 +0200 | [diff] [blame] | 1706 | for_each_new_crtc_in_state(state, crtc, crtc_state, i) { |
Deepak Rawat | 7e14eab | 2018-06-20 11:23:55 +0200 | [diff] [blame] | 1707 | if (drm_atomic_crtc_needs_modeset(crtc_state)) |
| 1708 | need_modeset = true; |
Sinclair Yeh | c46a306 | 2017-03-23 14:24:53 -0700 | [diff] [blame] | 1709 | } |
| 1710 | |
Deepak Rawat | 7e14eab | 2018-06-20 11:23:55 +0200 | [diff] [blame] | 1711 | if (need_modeset) |
| 1712 | return vmw_kms_check_topology(dev, state); |
| 1713 | |
| 1714 | return ret; |
Sinclair Yeh | c46a306 | 2017-03-23 14:24:53 -0700 | [diff] [blame] | 1715 | } |
| 1716 | |
Laurent Pinchart | e6ecefa | 2012-05-17 13:27:23 +0200 | [diff] [blame] | 1717 | static const struct drm_mode_config_funcs vmw_kms_funcs = { |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 1718 | .fb_create = vmw_kms_fb_create, |
Sinclair Yeh | c46a306 | 2017-03-23 14:24:53 -0700 | [diff] [blame] | 1719 | .atomic_check = vmw_kms_atomic_check_modeset, |
Deepak Rawat | 904efd9 | 2018-01-16 08:48:09 +0100 | [diff] [blame] | 1720 | .atomic_commit = drm_atomic_helper_commit, |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 1721 | }; |
| 1722 | |
Thomas Hellstrom | b9eb1a6 | 2015-04-02 02:39:45 -0700 | [diff] [blame] | 1723 | static int vmw_kms_generic_present(struct vmw_private *dev_priv, |
| 1724 | struct drm_file *file_priv, |
| 1725 | struct vmw_framebuffer *vfb, |
| 1726 | struct vmw_surface *surface, |
| 1727 | uint32_t sid, |
| 1728 | int32_t destX, int32_t destY, |
| 1729 | struct drm_vmw_rect *clips, |
| 1730 | uint32_t num_clips) |
Jakob Bornecrantz | 2fcd5a7 | 2011-10-04 20:13:26 +0200 | [diff] [blame] | 1731 | { |
Thomas Hellstrom | 10b1e0c | 2015-06-26 02:14:27 -0700 | [diff] [blame] | 1732 | return vmw_kms_sou_do_surface_dirty(dev_priv, vfb, NULL, clips, |
| 1733 | &surface->res, destX, destY, |
Deepak Rawat | 91e9f35 | 2018-01-16 08:24:17 +0100 | [diff] [blame] | 1734 | num_clips, 1, NULL, NULL); |
Jakob Bornecrantz | 2fcd5a7 | 2011-10-04 20:13:26 +0200 | [diff] [blame] | 1735 | } |
| 1736 | |
Thomas Hellstrom | 6bf6bf0 | 2015-06-26 02:22:40 -0700 | [diff] [blame] | 1737 | |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 1738 | int vmw_kms_present(struct vmw_private *dev_priv, |
| 1739 | struct drm_file *file_priv, |
| 1740 | struct vmw_framebuffer *vfb, |
| 1741 | struct vmw_surface *surface, |
| 1742 | uint32_t sid, |
| 1743 | int32_t destX, int32_t destY, |
| 1744 | struct drm_vmw_rect *clips, |
| 1745 | uint32_t num_clips) |
| 1746 | { |
Sinclair Yeh | 35c0512 | 2015-06-26 01:42:06 -0700 | [diff] [blame] | 1747 | int ret; |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 1748 | |
Thomas Hellstrom | 6bf6bf0 | 2015-06-26 02:22:40 -0700 | [diff] [blame] | 1749 | switch (dev_priv->active_display_unit) { |
| 1750 | case vmw_du_screen_target: |
| 1751 | ret = vmw_kms_stdu_surface_dirty(dev_priv, vfb, NULL, clips, |
| 1752 | &surface->res, destX, destY, |
Deepak Rawat | 91e9f35 | 2018-01-16 08:24:17 +0100 | [diff] [blame] | 1753 | num_clips, 1, NULL, NULL); |
Thomas Hellstrom | 6bf6bf0 | 2015-06-26 02:22:40 -0700 | [diff] [blame] | 1754 | break; |
| 1755 | case vmw_du_screen_object: |
| 1756 | ret = vmw_kms_generic_present(dev_priv, file_priv, vfb, surface, |
| 1757 | sid, destX, destY, clips, |
| 1758 | num_clips); |
| 1759 | break; |
| 1760 | default: |
| 1761 | WARN_ONCE(true, |
| 1762 | "Present called with invalid display system.\n"); |
| 1763 | ret = -ENOSYS; |
| 1764 | break; |
Jakob Bornecrantz | d7e1958 | 2010-05-28 11:21:59 +0200 | [diff] [blame] | 1765 | } |
Sinclair Yeh | 35c0512 | 2015-06-26 01:42:06 -0700 | [diff] [blame] | 1766 | if (ret) |
| 1767 | return ret; |
Jakob Bornecrantz | d7e1958 | 2010-05-28 11:21:59 +0200 | [diff] [blame] | 1768 | |
Zack Rusin | 8426ed9 | 2020-11-18 12:54:19 -0500 | [diff] [blame] | 1769 | vmw_cmd_flush(dev_priv, false); |
Michel Dänzer | 0bef23f | 2011-08-31 07:42:50 +0000 | [diff] [blame] | 1770 | |
Sinclair Yeh | 35c0512 | 2015-06-26 01:42:06 -0700 | [diff] [blame] | 1771 | return 0; |
Thomas Hellstrom | 7c4f778 | 2010-06-01 11:38:17 +0200 | [diff] [blame] | 1772 | } |
| 1773 | |
Thomas Hellstrom | 578e609 | 2016-02-12 09:45:42 +0100 | [diff] [blame] | 1774 | static void |
| 1775 | vmw_kms_create_hotplug_mode_update_property(struct vmw_private *dev_priv) |
| 1776 | { |
| 1777 | if (dev_priv->hotplug_mode_update_property) |
| 1778 | return; |
| 1779 | |
| 1780 | dev_priv->hotplug_mode_update_property = |
Zack Rusin | 9703bb3 | 2020-11-03 22:21:34 -0500 | [diff] [blame] | 1781 | drm_property_create_range(&dev_priv->drm, |
Thomas Hellstrom | 578e609 | 2016-02-12 09:45:42 +0100 | [diff] [blame] | 1782 | DRM_MODE_PROP_IMMUTABLE, |
| 1783 | "hotplug_mode_update", 0, 1); |
Thomas Hellstrom | 578e609 | 2016-02-12 09:45:42 +0100 | [diff] [blame] | 1784 | } |
| 1785 | |
Jakob Bornecrantz | d7e1958 | 2010-05-28 11:21:59 +0200 | [diff] [blame] | 1786 | int vmw_kms_init(struct vmw_private *dev_priv) |
| 1787 | { |
Zack Rusin | 9703bb3 | 2020-11-03 22:21:34 -0500 | [diff] [blame] | 1788 | struct drm_device *dev = &dev_priv->drm; |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 1789 | int ret; |
| 1790 | |
| 1791 | drm_mode_config_init(dev); |
| 1792 | dev->mode_config.funcs = &vmw_kms_funcs; |
| 1793 | dev->mode_config.min_width = 1; |
| 1794 | dev->mode_config.min_height = 1; |
Sinclair Yeh | 65ade7d | 2015-07-16 10:49:13 -0700 | [diff] [blame] | 1795 | dev->mode_config.max_width = dev_priv->texture_max_width; |
| 1796 | dev->mode_config.max_height = dev_priv->texture_max_height; |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 1797 | |
Thomas Hellstrom | 578e609 | 2016-02-12 09:45:42 +0100 | [diff] [blame] | 1798 | drm_mode_create_suggested_offset_properties(dev); |
| 1799 | vmw_kms_create_hotplug_mode_update_property(dev_priv); |
| 1800 | |
Sinclair Yeh | 35c0512 | 2015-06-26 01:42:06 -0700 | [diff] [blame] | 1801 | ret = vmw_kms_stdu_init_display(dev_priv); |
| 1802 | if (ret) { |
| 1803 | ret = vmw_kms_sou_init_display(dev_priv); |
| 1804 | if (ret) /* Fallback */ |
| 1805 | ret = vmw_kms_ldu_init_display(dev_priv); |
| 1806 | } |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 1807 | |
Sinclair Yeh | c8261a9 | 2015-06-26 01:23:42 -0700 | [diff] [blame] | 1808 | return ret; |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 1809 | } |
| 1810 | |
| 1811 | int vmw_kms_close(struct vmw_private *dev_priv) |
| 1812 | { |
Daniel Vetter | 5f58e97 | 2017-06-26 18:19:48 +0200 | [diff] [blame] | 1813 | int ret = 0; |
Sinclair Yeh | c8261a9 | 2015-06-26 01:23:42 -0700 | [diff] [blame] | 1814 | |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 1815 | /* |
| 1816 | * Docs says we should take the lock before calling this function |
| 1817 | * but since it destroys encoders and our destructor calls |
| 1818 | * drm_encoder_cleanup which takes the lock we deadlock. |
| 1819 | */ |
Zack Rusin | 9703bb3 | 2020-11-03 22:21:34 -0500 | [diff] [blame] | 1820 | drm_mode_config_cleanup(&dev_priv->drm); |
Daniel Vetter | 5f58e97 | 2017-06-26 18:19:48 +0200 | [diff] [blame] | 1821 | if (dev_priv->active_display_unit == vmw_du_legacy) |
Sinclair Yeh | c8261a9 | 2015-06-26 01:23:42 -0700 | [diff] [blame] | 1822 | ret = vmw_kms_ldu_close_display(dev_priv); |
| 1823 | |
| 1824 | return ret; |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 1825 | } |
| 1826 | |
| 1827 | int vmw_kms_cursor_bypass_ioctl(struct drm_device *dev, void *data, |
| 1828 | struct drm_file *file_priv) |
| 1829 | { |
| 1830 | struct drm_vmw_cursor_bypass_arg *arg = data; |
| 1831 | struct vmw_display_unit *du; |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 1832 | struct drm_crtc *crtc; |
| 1833 | int ret = 0; |
| 1834 | |
| 1835 | |
| 1836 | mutex_lock(&dev->mode_config.mutex); |
| 1837 | if (arg->flags & DRM_VMW_CURSOR_BYPASS_ALL) { |
| 1838 | |
| 1839 | list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) { |
| 1840 | du = vmw_crtc_to_du(crtc); |
| 1841 | du->hotspot_x = arg->xhot; |
| 1842 | du->hotspot_y = arg->yhot; |
| 1843 | } |
| 1844 | |
| 1845 | mutex_unlock(&dev->mode_config.mutex); |
| 1846 | return 0; |
| 1847 | } |
| 1848 | |
Keith Packard | 418da17 | 2017-03-14 23:25:07 -0700 | [diff] [blame] | 1849 | crtc = drm_crtc_find(dev, file_priv, arg->crtc_id); |
Rob Clark | a4cd5d6 | 2014-07-17 23:30:02 -0400 | [diff] [blame] | 1850 | if (!crtc) { |
Ville Syrjälä | 4ae87ff | 2013-10-17 13:35:05 +0300 | [diff] [blame] | 1851 | ret = -ENOENT; |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 1852 | goto out; |
| 1853 | } |
| 1854 | |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 1855 | du = vmw_crtc_to_du(crtc); |
| 1856 | |
| 1857 | du->hotspot_x = arg->xhot; |
| 1858 | du->hotspot_y = arg->yhot; |
| 1859 | |
| 1860 | out: |
| 1861 | mutex_unlock(&dev->mode_config.mutex); |
| 1862 | |
| 1863 | return ret; |
| 1864 | } |
| 1865 | |
| 1866 | int vmw_kms_write_svga(struct vmw_private *vmw_priv, |
| 1867 | unsigned width, unsigned height, unsigned pitch, |
| 1868 | unsigned bpp, unsigned depth) |
| 1869 | { |
| 1870 | if (vmw_priv->capabilities & SVGA_CAP_PITCHLOCK) |
| 1871 | vmw_write(vmw_priv, SVGA_REG_PITCHLOCK, pitch); |
| 1872 | else if (vmw_fifo_have_pitchlock(vmw_priv)) |
Zack Rusin | be4f77a | 2020-11-04 13:46:09 -0500 | [diff] [blame] | 1873 | vmw_fifo_mem_write(vmw_priv, SVGA_FIFO_PITCHLOCK, pitch); |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 1874 | vmw_write(vmw_priv, SVGA_REG_WIDTH, width); |
| 1875 | vmw_write(vmw_priv, SVGA_REG_HEIGHT, height); |
Zack Rusin | 625f8fb | 2020-11-19 19:37:07 -0500 | [diff] [blame] | 1876 | if ((vmw_priv->capabilities & SVGA_CAP_8BIT_EMULATION) != 0) |
| 1877 | vmw_write(vmw_priv, SVGA_REG_BITS_PER_PIXEL, bpp); |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 1878 | |
| 1879 | if (vmw_read(vmw_priv, SVGA_REG_DEPTH) != depth) { |
| 1880 | DRM_ERROR("Invalid depth %u for %u bpp, host expects %u\n", |
| 1881 | depth, bpp, vmw_read(vmw_priv, SVGA_REG_DEPTH)); |
| 1882 | return -EINVAL; |
| 1883 | } |
| 1884 | |
| 1885 | return 0; |
| 1886 | } |
| 1887 | |
Thomas Hellstrom | e133e737 | 2010-10-05 12:43:04 +0200 | [diff] [blame] | 1888 | bool vmw_kms_validate_mode_vram(struct vmw_private *dev_priv, |
| 1889 | uint32_t pitch, |
| 1890 | uint32_t height) |
| 1891 | { |
Sinclair Yeh | 35c0512 | 2015-06-26 01:42:06 -0700 | [diff] [blame] | 1892 | return ((u64) pitch * (u64) height) < (u64) |
| 1893 | ((dev_priv->active_display_unit == vmw_du_screen_target) ? |
| 1894 | dev_priv->prim_bb_mem : dev_priv->vram_size); |
Thomas Hellstrom | e133e737 | 2010-10-05 12:43:04 +0200 | [diff] [blame] | 1895 | } |
| 1896 | |
Jakob Bornecrantz | 1c482ab | 2011-10-17 11:59:45 +0200 | [diff] [blame] | 1897 | |
Lee Jones | c88c25a | 2021-01-15 18:12:53 +0000 | [diff] [blame] | 1898 | /* |
Jakob Bornecrantz | 1c482ab | 2011-10-17 11:59:45 +0200 | [diff] [blame] | 1899 | * Function called by DRM code called with vbl_lock held. |
| 1900 | */ |
Thomas Zimmermann | 4bebe91 | 2020-01-23 14:59:41 +0100 | [diff] [blame] | 1901 | u32 vmw_get_vblank_counter(struct drm_crtc *crtc) |
Thomas Hellstrom | 7a1c2f6 | 2010-10-01 10:21:49 +0200 | [diff] [blame] | 1902 | { |
| 1903 | return 0; |
| 1904 | } |
Jakob Bornecrantz | 626ab77 | 2011-10-04 20:13:20 +0200 | [diff] [blame] | 1905 | |
Lee Jones | c88c25a | 2021-01-15 18:12:53 +0000 | [diff] [blame] | 1906 | /* |
Jakob Bornecrantz | 1c482ab | 2011-10-17 11:59:45 +0200 | [diff] [blame] | 1907 | * Function called by DRM code called with vbl_lock held. |
| 1908 | */ |
Thomas Zimmermann | 4bebe91 | 2020-01-23 14:59:41 +0100 | [diff] [blame] | 1909 | int vmw_enable_vblank(struct drm_crtc *crtc) |
Jakob Bornecrantz | 1c482ab | 2011-10-17 11:59:45 +0200 | [diff] [blame] | 1910 | { |
Woody Suwalski | 2b0bc68 | 2018-01-17 09:07:47 +0100 | [diff] [blame] | 1911 | return -EINVAL; |
Jakob Bornecrantz | 1c482ab | 2011-10-17 11:59:45 +0200 | [diff] [blame] | 1912 | } |
| 1913 | |
Lee Jones | c88c25a | 2021-01-15 18:12:53 +0000 | [diff] [blame] | 1914 | /* |
Jakob Bornecrantz | 1c482ab | 2011-10-17 11:59:45 +0200 | [diff] [blame] | 1915 | * Function called by DRM code called with vbl_lock held. |
| 1916 | */ |
Thomas Zimmermann | 4bebe91 | 2020-01-23 14:59:41 +0100 | [diff] [blame] | 1917 | void vmw_disable_vblank(struct drm_crtc *crtc) |
Jakob Bornecrantz | 1c482ab | 2011-10-17 11:59:45 +0200 | [diff] [blame] | 1918 | { |
| 1919 | } |
| 1920 | |
Deepak Rawat | 5e24133 | 2018-06-20 11:17:16 +0200 | [diff] [blame] | 1921 | /** |
| 1922 | * vmw_du_update_layout - Update the display unit with topology from resolution |
| 1923 | * plugin and generate DRM uevent |
| 1924 | * @dev_priv: device private |
| 1925 | * @num_rects: number of drm_rect in rects |
| 1926 | * @rects: toplogy to update |
Jakob Bornecrantz | 626ab77 | 2011-10-04 20:13:20 +0200 | [diff] [blame] | 1927 | */ |
Deepak Rawat | 5e24133 | 2018-06-20 11:17:16 +0200 | [diff] [blame] | 1928 | static int vmw_du_update_layout(struct vmw_private *dev_priv, |
| 1929 | unsigned int num_rects, struct drm_rect *rects) |
Jakob Bornecrantz | 626ab77 | 2011-10-04 20:13:20 +0200 | [diff] [blame] | 1930 | { |
Zack Rusin | 9703bb3 | 2020-11-03 22:21:34 -0500 | [diff] [blame] | 1931 | struct drm_device *dev = &dev_priv->drm; |
Jakob Bornecrantz | 626ab77 | 2011-10-04 20:13:20 +0200 | [diff] [blame] | 1932 | struct vmw_display_unit *du; |
| 1933 | struct drm_connector *con; |
Deepak Rawat | b89e5ff | 2018-06-20 11:32:29 +0200 | [diff] [blame] | 1934 | struct drm_connector_list_iter conn_iter; |
Thomas Hellstrom | 9da6e26 | 2018-11-12 15:46:39 +0100 | [diff] [blame] | 1935 | struct drm_modeset_acquire_ctx ctx; |
| 1936 | struct drm_crtc *crtc; |
| 1937 | int ret; |
Jakob Bornecrantz | 626ab77 | 2011-10-04 20:13:20 +0200 | [diff] [blame] | 1938 | |
Thomas Hellstrom | 9da6e26 | 2018-11-12 15:46:39 +0100 | [diff] [blame] | 1939 | /* Currently gui_x/y is protected with the crtc mutex */ |
| 1940 | mutex_lock(&dev->mode_config.mutex); |
| 1941 | drm_modeset_acquire_init(&ctx, 0); |
| 1942 | retry: |
| 1943 | drm_for_each_crtc(crtc, dev) { |
| 1944 | ret = drm_modeset_lock(&crtc->mutex, &ctx); |
| 1945 | if (ret < 0) { |
| 1946 | if (ret == -EDEADLK) { |
| 1947 | drm_modeset_backoff(&ctx); |
| 1948 | goto retry; |
| 1949 | } |
| 1950 | goto out_fini; |
| 1951 | } |
| 1952 | } |
| 1953 | |
Deepak Rawat | b89e5ff | 2018-06-20 11:32:29 +0200 | [diff] [blame] | 1954 | drm_connector_list_iter_begin(dev, &conn_iter); |
| 1955 | drm_for_each_connector_iter(con, &conn_iter) { |
Jakob Bornecrantz | 626ab77 | 2011-10-04 20:13:20 +0200 | [diff] [blame] | 1956 | du = vmw_connector_to_du(con); |
Deepak Rawat | 5e24133 | 2018-06-20 11:17:16 +0200 | [diff] [blame] | 1957 | if (num_rects > du->unit) { |
| 1958 | du->pref_width = drm_rect_width(&rects[du->unit]); |
| 1959 | du->pref_height = drm_rect_height(&rects[du->unit]); |
Jakob Bornecrantz | 626ab77 | 2011-10-04 20:13:20 +0200 | [diff] [blame] | 1960 | du->pref_active = true; |
Deepak Rawat | 5e24133 | 2018-06-20 11:17:16 +0200 | [diff] [blame] | 1961 | du->gui_x = rects[du->unit].x1; |
| 1962 | du->gui_y = rects[du->unit].y1; |
Deepak Rawat | b89e5ff | 2018-06-20 11:32:29 +0200 | [diff] [blame] | 1963 | } else { |
| 1964 | du->pref_width = 800; |
| 1965 | du->pref_height = 600; |
| 1966 | du->pref_active = false; |
| 1967 | du->gui_x = 0; |
| 1968 | du->gui_y = 0; |
| 1969 | } |
| 1970 | } |
| 1971 | drm_connector_list_iter_end(&conn_iter); |
Jakob Bornecrantz | 626ab77 | 2011-10-04 20:13:20 +0200 | [diff] [blame] | 1972 | |
Jakob Bornecrantz | 626ab77 | 2011-10-04 20:13:20 +0200 | [diff] [blame] | 1973 | list_for_each_entry(con, &dev->mode_config.connector_list, head) { |
| 1974 | du = vmw_connector_to_du(con); |
Deepak Rawat | b89e5ff | 2018-06-20 11:32:29 +0200 | [diff] [blame] | 1975 | if (num_rects > du->unit) { |
Thomas Hellstrom | 578e609 | 2016-02-12 09:45:42 +0100 | [diff] [blame] | 1976 | drm_object_property_set_value |
| 1977 | (&con->base, dev->mode_config.suggested_x_property, |
| 1978 | du->gui_x); |
| 1979 | drm_object_property_set_value |
| 1980 | (&con->base, dev->mode_config.suggested_y_property, |
| 1981 | du->gui_y); |
Jakob Bornecrantz | 626ab77 | 2011-10-04 20:13:20 +0200 | [diff] [blame] | 1982 | } else { |
Thomas Hellstrom | 578e609 | 2016-02-12 09:45:42 +0100 | [diff] [blame] | 1983 | drm_object_property_set_value |
| 1984 | (&con->base, dev->mode_config.suggested_x_property, |
| 1985 | 0); |
| 1986 | drm_object_property_set_value |
| 1987 | (&con->base, dev->mode_config.suggested_y_property, |
| 1988 | 0); |
Jakob Bornecrantz | 626ab77 | 2011-10-04 20:13:20 +0200 | [diff] [blame] | 1989 | } |
| 1990 | con->status = vmw_du_connector_detect(con, true); |
| 1991 | } |
Deepak Rawat | b89e5ff | 2018-06-20 11:32:29 +0200 | [diff] [blame] | 1992 | |
Thomas Hellstrom | 578e609 | 2016-02-12 09:45:42 +0100 | [diff] [blame] | 1993 | drm_sysfs_hotplug_event(dev); |
Thomas Hellstrom | 9da6e26 | 2018-11-12 15:46:39 +0100 | [diff] [blame] | 1994 | out_fini: |
| 1995 | drm_modeset_drop_locks(&ctx); |
| 1996 | drm_modeset_acquire_fini(&ctx); |
| 1997 | mutex_unlock(&dev->mode_config.mutex); |
| 1998 | |
Jakob Bornecrantz | 626ab77 | 2011-10-04 20:13:20 +0200 | [diff] [blame] | 1999 | return 0; |
| 2000 | } |
| 2001 | |
Maarten Lankhorst | 7ea7728 | 2016-06-07 12:49:30 +0200 | [diff] [blame] | 2002 | int vmw_du_crtc_gamma_set(struct drm_crtc *crtc, |
| 2003 | u16 *r, u16 *g, u16 *b, |
Daniel Vetter | 6d124ff | 2017-04-03 10:33:01 +0200 | [diff] [blame] | 2004 | uint32_t size, |
| 2005 | struct drm_modeset_acquire_ctx *ctx) |
Jakob Bornecrantz | 626ab77 | 2011-10-04 20:13:20 +0200 | [diff] [blame] | 2006 | { |
| 2007 | struct vmw_private *dev_priv = vmw_priv(crtc->dev); |
| 2008 | int i; |
| 2009 | |
| 2010 | for (i = 0; i < size; i++) { |
| 2011 | DRM_DEBUG("%d r/g/b = 0x%04x / 0x%04x / 0x%04x\n", i, |
| 2012 | r[i], g[i], b[i]); |
| 2013 | vmw_write(dev_priv, SVGA_PALETTE_BASE + i * 3 + 0, r[i] >> 8); |
| 2014 | vmw_write(dev_priv, SVGA_PALETTE_BASE + i * 3 + 1, g[i] >> 8); |
| 2015 | vmw_write(dev_priv, SVGA_PALETTE_BASE + i * 3 + 2, b[i] >> 8); |
| 2016 | } |
Maarten Lankhorst | 7ea7728 | 2016-06-07 12:49:30 +0200 | [diff] [blame] | 2017 | |
| 2018 | return 0; |
Jakob Bornecrantz | 626ab77 | 2011-10-04 20:13:20 +0200 | [diff] [blame] | 2019 | } |
| 2020 | |
Maarten Lankhorst | 9a69a9a | 2015-07-21 11:34:55 +0200 | [diff] [blame] | 2021 | int vmw_du_connector_dpms(struct drm_connector *connector, int mode) |
Jakob Bornecrantz | 626ab77 | 2011-10-04 20:13:20 +0200 | [diff] [blame] | 2022 | { |
Maarten Lankhorst | 9a69a9a | 2015-07-21 11:34:55 +0200 | [diff] [blame] | 2023 | return 0; |
Jakob Bornecrantz | 626ab77 | 2011-10-04 20:13:20 +0200 | [diff] [blame] | 2024 | } |
| 2025 | |
Jakob Bornecrantz | 626ab77 | 2011-10-04 20:13:20 +0200 | [diff] [blame] | 2026 | enum drm_connector_status |
| 2027 | vmw_du_connector_detect(struct drm_connector *connector, bool force) |
| 2028 | { |
| 2029 | uint32_t num_displays; |
| 2030 | struct drm_device *dev = connector->dev; |
| 2031 | struct vmw_private *dev_priv = vmw_priv(dev); |
Thomas Hellstrom | cd2b89e | 2011-10-25 23:35:53 +0200 | [diff] [blame] | 2032 | struct vmw_display_unit *du = vmw_connector_to_du(connector); |
Jakob Bornecrantz | 626ab77 | 2011-10-04 20:13:20 +0200 | [diff] [blame] | 2033 | |
Jakob Bornecrantz | 626ab77 | 2011-10-04 20:13:20 +0200 | [diff] [blame] | 2034 | num_displays = vmw_read(dev_priv, SVGA_REG_NUM_DISPLAYS); |
Jakob Bornecrantz | 626ab77 | 2011-10-04 20:13:20 +0200 | [diff] [blame] | 2035 | |
Thomas Hellstrom | cd2b89e | 2011-10-25 23:35:53 +0200 | [diff] [blame] | 2036 | return ((vmw_connector_to_du(connector)->unit < num_displays && |
| 2037 | du->pref_active) ? |
Jakob Bornecrantz | 626ab77 | 2011-10-04 20:13:20 +0200 | [diff] [blame] | 2038 | connector_status_connected : connector_status_disconnected); |
| 2039 | } |
| 2040 | |
| 2041 | static struct drm_display_mode vmw_kms_connector_builtin[] = { |
| 2042 | /* 640x480@60Hz */ |
| 2043 | { DRM_MODE("640x480", DRM_MODE_TYPE_DRIVER, 25175, 640, 656, |
| 2044 | 752, 800, 0, 480, 489, 492, 525, 0, |
| 2045 | DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) }, |
| 2046 | /* 800x600@60Hz */ |
| 2047 | { DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER, 40000, 800, 840, |
| 2048 | 968, 1056, 0, 600, 601, 605, 628, 0, |
| 2049 | DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, |
| 2050 | /* 1024x768@60Hz */ |
| 2051 | { DRM_MODE("1024x768", DRM_MODE_TYPE_DRIVER, 65000, 1024, 1048, |
| 2052 | 1184, 1344, 0, 768, 771, 777, 806, 0, |
| 2053 | DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) }, |
| 2054 | /* 1152x864@75Hz */ |
| 2055 | { DRM_MODE("1152x864", DRM_MODE_TYPE_DRIVER, 108000, 1152, 1216, |
| 2056 | 1344, 1600, 0, 864, 865, 868, 900, 0, |
| 2057 | DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, |
Roland Scheidegger | cfc51a7 | 2021-02-05 02:04:46 +0100 | [diff] [blame] | 2058 | /* 1280x720@60Hz */ |
| 2059 | { DRM_MODE("1280x720", DRM_MODE_TYPE_DRIVER, 74500, 1280, 1344, |
| 2060 | 1472, 1664, 0, 720, 723, 728, 748, 0, |
| 2061 | DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) }, |
Jakob Bornecrantz | 626ab77 | 2011-10-04 20:13:20 +0200 | [diff] [blame] | 2062 | /* 1280x768@60Hz */ |
| 2063 | { DRM_MODE("1280x768", DRM_MODE_TYPE_DRIVER, 79500, 1280, 1344, |
| 2064 | 1472, 1664, 0, 768, 771, 778, 798, 0, |
| 2065 | DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) }, |
| 2066 | /* 1280x800@60Hz */ |
| 2067 | { DRM_MODE("1280x800", DRM_MODE_TYPE_DRIVER, 83500, 1280, 1352, |
| 2068 | 1480, 1680, 0, 800, 803, 809, 831, 0, |
| 2069 | DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) }, |
| 2070 | /* 1280x960@60Hz */ |
| 2071 | { DRM_MODE("1280x960", DRM_MODE_TYPE_DRIVER, 108000, 1280, 1376, |
| 2072 | 1488, 1800, 0, 960, 961, 964, 1000, 0, |
| 2073 | DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, |
| 2074 | /* 1280x1024@60Hz */ |
| 2075 | { DRM_MODE("1280x1024", DRM_MODE_TYPE_DRIVER, 108000, 1280, 1328, |
| 2076 | 1440, 1688, 0, 1024, 1025, 1028, 1066, 0, |
| 2077 | DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, |
| 2078 | /* 1360x768@60Hz */ |
| 2079 | { DRM_MODE("1360x768", DRM_MODE_TYPE_DRIVER, 85500, 1360, 1424, |
| 2080 | 1536, 1792, 0, 768, 771, 777, 795, 0, |
| 2081 | DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, |
| 2082 | /* 1440x1050@60Hz */ |
| 2083 | { DRM_MODE("1400x1050", DRM_MODE_TYPE_DRIVER, 121750, 1400, 1488, |
| 2084 | 1632, 1864, 0, 1050, 1053, 1057, 1089, 0, |
| 2085 | DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) }, |
| 2086 | /* 1440x900@60Hz */ |
| 2087 | { DRM_MODE("1440x900", DRM_MODE_TYPE_DRIVER, 106500, 1440, 1520, |
| 2088 | 1672, 1904, 0, 900, 903, 909, 934, 0, |
| 2089 | DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) }, |
| 2090 | /* 1600x1200@60Hz */ |
| 2091 | { DRM_MODE("1600x1200", DRM_MODE_TYPE_DRIVER, 162000, 1600, 1664, |
| 2092 | 1856, 2160, 0, 1200, 1201, 1204, 1250, 0, |
| 2093 | DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, |
| 2094 | /* 1680x1050@60Hz */ |
| 2095 | { DRM_MODE("1680x1050", DRM_MODE_TYPE_DRIVER, 146250, 1680, 1784, |
| 2096 | 1960, 2240, 0, 1050, 1053, 1059, 1089, 0, |
| 2097 | DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) }, |
| 2098 | /* 1792x1344@60Hz */ |
| 2099 | { DRM_MODE("1792x1344", DRM_MODE_TYPE_DRIVER, 204750, 1792, 1920, |
| 2100 | 2120, 2448, 0, 1344, 1345, 1348, 1394, 0, |
| 2101 | DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) }, |
| 2102 | /* 1853x1392@60Hz */ |
| 2103 | { DRM_MODE("1856x1392", DRM_MODE_TYPE_DRIVER, 218250, 1856, 1952, |
| 2104 | 2176, 2528, 0, 1392, 1393, 1396, 1439, 0, |
| 2105 | DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) }, |
Roland Scheidegger | cfc51a7 | 2021-02-05 02:04:46 +0100 | [diff] [blame] | 2106 | /* 1920x1080@60Hz */ |
| 2107 | { DRM_MODE("1920x1080", DRM_MODE_TYPE_DRIVER, 173000, 1920, 2048, |
| 2108 | 2248, 2576, 0, 1080, 1083, 1088, 1120, 0, |
| 2109 | DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) }, |
Jakob Bornecrantz | 626ab77 | 2011-10-04 20:13:20 +0200 | [diff] [blame] | 2110 | /* 1920x1200@60Hz */ |
| 2111 | { DRM_MODE("1920x1200", DRM_MODE_TYPE_DRIVER, 193250, 1920, 2056, |
| 2112 | 2256, 2592, 0, 1200, 1203, 1209, 1245, 0, |
| 2113 | DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) }, |
| 2114 | /* 1920x1440@60Hz */ |
| 2115 | { DRM_MODE("1920x1440", DRM_MODE_TYPE_DRIVER, 234000, 1920, 2048, |
| 2116 | 2256, 2600, 0, 1440, 1441, 1444, 1500, 0, |
| 2117 | DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) }, |
Roland Scheidegger | cfc51a7 | 2021-02-05 02:04:46 +0100 | [diff] [blame] | 2118 | /* 2560x1440@60Hz */ |
| 2119 | { DRM_MODE("2560x1440", DRM_MODE_TYPE_DRIVER, 241500, 2560, 2608, |
| 2120 | 2640, 2720, 0, 1440, 1443, 1448, 1481, 0, |
| 2121 | DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) }, |
Jakob Bornecrantz | 626ab77 | 2011-10-04 20:13:20 +0200 | [diff] [blame] | 2122 | /* 2560x1600@60Hz */ |
| 2123 | { DRM_MODE("2560x1600", DRM_MODE_TYPE_DRIVER, 348500, 2560, 2752, |
| 2124 | 3032, 3504, 0, 1600, 1603, 1609, 1658, 0, |
| 2125 | DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) }, |
Roland Scheidegger | cfc51a7 | 2021-02-05 02:04:46 +0100 | [diff] [blame] | 2126 | /* 2880x1800@60Hz */ |
| 2127 | { DRM_MODE("2880x1800", DRM_MODE_TYPE_DRIVER, 337500, 2880, 2928, |
| 2128 | 2960, 3040, 0, 1800, 1803, 1809, 1852, 0, |
| 2129 | DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) }, |
| 2130 | /* 3840x2160@60Hz */ |
| 2131 | { DRM_MODE("3840x2160", DRM_MODE_TYPE_DRIVER, 533000, 3840, 3888, |
| 2132 | 3920, 4000, 0, 2160, 2163, 2168, 2222, 0, |
| 2133 | DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) }, |
| 2134 | /* 3840x2400@60Hz */ |
| 2135 | { DRM_MODE("3840x2400", DRM_MODE_TYPE_DRIVER, 592250, 3840, 3888, |
| 2136 | 3920, 4000, 0, 2400, 2403, 2409, 2469, 0, |
| 2137 | DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) }, |
Jakob Bornecrantz | 626ab77 | 2011-10-04 20:13:20 +0200 | [diff] [blame] | 2138 | /* Terminate */ |
| 2139 | { DRM_MODE("", 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0) }, |
| 2140 | }; |
| 2141 | |
Thomas Hellstrom | 1543b4dd | 2011-11-02 09:43:10 +0100 | [diff] [blame] | 2142 | /** |
| 2143 | * vmw_guess_mode_timing - Provide fake timings for a |
| 2144 | * 60Hz vrefresh mode. |
| 2145 | * |
Lee Jones | c88c25a | 2021-01-15 18:12:53 +0000 | [diff] [blame] | 2146 | * @mode: Pointer to a struct drm_display_mode with hdisplay and vdisplay |
Thomas Hellstrom | 1543b4dd | 2011-11-02 09:43:10 +0100 | [diff] [blame] | 2147 | * members filled in. |
| 2148 | */ |
Thomas Hellstrom | a278724 | 2015-06-29 12:55:07 -0700 | [diff] [blame] | 2149 | void vmw_guess_mode_timing(struct drm_display_mode *mode) |
Thomas Hellstrom | 1543b4dd | 2011-11-02 09:43:10 +0100 | [diff] [blame] | 2150 | { |
| 2151 | mode->hsync_start = mode->hdisplay + 50; |
| 2152 | mode->hsync_end = mode->hsync_start + 50; |
| 2153 | mode->htotal = mode->hsync_end + 50; |
| 2154 | |
| 2155 | mode->vsync_start = mode->vdisplay + 50; |
| 2156 | mode->vsync_end = mode->vsync_start + 50; |
| 2157 | mode->vtotal = mode->vsync_end + 50; |
| 2158 | |
| 2159 | mode->clock = (u32)mode->htotal * (u32)mode->vtotal / 100 * 6; |
Thomas Hellstrom | 1543b4dd | 2011-11-02 09:43:10 +0100 | [diff] [blame] | 2160 | } |
| 2161 | |
| 2162 | |
Jakob Bornecrantz | 626ab77 | 2011-10-04 20:13:20 +0200 | [diff] [blame] | 2163 | int vmw_du_connector_fill_modes(struct drm_connector *connector, |
| 2164 | uint32_t max_width, uint32_t max_height) |
| 2165 | { |
| 2166 | struct vmw_display_unit *du = vmw_connector_to_du(connector); |
| 2167 | struct drm_device *dev = connector->dev; |
| 2168 | struct vmw_private *dev_priv = vmw_priv(dev); |
| 2169 | struct drm_display_mode *mode = NULL; |
| 2170 | struct drm_display_mode *bmode; |
| 2171 | struct drm_display_mode prefmode = { DRM_MODE("preferred", |
| 2172 | DRM_MODE_TYPE_DRIVER | DRM_MODE_TYPE_PREFERRED, |
| 2173 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 2174 | DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) |
| 2175 | }; |
| 2176 | int i; |
Sinclair Yeh | 7c20d21 | 2016-06-29 11:29:47 -0700 | [diff] [blame] | 2177 | u32 assumed_bpp = 4; |
Sinclair Yeh | 9a72384 | 2014-10-31 09:58:06 +0100 | [diff] [blame] | 2178 | |
Sinclair Yeh | 04319d8 | 2016-06-29 12:15:48 -0700 | [diff] [blame] | 2179 | if (dev_priv->assume_16bpp) |
| 2180 | assumed_bpp = 2; |
Jakob Bornecrantz | 626ab77 | 2011-10-04 20:13:20 +0200 | [diff] [blame] | 2181 | |
Deepak Rawat | 140b4e6 | 2018-09-13 12:44:13 +0200 | [diff] [blame] | 2182 | max_width = min(max_width, dev_priv->texture_max_width); |
| 2183 | max_height = min(max_height, dev_priv->texture_max_height); |
| 2184 | |
| 2185 | /* |
| 2186 | * For STDU extra limit for a mode on SVGA_REG_SCREENTARGET_MAX_WIDTH/ |
| 2187 | * HEIGHT registers. |
| 2188 | */ |
Sinclair Yeh | 35c0512 | 2015-06-26 01:42:06 -0700 | [diff] [blame] | 2189 | if (dev_priv->active_display_unit == vmw_du_screen_target) { |
| 2190 | max_width = min(max_width, dev_priv->stdu_max_width); |
| 2191 | max_height = min(max_height, dev_priv->stdu_max_height); |
Jakob Bornecrantz | 626ab77 | 2011-10-04 20:13:20 +0200 | [diff] [blame] | 2192 | } |
| 2193 | |
| 2194 | /* Add preferred mode */ |
Sinclair Yeh | c8261a9 | 2015-06-26 01:23:42 -0700 | [diff] [blame] | 2195 | mode = drm_mode_duplicate(dev, &prefmode); |
| 2196 | if (!mode) |
| 2197 | return 0; |
| 2198 | mode->hdisplay = du->pref_width; |
| 2199 | mode->vdisplay = du->pref_height; |
| 2200 | vmw_guess_mode_timing(mode); |
Zack Rusin | e3dc552 | 2021-02-08 14:48:44 -0500 | [diff] [blame] | 2201 | drm_mode_set_name(mode); |
Jakob Bornecrantz | 626ab77 | 2011-10-04 20:13:20 +0200 | [diff] [blame] | 2202 | |
Sinclair Yeh | c8261a9 | 2015-06-26 01:23:42 -0700 | [diff] [blame] | 2203 | if (vmw_kms_validate_mode_vram(dev_priv, |
| 2204 | mode->hdisplay * assumed_bpp, |
| 2205 | mode->vdisplay)) { |
| 2206 | drm_mode_probed_add(connector, mode); |
| 2207 | } else { |
| 2208 | drm_mode_destroy(dev, mode); |
| 2209 | mode = NULL; |
Jakob Bornecrantz | 626ab77 | 2011-10-04 20:13:20 +0200 | [diff] [blame] | 2210 | } |
| 2211 | |
Sinclair Yeh | c8261a9 | 2015-06-26 01:23:42 -0700 | [diff] [blame] | 2212 | if (du->pref_mode) { |
| 2213 | list_del_init(&du->pref_mode->head); |
| 2214 | drm_mode_destroy(dev, du->pref_mode); |
| 2215 | } |
| 2216 | |
| 2217 | /* mode might be null here, this is intended */ |
| 2218 | du->pref_mode = mode; |
| 2219 | |
Jakob Bornecrantz | 626ab77 | 2011-10-04 20:13:20 +0200 | [diff] [blame] | 2220 | for (i = 0; vmw_kms_connector_builtin[i].type != 0; i++) { |
| 2221 | bmode = &vmw_kms_connector_builtin[i]; |
| 2222 | if (bmode->hdisplay > max_width || |
| 2223 | bmode->vdisplay > max_height) |
| 2224 | continue; |
| 2225 | |
Sinclair Yeh | 9a72384 | 2014-10-31 09:58:06 +0100 | [diff] [blame] | 2226 | if (!vmw_kms_validate_mode_vram(dev_priv, |
| 2227 | bmode->hdisplay * assumed_bpp, |
Jakob Bornecrantz | 626ab77 | 2011-10-04 20:13:20 +0200 | [diff] [blame] | 2228 | bmode->vdisplay)) |
| 2229 | continue; |
| 2230 | |
| 2231 | mode = drm_mode_duplicate(dev, bmode); |
| 2232 | if (!mode) |
| 2233 | return 0; |
Jakob Bornecrantz | 626ab77 | 2011-10-04 20:13:20 +0200 | [diff] [blame] | 2234 | |
| 2235 | drm_mode_probed_add(connector, mode); |
| 2236 | } |
| 2237 | |
Daniel Vetter | 97e14fb | 2018-07-09 10:40:08 +0200 | [diff] [blame] | 2238 | drm_connector_list_update(connector); |
Thomas Hellstrom | f6b0500 | 2015-06-29 12:59:58 -0700 | [diff] [blame] | 2239 | /* Move the prefered mode first, help apps pick the right mode. */ |
| 2240 | drm_mode_sort(&connector->modes); |
Jakob Bornecrantz | 626ab77 | 2011-10-04 20:13:20 +0200 | [diff] [blame] | 2241 | |
| 2242 | return 1; |
| 2243 | } |
| 2244 | |
Deepak Rawat | 5e24133 | 2018-06-20 11:17:16 +0200 | [diff] [blame] | 2245 | /** |
| 2246 | * vmw_kms_update_layout_ioctl - Handler for DRM_VMW_UPDATE_LAYOUT ioctl |
| 2247 | * @dev: drm device for the ioctl |
| 2248 | * @data: data pointer for the ioctl |
| 2249 | * @file_priv: drm file for the ioctl call |
| 2250 | * |
| 2251 | * Update preferred topology of display unit as per ioctl request. The topology |
| 2252 | * is expressed as array of drm_vmw_rect. |
| 2253 | * e.g. |
| 2254 | * [0 0 640 480] [640 0 800 600] [0 480 640 480] |
| 2255 | * |
| 2256 | * NOTE: |
| 2257 | * The x and y offset (upper left) in drm_vmw_rect cannot be less than 0. Beside |
| 2258 | * device limit on topology, x + w and y + h (lower right) cannot be greater |
| 2259 | * than INT_MAX. So topology beyond these limits will return with error. |
| 2260 | * |
| 2261 | * Returns: |
| 2262 | * Zero on success, negative errno on failure. |
| 2263 | */ |
Thomas Hellstrom | cd2b89e | 2011-10-25 23:35:53 +0200 | [diff] [blame] | 2264 | int vmw_kms_update_layout_ioctl(struct drm_device *dev, void *data, |
| 2265 | struct drm_file *file_priv) |
| 2266 | { |
| 2267 | struct vmw_private *dev_priv = vmw_priv(dev); |
Deepak Rawat | 0c1b174 | 2018-09-13 12:34:37 +0200 | [diff] [blame] | 2268 | struct drm_mode_config *mode_config = &dev->mode_config; |
Thomas Hellstrom | cd2b89e | 2011-10-25 23:35:53 +0200 | [diff] [blame] | 2269 | struct drm_vmw_update_layout_arg *arg = |
| 2270 | (struct drm_vmw_update_layout_arg *)data; |
Thomas Hellstrom | cd2b89e | 2011-10-25 23:35:53 +0200 | [diff] [blame] | 2271 | void __user *user_rects; |
| 2272 | struct drm_vmw_rect *rects; |
Deepak Rawat | 5e24133 | 2018-06-20 11:17:16 +0200 | [diff] [blame] | 2273 | struct drm_rect *drm_rects; |
Thomas Hellstrom | cd2b89e | 2011-10-25 23:35:53 +0200 | [diff] [blame] | 2274 | unsigned rects_size; |
Deepak Rawat | 5e24133 | 2018-06-20 11:17:16 +0200 | [diff] [blame] | 2275 | int ret, i; |
Thomas Hellstrom | cd2b89e | 2011-10-25 23:35:53 +0200 | [diff] [blame] | 2276 | |
Thomas Hellstrom | cd2b89e | 2011-10-25 23:35:53 +0200 | [diff] [blame] | 2277 | if (!arg->num_outputs) { |
Deepak Rawat | 5e24133 | 2018-06-20 11:17:16 +0200 | [diff] [blame] | 2278 | struct drm_rect def_rect = {0, 0, 800, 600}; |
Deepak Rawat | 745adc3 | 2019-05-09 11:47:40 -0700 | [diff] [blame] | 2279 | VMW_DEBUG_KMS("Default layout x1 = %d y1 = %d x2 = %d y2 = %d\n", |
| 2280 | def_rect.x1, def_rect.y1, |
| 2281 | def_rect.x2, def_rect.y2); |
Thomas Hellstrom | cd2b89e | 2011-10-25 23:35:53 +0200 | [diff] [blame] | 2282 | vmw_du_update_layout(dev_priv, 1, &def_rect); |
Thomas Hellstrom | 5151adb | 2015-03-09 01:56:21 -0700 | [diff] [blame] | 2283 | return 0; |
Thomas Hellstrom | cd2b89e | 2011-10-25 23:35:53 +0200 | [diff] [blame] | 2284 | } |
| 2285 | |
| 2286 | rects_size = arg->num_outputs * sizeof(struct drm_vmw_rect); |
Xi Wang | bab9efc | 2011-11-28 12:25:43 +0100 | [diff] [blame] | 2287 | rects = kcalloc(arg->num_outputs, sizeof(struct drm_vmw_rect), |
| 2288 | GFP_KERNEL); |
Thomas Hellstrom | 5151adb | 2015-03-09 01:56:21 -0700 | [diff] [blame] | 2289 | if (unlikely(!rects)) |
| 2290 | return -ENOMEM; |
Thomas Hellstrom | cd2b89e | 2011-10-25 23:35:53 +0200 | [diff] [blame] | 2291 | |
| 2292 | user_rects = (void __user *)(unsigned long)arg->rects; |
| 2293 | ret = copy_from_user(rects, user_rects, rects_size); |
| 2294 | if (unlikely(ret != 0)) { |
| 2295 | DRM_ERROR("Failed to get rects.\n"); |
| 2296 | ret = -EFAULT; |
| 2297 | goto out_free; |
| 2298 | } |
| 2299 | |
Deepak Rawat | 5e24133 | 2018-06-20 11:17:16 +0200 | [diff] [blame] | 2300 | drm_rects = (struct drm_rect *)rects; |
| 2301 | |
Deepak Rawat | 745adc3 | 2019-05-09 11:47:40 -0700 | [diff] [blame] | 2302 | VMW_DEBUG_KMS("Layout count = %u\n", arg->num_outputs); |
Deepak Rawat | 5e24133 | 2018-06-20 11:17:16 +0200 | [diff] [blame] | 2303 | for (i = 0; i < arg->num_outputs; i++) { |
| 2304 | struct drm_vmw_rect curr_rect; |
| 2305 | |
| 2306 | /* Verify user-space for overflow as kernel use drm_rect */ |
| 2307 | if ((rects[i].x + rects[i].w > INT_MAX) || |
| 2308 | (rects[i].y + rects[i].h > INT_MAX)) { |
| 2309 | ret = -ERANGE; |
Thomas Hellstrom | cd2b89e | 2011-10-25 23:35:53 +0200 | [diff] [blame] | 2310 | goto out_free; |
| 2311 | } |
Sinclair Yeh | c8261a9 | 2015-06-26 01:23:42 -0700 | [diff] [blame] | 2312 | |
Deepak Rawat | 5e24133 | 2018-06-20 11:17:16 +0200 | [diff] [blame] | 2313 | curr_rect = rects[i]; |
| 2314 | drm_rects[i].x1 = curr_rect.x; |
| 2315 | drm_rects[i].y1 = curr_rect.y; |
| 2316 | drm_rects[i].x2 = curr_rect.x + curr_rect.w; |
| 2317 | drm_rects[i].y2 = curr_rect.y + curr_rect.h; |
Deepak Rawat | 0c1b174 | 2018-09-13 12:34:37 +0200 | [diff] [blame] | 2318 | |
Deepak Rawat | 745adc3 | 2019-05-09 11:47:40 -0700 | [diff] [blame] | 2319 | VMW_DEBUG_KMS(" x1 = %d y1 = %d x2 = %d y2 = %d\n", |
| 2320 | drm_rects[i].x1, drm_rects[i].y1, |
| 2321 | drm_rects[i].x2, drm_rects[i].y2); |
| 2322 | |
Deepak Rawat | 0c1b174 | 2018-09-13 12:34:37 +0200 | [diff] [blame] | 2323 | /* |
| 2324 | * Currently this check is limiting the topology within |
| 2325 | * mode_config->max (which actually is max texture size |
| 2326 | * supported by virtual device). This limit is here to address |
| 2327 | * window managers that create a big framebuffer for whole |
| 2328 | * topology. |
| 2329 | */ |
| 2330 | if (drm_rects[i].x1 < 0 || drm_rects[i].y1 < 0 || |
| 2331 | drm_rects[i].x2 > mode_config->max_width || |
| 2332 | drm_rects[i].y2 > mode_config->max_height) { |
Deepak Rawat | 9bb34e9 | 2019-05-09 12:42:58 -0700 | [diff] [blame] | 2333 | VMW_DEBUG_KMS("Invalid layout %d %d %d %d\n", |
| 2334 | drm_rects[i].x1, drm_rects[i].y1, |
| 2335 | drm_rects[i].x2, drm_rects[i].y2); |
Deepak Rawat | 0c1b174 | 2018-09-13 12:34:37 +0200 | [diff] [blame] | 2336 | ret = -EINVAL; |
| 2337 | goto out_free; |
| 2338 | } |
Thomas Hellstrom | cd2b89e | 2011-10-25 23:35:53 +0200 | [diff] [blame] | 2339 | } |
| 2340 | |
Deepak Rawat | 5e24133 | 2018-06-20 11:17:16 +0200 | [diff] [blame] | 2341 | ret = vmw_kms_check_display_memory(dev, arg->num_outputs, drm_rects); |
Sinclair Yeh | 65ade7d | 2015-07-16 10:49:13 -0700 | [diff] [blame] | 2342 | |
Deepak Rawat | 5e24133 | 2018-06-20 11:17:16 +0200 | [diff] [blame] | 2343 | if (ret == 0) |
| 2344 | vmw_du_update_layout(dev_priv, arg->num_outputs, drm_rects); |
Thomas Hellstrom | cd2b89e | 2011-10-25 23:35:53 +0200 | [diff] [blame] | 2345 | |
| 2346 | out_free: |
| 2347 | kfree(rects); |
Thomas Hellstrom | cd2b89e | 2011-10-25 23:35:53 +0200 | [diff] [blame] | 2348 | return ret; |
| 2349 | } |
Thomas Hellstrom | 1a4b172 | 2015-06-26 02:03:53 -0700 | [diff] [blame] | 2350 | |
| 2351 | /** |
| 2352 | * vmw_kms_helper_dirty - Helper to build commands and perform actions based |
| 2353 | * on a set of cliprects and a set of display units. |
| 2354 | * |
| 2355 | * @dev_priv: Pointer to a device private structure. |
| 2356 | * @framebuffer: Pointer to the framebuffer on which to perform the actions. |
| 2357 | * @clips: A set of struct drm_clip_rect. Either this os @vclips must be NULL. |
| 2358 | * Cliprects are given in framebuffer coordinates. |
| 2359 | * @vclips: A set of struct drm_vmw_rect cliprects. Either this or @clips must |
| 2360 | * be NULL. Cliprects are given in source coordinates. |
| 2361 | * @dest_x: X coordinate offset for the crtc / destination clip rects. |
| 2362 | * @dest_y: Y coordinate offset for the crtc / destination clip rects. |
| 2363 | * @num_clips: Number of cliprects in the @clips or @vclips array. |
| 2364 | * @increment: Integer with which to increment the clip counter when looping. |
| 2365 | * Used to skip a predetermined number of clip rects. |
| 2366 | * @dirty: Closure structure. See the description of struct vmw_kms_dirty. |
| 2367 | */ |
| 2368 | int vmw_kms_helper_dirty(struct vmw_private *dev_priv, |
| 2369 | struct vmw_framebuffer *framebuffer, |
| 2370 | const struct drm_clip_rect *clips, |
| 2371 | const struct drm_vmw_rect *vclips, |
| 2372 | s32 dest_x, s32 dest_y, |
| 2373 | int num_clips, |
| 2374 | int increment, |
| 2375 | struct vmw_kms_dirty *dirty) |
| 2376 | { |
| 2377 | struct vmw_display_unit *units[VMWGFX_NUM_DISPLAY_UNITS]; |
| 2378 | struct drm_crtc *crtc; |
| 2379 | u32 num_units = 0; |
| 2380 | u32 i, k; |
Thomas Hellstrom | 1a4b172 | 2015-06-26 02:03:53 -0700 | [diff] [blame] | 2381 | |
| 2382 | dirty->dev_priv = dev_priv; |
| 2383 | |
Deepak Rawat | 91e9f35 | 2018-01-16 08:24:17 +0100 | [diff] [blame] | 2384 | /* If crtc is passed, no need to iterate over other display units */ |
| 2385 | if (dirty->crtc) { |
| 2386 | units[num_units++] = vmw_crtc_to_du(dirty->crtc); |
| 2387 | } else { |
Zack Rusin | 9703bb3 | 2020-11-03 22:21:34 -0500 | [diff] [blame] | 2388 | list_for_each_entry(crtc, &dev_priv->drm.mode_config.crtc_list, |
Deepak Rawat | 91e9f35 | 2018-01-16 08:24:17 +0100 | [diff] [blame] | 2389 | head) { |
Ville Syrjälä | 464ce09 | 2018-05-25 21:50:34 +0300 | [diff] [blame] | 2390 | struct drm_plane *plane = crtc->primary; |
| 2391 | |
| 2392 | if (plane->state->fb == &framebuffer->base) |
| 2393 | units[num_units++] = vmw_crtc_to_du(crtc); |
Deepak Rawat | 91e9f35 | 2018-01-16 08:24:17 +0100 | [diff] [blame] | 2394 | } |
Thomas Hellstrom | 1a4b172 | 2015-06-26 02:03:53 -0700 | [diff] [blame] | 2395 | } |
| 2396 | |
| 2397 | for (k = 0; k < num_units; k++) { |
| 2398 | struct vmw_display_unit *unit = units[k]; |
| 2399 | s32 crtc_x = unit->crtc.x; |
| 2400 | s32 crtc_y = unit->crtc.y; |
| 2401 | s32 crtc_width = unit->crtc.mode.hdisplay; |
| 2402 | s32 crtc_height = unit->crtc.mode.vdisplay; |
| 2403 | const struct drm_clip_rect *clips_ptr = clips; |
| 2404 | const struct drm_vmw_rect *vclips_ptr = vclips; |
| 2405 | |
| 2406 | dirty->unit = unit; |
| 2407 | if (dirty->fifo_reserve_size > 0) { |
Zack Rusin | 8426ed9 | 2020-11-18 12:54:19 -0500 | [diff] [blame] | 2408 | dirty->cmd = VMW_CMD_RESERVE(dev_priv, |
Thomas Hellstrom | 1a4b172 | 2015-06-26 02:03:53 -0700 | [diff] [blame] | 2409 | dirty->fifo_reserve_size); |
Deepak Rawat | 11c4541 | 2019-02-14 16:15:39 -0800 | [diff] [blame] | 2410 | if (!dirty->cmd) |
Christian Engelmayer | f3b8c0c | 2015-09-19 00:32:24 +0200 | [diff] [blame] | 2411 | return -ENOMEM; |
Deepak Rawat | 11c4541 | 2019-02-14 16:15:39 -0800 | [diff] [blame] | 2412 | |
Thomas Hellstrom | 1a4b172 | 2015-06-26 02:03:53 -0700 | [diff] [blame] | 2413 | memset(dirty->cmd, 0, dirty->fifo_reserve_size); |
| 2414 | } |
| 2415 | dirty->num_hits = 0; |
| 2416 | for (i = 0; i < num_clips; i++, clips_ptr += increment, |
| 2417 | vclips_ptr += increment) { |
| 2418 | s32 clip_left; |
| 2419 | s32 clip_top; |
| 2420 | |
| 2421 | /* |
| 2422 | * Select clip array type. Note that integer type |
| 2423 | * in @clips is unsigned short, whereas in @vclips |
| 2424 | * it's 32-bit. |
| 2425 | */ |
| 2426 | if (clips) { |
| 2427 | dirty->fb_x = (s32) clips_ptr->x1; |
| 2428 | dirty->fb_y = (s32) clips_ptr->y1; |
| 2429 | dirty->unit_x2 = (s32) clips_ptr->x2 + dest_x - |
| 2430 | crtc_x; |
| 2431 | dirty->unit_y2 = (s32) clips_ptr->y2 + dest_y - |
| 2432 | crtc_y; |
| 2433 | } else { |
| 2434 | dirty->fb_x = vclips_ptr->x; |
| 2435 | dirty->fb_y = vclips_ptr->y; |
| 2436 | dirty->unit_x2 = dirty->fb_x + vclips_ptr->w + |
| 2437 | dest_x - crtc_x; |
| 2438 | dirty->unit_y2 = dirty->fb_y + vclips_ptr->h + |
| 2439 | dest_y - crtc_y; |
| 2440 | } |
| 2441 | |
| 2442 | dirty->unit_x1 = dirty->fb_x + dest_x - crtc_x; |
| 2443 | dirty->unit_y1 = dirty->fb_y + dest_y - crtc_y; |
| 2444 | |
| 2445 | /* Skip this clip if it's outside the crtc region */ |
| 2446 | if (dirty->unit_x1 >= crtc_width || |
| 2447 | dirty->unit_y1 >= crtc_height || |
| 2448 | dirty->unit_x2 <= 0 || dirty->unit_y2 <= 0) |
| 2449 | continue; |
| 2450 | |
| 2451 | /* Clip right and bottom to crtc limits */ |
| 2452 | dirty->unit_x2 = min_t(s32, dirty->unit_x2, |
| 2453 | crtc_width); |
| 2454 | dirty->unit_y2 = min_t(s32, dirty->unit_y2, |
| 2455 | crtc_height); |
| 2456 | |
| 2457 | /* Clip left and top to crtc limits */ |
| 2458 | clip_left = min_t(s32, dirty->unit_x1, 0); |
| 2459 | clip_top = min_t(s32, dirty->unit_y1, 0); |
| 2460 | dirty->unit_x1 -= clip_left; |
| 2461 | dirty->unit_y1 -= clip_top; |
| 2462 | dirty->fb_x -= clip_left; |
| 2463 | dirty->fb_y -= clip_top; |
| 2464 | |
| 2465 | dirty->clip(dirty); |
| 2466 | } |
| 2467 | |
| 2468 | dirty->fifo_commit(dirty); |
| 2469 | } |
| 2470 | |
| 2471 | return 0; |
| 2472 | } |
| 2473 | |
| 2474 | /** |
Thomas Hellstrom | 2724b2d | 2018-09-26 15:34:50 +0200 | [diff] [blame] | 2475 | * vmw_kms_helper_validation_finish - Helper for post KMS command submission |
| 2476 | * cleanup and fencing |
| 2477 | * @dev_priv: Pointer to the device-private struct |
| 2478 | * @file_priv: Pointer identifying the client when user-space fencing is used |
| 2479 | * @ctx: Pointer to the validation context |
| 2480 | * @out_fence: If non-NULL, returned refcounted fence-pointer |
| 2481 | * @user_fence_rep: If non-NULL, pointer to user-space address area |
| 2482 | * in which to copy user-space fence info |
Thomas Hellstrom | 1a4b172 | 2015-06-26 02:03:53 -0700 | [diff] [blame] | 2483 | */ |
Thomas Hellstrom | 2724b2d | 2018-09-26 15:34:50 +0200 | [diff] [blame] | 2484 | void vmw_kms_helper_validation_finish(struct vmw_private *dev_priv, |
| 2485 | struct drm_file *file_priv, |
| 2486 | struct vmw_validation_context *ctx, |
| 2487 | struct vmw_fence_obj **out_fence, |
| 2488 | struct drm_vmw_fence_rep __user * |
| 2489 | user_fence_rep) |
Thomas Hellstrom | 1a4b172 | 2015-06-26 02:03:53 -0700 | [diff] [blame] | 2490 | { |
Thomas Hellstrom | 2724b2d | 2018-09-26 15:34:50 +0200 | [diff] [blame] | 2491 | struct vmw_fence_obj *fence = NULL; |
Thomas Hellstrom | 51fdbeb | 2019-01-31 10:52:21 +0100 | [diff] [blame] | 2492 | uint32_t handle = 0; |
| 2493 | int ret = 0; |
Thomas Hellstrom | 1a4b172 | 2015-06-26 02:03:53 -0700 | [diff] [blame] | 2494 | |
Thomas Hellstrom | 2724b2d | 2018-09-26 15:34:50 +0200 | [diff] [blame] | 2495 | if (file_priv || user_fence_rep || vmw_validation_has_bos(ctx) || |
| 2496 | out_fence) |
| 2497 | ret = vmw_execbuf_fence_commands(file_priv, dev_priv, &fence, |
| 2498 | file_priv ? &handle : NULL); |
| 2499 | vmw_validation_done(ctx, fence); |
Thomas Hellstrom | 1a4b172 | 2015-06-26 02:03:53 -0700 | [diff] [blame] | 2500 | if (file_priv) |
| 2501 | vmw_execbuf_copy_fence_user(dev_priv, vmw_fpriv(file_priv), |
| 2502 | ret, user_fence_rep, fence, |
Sinclair Yeh | c906965d | 2017-07-05 01:49:32 -0700 | [diff] [blame] | 2503 | handle, -1, NULL); |
Thomas Hellstrom | 1a4b172 | 2015-06-26 02:03:53 -0700 | [diff] [blame] | 2504 | if (out_fence) |
| 2505 | *out_fence = fence; |
| 2506 | else |
| 2507 | vmw_fence_obj_unreference(&fence); |
Thomas Hellstrom | 1a4b172 | 2015-06-26 02:03:53 -0700 | [diff] [blame] | 2508 | } |
Thomas Hellstrom | 6bf6bf0 | 2015-06-26 02:22:40 -0700 | [diff] [blame] | 2509 | |
| 2510 | /** |
| 2511 | * vmw_kms_update_proxy - Helper function to update a proxy surface from |
| 2512 | * its backing MOB. |
| 2513 | * |
| 2514 | * @res: Pointer to the surface resource |
| 2515 | * @clips: Clip rects in framebuffer (surface) space. |
| 2516 | * @num_clips: Number of clips in @clips. |
| 2517 | * @increment: Integer with which to increment the clip counter when looping. |
| 2518 | * Used to skip a predetermined number of clip rects. |
| 2519 | * |
| 2520 | * This function makes sure the proxy surface is updated from its backing MOB |
| 2521 | * using the region given by @clips. The surface resource @res and its backing |
| 2522 | * MOB needs to be reserved and validated on call. |
| 2523 | */ |
| 2524 | int vmw_kms_update_proxy(struct vmw_resource *res, |
| 2525 | const struct drm_clip_rect *clips, |
| 2526 | unsigned num_clips, |
| 2527 | int increment) |
| 2528 | { |
| 2529 | struct vmw_private *dev_priv = res->dev_priv; |
Deepak Rawat | 26b8287 | 2019-04-29 11:42:45 -0700 | [diff] [blame] | 2530 | struct drm_vmw_size *size = &vmw_res_to_srf(res)->metadata.base_size; |
Thomas Hellstrom | 6bf6bf0 | 2015-06-26 02:22:40 -0700 | [diff] [blame] | 2531 | struct { |
| 2532 | SVGA3dCmdHeader header; |
| 2533 | SVGA3dCmdUpdateGBImage body; |
| 2534 | } *cmd; |
| 2535 | SVGA3dBox *box; |
| 2536 | size_t copy_size = 0; |
| 2537 | int i; |
| 2538 | |
| 2539 | if (!clips) |
| 2540 | return 0; |
| 2541 | |
Zack Rusin | 8426ed9 | 2020-11-18 12:54:19 -0500 | [diff] [blame] | 2542 | cmd = VMW_CMD_RESERVE(dev_priv, sizeof(*cmd) * num_clips); |
Deepak Rawat | 11c4541 | 2019-02-14 16:15:39 -0800 | [diff] [blame] | 2543 | if (!cmd) |
Thomas Hellstrom | 6bf6bf0 | 2015-06-26 02:22:40 -0700 | [diff] [blame] | 2544 | return -ENOMEM; |
Thomas Hellstrom | 6bf6bf0 | 2015-06-26 02:22:40 -0700 | [diff] [blame] | 2545 | |
| 2546 | for (i = 0; i < num_clips; ++i, clips += increment, ++cmd) { |
| 2547 | box = &cmd->body.box; |
| 2548 | |
| 2549 | cmd->header.id = SVGA_3D_CMD_UPDATE_GB_IMAGE; |
| 2550 | cmd->header.size = sizeof(cmd->body); |
| 2551 | cmd->body.image.sid = res->id; |
| 2552 | cmd->body.image.face = 0; |
| 2553 | cmd->body.image.mipmap = 0; |
| 2554 | |
| 2555 | if (clips->x1 > size->width || clips->x2 > size->width || |
| 2556 | clips->y1 > size->height || clips->y2 > size->height) { |
| 2557 | DRM_ERROR("Invalid clips outsize of framebuffer.\n"); |
| 2558 | return -EINVAL; |
| 2559 | } |
| 2560 | |
| 2561 | box->x = clips->x1; |
| 2562 | box->y = clips->y1; |
| 2563 | box->z = 0; |
| 2564 | box->w = clips->x2 - clips->x1; |
| 2565 | box->h = clips->y2 - clips->y1; |
| 2566 | box->d = 1; |
| 2567 | |
| 2568 | copy_size += sizeof(*cmd); |
| 2569 | } |
| 2570 | |
Zack Rusin | 8426ed9 | 2020-11-18 12:54:19 -0500 | [diff] [blame] | 2571 | vmw_cmd_commit(dev_priv, copy_size); |
Thomas Hellstrom | 6bf6bf0 | 2015-06-26 02:22:40 -0700 | [diff] [blame] | 2572 | |
| 2573 | return 0; |
| 2574 | } |
Thomas Hellstrom | a278724 | 2015-06-29 12:55:07 -0700 | [diff] [blame] | 2575 | |
| 2576 | int vmw_kms_fbdev_init_data(struct vmw_private *dev_priv, |
| 2577 | unsigned unit, |
| 2578 | u32 max_width, |
| 2579 | u32 max_height, |
| 2580 | struct drm_connector **p_con, |
| 2581 | struct drm_crtc **p_crtc, |
| 2582 | struct drm_display_mode **p_mode) |
| 2583 | { |
| 2584 | struct drm_connector *con; |
| 2585 | struct vmw_display_unit *du; |
| 2586 | struct drm_display_mode *mode; |
| 2587 | int i = 0; |
Thomas Hellstrom | 21fbd08 | 2018-04-26 09:48:55 +0200 | [diff] [blame] | 2588 | int ret = 0; |
Thomas Hellstrom | a278724 | 2015-06-29 12:55:07 -0700 | [diff] [blame] | 2589 | |
Zack Rusin | 9703bb3 | 2020-11-03 22:21:34 -0500 | [diff] [blame] | 2590 | mutex_lock(&dev_priv->drm.mode_config.mutex); |
| 2591 | list_for_each_entry(con, &dev_priv->drm.mode_config.connector_list, |
Thomas Hellstrom | a278724 | 2015-06-29 12:55:07 -0700 | [diff] [blame] | 2592 | head) { |
| 2593 | if (i == unit) |
| 2594 | break; |
| 2595 | |
| 2596 | ++i; |
| 2597 | } |
| 2598 | |
Zack Rusin | 9703bb3 | 2020-11-03 22:21:34 -0500 | [diff] [blame] | 2599 | if (&con->head == &dev_priv->drm.mode_config.connector_list) { |
Thomas Hellstrom | a278724 | 2015-06-29 12:55:07 -0700 | [diff] [blame] | 2600 | DRM_ERROR("Could not find initial display unit.\n"); |
Thomas Hellstrom | 21fbd08 | 2018-04-26 09:48:55 +0200 | [diff] [blame] | 2601 | ret = -EINVAL; |
| 2602 | goto out_unlock; |
Thomas Hellstrom | a278724 | 2015-06-29 12:55:07 -0700 | [diff] [blame] | 2603 | } |
| 2604 | |
| 2605 | if (list_empty(&con->modes)) |
| 2606 | (void) vmw_du_connector_fill_modes(con, max_width, max_height); |
| 2607 | |
| 2608 | if (list_empty(&con->modes)) { |
| 2609 | DRM_ERROR("Could not find initial display mode.\n"); |
Thomas Hellstrom | 21fbd08 | 2018-04-26 09:48:55 +0200 | [diff] [blame] | 2610 | ret = -EINVAL; |
| 2611 | goto out_unlock; |
Thomas Hellstrom | a278724 | 2015-06-29 12:55:07 -0700 | [diff] [blame] | 2612 | } |
| 2613 | |
| 2614 | du = vmw_connector_to_du(con); |
| 2615 | *p_con = con; |
| 2616 | *p_crtc = &du->crtc; |
| 2617 | |
| 2618 | list_for_each_entry(mode, &con->modes, head) { |
| 2619 | if (mode->type & DRM_MODE_TYPE_PREFERRED) |
| 2620 | break; |
| 2621 | } |
| 2622 | |
Dan Carpenter | 4437c11 | 2020-06-26 13:39:59 +0300 | [diff] [blame] | 2623 | if (&mode->head == &con->modes) { |
Thomas Hellstrom | a278724 | 2015-06-29 12:55:07 -0700 | [diff] [blame] | 2624 | WARN_ONCE(true, "Could not find initial preferred mode.\n"); |
| 2625 | *p_mode = list_first_entry(&con->modes, |
| 2626 | struct drm_display_mode, |
| 2627 | head); |
Dan Carpenter | 4437c11 | 2020-06-26 13:39:59 +0300 | [diff] [blame] | 2628 | } else { |
| 2629 | *p_mode = mode; |
Thomas Hellstrom | a278724 | 2015-06-29 12:55:07 -0700 | [diff] [blame] | 2630 | } |
| 2631 | |
Thomas Hellstrom | 21fbd08 | 2018-04-26 09:48:55 +0200 | [diff] [blame] | 2632 | out_unlock: |
Zack Rusin | 9703bb3 | 2020-11-03 22:21:34 -0500 | [diff] [blame] | 2633 | mutex_unlock(&dev_priv->drm.mode_config.mutex); |
Thomas Hellstrom | 21fbd08 | 2018-04-26 09:48:55 +0200 | [diff] [blame] | 2634 | |
| 2635 | return ret; |
Thomas Hellstrom | a278724 | 2015-06-29 12:55:07 -0700 | [diff] [blame] | 2636 | } |
Thomas Hellstrom | 75c0685 | 2016-02-12 09:00:26 +0100 | [diff] [blame] | 2637 | |
| 2638 | /** |
Thomas Hellstrom | 76404ac | 2016-02-12 09:55:45 +0100 | [diff] [blame] | 2639 | * vmw_kms_create_implicit_placement_proparty - Set up the implicit placement |
| 2640 | * property. |
| 2641 | * |
| 2642 | * @dev_priv: Pointer to a device private struct. |
Thomas Hellstrom | 76404ac | 2016-02-12 09:55:45 +0100 | [diff] [blame] | 2643 | * |
| 2644 | * Sets up the implicit placement property unless it's already set up. |
| 2645 | */ |
| 2646 | void |
Thomas Hellstrom | 9d9486e | 2018-10-04 22:38:17 +0000 | [diff] [blame] | 2647 | vmw_kms_create_implicit_placement_property(struct vmw_private *dev_priv) |
Thomas Hellstrom | 76404ac | 2016-02-12 09:55:45 +0100 | [diff] [blame] | 2648 | { |
| 2649 | if (dev_priv->implicit_placement_property) |
| 2650 | return; |
| 2651 | |
| 2652 | dev_priv->implicit_placement_property = |
Zack Rusin | 9703bb3 | 2020-11-03 22:21:34 -0500 | [diff] [blame] | 2653 | drm_property_create_range(&dev_priv->drm, |
Thomas Hellstrom | 9d9486e | 2018-10-04 22:38:17 +0000 | [diff] [blame] | 2654 | DRM_MODE_PROP_IMMUTABLE, |
Thomas Hellstrom | 76404ac | 2016-02-12 09:55:45 +0100 | [diff] [blame] | 2655 | "implicit_placement", 0, 1); |
Thomas Hellstrom | 76404ac | 2016-02-12 09:55:45 +0100 | [diff] [blame] | 2656 | } |
Sinclair Yeh | 904bb5e | 2017-03-23 14:29:22 -0700 | [diff] [blame] | 2657 | |
Thomas Hellstrom | c3b9b16 | 2018-03-22 10:26:37 +0100 | [diff] [blame] | 2658 | /** |
| 2659 | * vmw_kms_suspend - Save modesetting state and turn modesetting off. |
| 2660 | * |
| 2661 | * @dev: Pointer to the drm device |
| 2662 | * Return: 0 on success. Negative error code on failure. |
| 2663 | */ |
| 2664 | int vmw_kms_suspend(struct drm_device *dev) |
| 2665 | { |
| 2666 | struct vmw_private *dev_priv = vmw_priv(dev); |
| 2667 | |
| 2668 | dev_priv->suspend_state = drm_atomic_helper_suspend(dev); |
| 2669 | if (IS_ERR(dev_priv->suspend_state)) { |
| 2670 | int ret = PTR_ERR(dev_priv->suspend_state); |
| 2671 | |
| 2672 | DRM_ERROR("Failed kms suspend: %d\n", ret); |
| 2673 | dev_priv->suspend_state = NULL; |
| 2674 | |
| 2675 | return ret; |
| 2676 | } |
| 2677 | |
| 2678 | return 0; |
| 2679 | } |
| 2680 | |
| 2681 | |
| 2682 | /** |
| 2683 | * vmw_kms_resume - Re-enable modesetting and restore state |
| 2684 | * |
| 2685 | * @dev: Pointer to the drm device |
| 2686 | * Return: 0 on success. Negative error code on failure. |
| 2687 | * |
| 2688 | * State is resumed from a previous vmw_kms_suspend(). It's illegal |
| 2689 | * to call this function without a previous vmw_kms_suspend(). |
| 2690 | */ |
| 2691 | int vmw_kms_resume(struct drm_device *dev) |
| 2692 | { |
| 2693 | struct vmw_private *dev_priv = vmw_priv(dev); |
| 2694 | int ret; |
| 2695 | |
| 2696 | if (WARN_ON(!dev_priv->suspend_state)) |
| 2697 | return 0; |
| 2698 | |
| 2699 | ret = drm_atomic_helper_resume(dev, dev_priv->suspend_state); |
| 2700 | dev_priv->suspend_state = NULL; |
| 2701 | |
| 2702 | return ret; |
| 2703 | } |
Dave Airlie | 2b4f44ee | 2018-03-28 14:30:41 +1000 | [diff] [blame] | 2704 | |
| 2705 | /** |
Thomas Hellstrom | 140bcaa | 2018-03-08 10:07:37 +0100 | [diff] [blame] | 2706 | * vmw_kms_lost_device - Notify kms that modesetting capabilities will be lost |
| 2707 | * |
| 2708 | * @dev: Pointer to the drm device |
| 2709 | */ |
| 2710 | void vmw_kms_lost_device(struct drm_device *dev) |
| 2711 | { |
| 2712 | drm_atomic_helper_shutdown(dev); |
| 2713 | } |
Deepak Rawat | e41774c | 2018-07-11 15:42:45 -0700 | [diff] [blame] | 2714 | |
| 2715 | /** |
| 2716 | * vmw_du_helper_plane_update - Helper to do plane update on a display unit. |
| 2717 | * @update: The closure structure. |
| 2718 | * |
| 2719 | * Call this helper after setting callbacks in &vmw_du_update_plane to do plane |
| 2720 | * update on display unit. |
| 2721 | * |
| 2722 | * Return: 0 on success or a negative error code on failure. |
| 2723 | */ |
| 2724 | int vmw_du_helper_plane_update(struct vmw_du_update_plane *update) |
| 2725 | { |
| 2726 | struct drm_plane_state *state = update->plane->state; |
| 2727 | struct drm_plane_state *old_state = update->old_state; |
| 2728 | struct drm_atomic_helper_damage_iter iter; |
| 2729 | struct drm_rect clip; |
| 2730 | struct drm_rect bb; |
| 2731 | DECLARE_VAL_CONTEXT(val_ctx, NULL, 0); |
| 2732 | uint32_t reserved_size = 0; |
| 2733 | uint32_t submit_size = 0; |
| 2734 | uint32_t curr_size = 0; |
| 2735 | uint32_t num_hits = 0; |
| 2736 | void *cmd_start; |
| 2737 | char *cmd_next; |
| 2738 | int ret; |
| 2739 | |
| 2740 | /* |
| 2741 | * Iterate in advance to check if really need plane update and find the |
| 2742 | * number of clips that actually are in plane src for fifo allocation. |
| 2743 | */ |
| 2744 | drm_atomic_helper_damage_iter_init(&iter, old_state, state); |
| 2745 | drm_atomic_for_each_plane_damage(&iter, &clip) |
| 2746 | num_hits++; |
| 2747 | |
| 2748 | if (num_hits == 0) |
| 2749 | return 0; |
| 2750 | |
| 2751 | if (update->vfb->bo) { |
| 2752 | struct vmw_framebuffer_bo *vfbbo = |
| 2753 | container_of(update->vfb, typeof(*vfbbo), base); |
| 2754 | |
| 2755 | ret = vmw_validation_add_bo(&val_ctx, vfbbo->buffer, false, |
| 2756 | update->cpu_blit); |
| 2757 | } else { |
| 2758 | struct vmw_framebuffer_surface *vfbs = |
| 2759 | container_of(update->vfb, typeof(*vfbs), base); |
| 2760 | |
| 2761 | ret = vmw_validation_add_resource(&val_ctx, &vfbs->surface->res, |
Thomas Hellstrom | a9f58c4 | 2019-02-20 08:21:26 +0100 | [diff] [blame] | 2762 | 0, VMW_RES_DIRTY_NONE, NULL, |
| 2763 | NULL); |
Deepak Rawat | e41774c | 2018-07-11 15:42:45 -0700 | [diff] [blame] | 2764 | } |
| 2765 | |
| 2766 | if (ret) |
| 2767 | return ret; |
| 2768 | |
| 2769 | ret = vmw_validation_prepare(&val_ctx, update->mutex, update->intr); |
| 2770 | if (ret) |
| 2771 | goto out_unref; |
| 2772 | |
| 2773 | reserved_size = update->calc_fifo_size(update, num_hits); |
Zack Rusin | 8426ed9 | 2020-11-18 12:54:19 -0500 | [diff] [blame] | 2774 | cmd_start = VMW_CMD_RESERVE(update->dev_priv, reserved_size); |
Deepak Rawat | e41774c | 2018-07-11 15:42:45 -0700 | [diff] [blame] | 2775 | if (!cmd_start) { |
| 2776 | ret = -ENOMEM; |
| 2777 | goto out_revert; |
| 2778 | } |
| 2779 | |
| 2780 | cmd_next = cmd_start; |
| 2781 | |
| 2782 | if (update->post_prepare) { |
| 2783 | curr_size = update->post_prepare(update, cmd_next); |
| 2784 | cmd_next += curr_size; |
| 2785 | submit_size += curr_size; |
| 2786 | } |
| 2787 | |
| 2788 | if (update->pre_clip) { |
| 2789 | curr_size = update->pre_clip(update, cmd_next, num_hits); |
| 2790 | cmd_next += curr_size; |
| 2791 | submit_size += curr_size; |
| 2792 | } |
| 2793 | |
| 2794 | bb.x1 = INT_MAX; |
| 2795 | bb.y1 = INT_MAX; |
| 2796 | bb.x2 = INT_MIN; |
| 2797 | bb.y2 = INT_MIN; |
| 2798 | |
| 2799 | drm_atomic_helper_damage_iter_init(&iter, old_state, state); |
| 2800 | drm_atomic_for_each_plane_damage(&iter, &clip) { |
| 2801 | uint32_t fb_x = clip.x1; |
| 2802 | uint32_t fb_y = clip.y1; |
| 2803 | |
| 2804 | vmw_du_translate_to_crtc(state, &clip); |
| 2805 | if (update->clip) { |
| 2806 | curr_size = update->clip(update, cmd_next, &clip, fb_x, |
| 2807 | fb_y); |
| 2808 | cmd_next += curr_size; |
| 2809 | submit_size += curr_size; |
| 2810 | } |
| 2811 | bb.x1 = min_t(int, bb.x1, clip.x1); |
| 2812 | bb.y1 = min_t(int, bb.y1, clip.y1); |
| 2813 | bb.x2 = max_t(int, bb.x2, clip.x2); |
| 2814 | bb.y2 = max_t(int, bb.y2, clip.y2); |
| 2815 | } |
| 2816 | |
| 2817 | curr_size = update->post_clip(update, cmd_next, &bb); |
| 2818 | submit_size += curr_size; |
| 2819 | |
| 2820 | if (reserved_size < submit_size) |
| 2821 | submit_size = 0; |
| 2822 | |
Zack Rusin | 8426ed9 | 2020-11-18 12:54:19 -0500 | [diff] [blame] | 2823 | vmw_cmd_commit(update->dev_priv, submit_size); |
Deepak Rawat | e41774c | 2018-07-11 15:42:45 -0700 | [diff] [blame] | 2824 | |
| 2825 | vmw_kms_helper_validation_finish(update->dev_priv, NULL, &val_ctx, |
| 2826 | update->out_fence, NULL); |
| 2827 | return ret; |
| 2828 | |
| 2829 | out_revert: |
| 2830 | vmw_validation_revert(&val_ctx); |
| 2831 | |
| 2832 | out_unref: |
| 2833 | vmw_validation_unref_lists(&val_ctx); |
| 2834 | return ret; |
| 2835 | } |