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