Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 1 | /************************************************************************** |
| 2 | * |
Sinclair Yeh | 54fbde8 | 2015-07-29 12:38:02 -0700 | [diff] [blame] | 3 | * Copyright © 2009-2015 VMware, Inc., Palo Alto, CA., USA |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 4 | * All Rights Reserved. |
| 5 | * |
| 6 | * Permission is hereby granted, free of charge, to any person obtaining a |
| 7 | * copy of this software and associated documentation files (the |
| 8 | * "Software"), to deal in the Software without restriction, including |
| 9 | * without limitation the rights to use, copy, modify, merge, publish, |
| 10 | * distribute, sub license, and/or sell copies of the Software, and to |
| 11 | * permit persons to whom the Software is furnished to do so, subject to |
| 12 | * the following conditions: |
| 13 | * |
| 14 | * The above copyright notice and this permission notice (including the |
| 15 | * next paragraph) shall be included in all copies or substantial portions |
| 16 | * of the Software. |
| 17 | * |
| 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL |
| 21 | * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, |
| 22 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR |
| 23 | * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE |
| 24 | * USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 25 | * |
| 26 | **************************************************************************/ |
| 27 | |
| 28 | #include "vmwgfx_kms.h" |
| 29 | |
Jakob Bornecrantz | 56d1c78 | 2011-10-04 20:13:22 +0200 | [diff] [blame] | 30 | |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 31 | /* Might need a hrtimer here? */ |
| 32 | #define VMWGFX_PRESENT_RATE ((HZ / 60 > 0) ? HZ / 60 : 1) |
| 33 | |
Sinclair Yeh | c8261a9 | 2015-06-26 01:23:42 -0700 | [diff] [blame] | 34 | void vmw_du_cleanup(struct vmw_display_unit *du) |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 35 | { |
| 36 | if (du->cursor_surface) |
| 37 | vmw_surface_unreference(&du->cursor_surface); |
| 38 | if (du->cursor_dmabuf) |
| 39 | vmw_dmabuf_unreference(&du->cursor_dmabuf); |
Thomas Wood | 34ea3d3 | 2014-05-29 16:57:41 +0100 | [diff] [blame] | 40 | drm_connector_unregister(&du->connector); |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 41 | drm_crtc_cleanup(&du->crtc); |
| 42 | drm_encoder_cleanup(&du->encoder); |
| 43 | drm_connector_cleanup(&du->connector); |
| 44 | } |
| 45 | |
| 46 | /* |
| 47 | * Display Unit Cursor functions |
| 48 | */ |
| 49 | |
| 50 | int vmw_cursor_update_image(struct vmw_private *dev_priv, |
| 51 | u32 *image, u32 width, u32 height, |
| 52 | u32 hotspotX, u32 hotspotY) |
| 53 | { |
| 54 | struct { |
| 55 | u32 cmd; |
| 56 | SVGAFifoCmdDefineAlphaCursor cursor; |
| 57 | } *cmd; |
| 58 | u32 image_size = width * height * 4; |
| 59 | u32 cmd_size = sizeof(*cmd) + image_size; |
| 60 | |
| 61 | if (!image) |
| 62 | return -EINVAL; |
| 63 | |
| 64 | cmd = vmw_fifo_reserve(dev_priv, cmd_size); |
| 65 | if (unlikely(cmd == NULL)) { |
| 66 | DRM_ERROR("Fifo reserve failed.\n"); |
| 67 | return -ENOMEM; |
| 68 | } |
| 69 | |
| 70 | memset(cmd, 0, sizeof(*cmd)); |
| 71 | |
| 72 | memcpy(&cmd[1], image, image_size); |
| 73 | |
Thomas Hellstrom | b9eb1a6 | 2015-04-02 02:39:45 -0700 | [diff] [blame] | 74 | cmd->cmd = SVGA_CMD_DEFINE_ALPHA_CURSOR; |
| 75 | cmd->cursor.id = 0; |
| 76 | cmd->cursor.width = width; |
| 77 | cmd->cursor.height = height; |
| 78 | cmd->cursor.hotspotX = hotspotX; |
| 79 | cmd->cursor.hotspotY = hotspotY; |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 80 | |
Thomas Hellstrom | 4e0858a | 2015-11-05 02:18:55 -0800 | [diff] [blame] | 81 | vmw_fifo_commit_flush(dev_priv, cmd_size); |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 82 | |
| 83 | return 0; |
| 84 | } |
| 85 | |
Jakob Bornecrantz | 6a91d97 | 2011-11-28 13:19:10 +0100 | [diff] [blame] | 86 | int vmw_cursor_update_dmabuf(struct vmw_private *dev_priv, |
| 87 | struct vmw_dma_buffer *dmabuf, |
| 88 | u32 width, u32 height, |
| 89 | u32 hotspotX, u32 hotspotY) |
| 90 | { |
| 91 | struct ttm_bo_kmap_obj map; |
| 92 | unsigned long kmap_offset; |
| 93 | unsigned long kmap_num; |
| 94 | void *virtual; |
| 95 | bool dummy; |
| 96 | int ret; |
| 97 | |
| 98 | kmap_offset = 0; |
| 99 | kmap_num = (width*height*4 + PAGE_SIZE - 1) >> PAGE_SHIFT; |
| 100 | |
Thierry Reding | ee3939e | 2014-07-21 13:15:51 +0200 | [diff] [blame] | 101 | ret = ttm_bo_reserve(&dmabuf->base, true, false, false, NULL); |
Jakob Bornecrantz | 6a91d97 | 2011-11-28 13:19:10 +0100 | [diff] [blame] | 102 | if (unlikely(ret != 0)) { |
| 103 | DRM_ERROR("reserve failed\n"); |
| 104 | return -EINVAL; |
| 105 | } |
| 106 | |
| 107 | ret = ttm_bo_kmap(&dmabuf->base, kmap_offset, kmap_num, &map); |
| 108 | if (unlikely(ret != 0)) |
| 109 | goto err_unreserve; |
| 110 | |
| 111 | virtual = ttm_kmap_obj_virtual(&map, &dummy); |
| 112 | ret = vmw_cursor_update_image(dev_priv, virtual, width, height, |
| 113 | hotspotX, hotspotY); |
| 114 | |
| 115 | ttm_bo_kunmap(&map); |
| 116 | err_unreserve: |
| 117 | ttm_bo_unreserve(&dmabuf->base); |
| 118 | |
| 119 | return ret; |
| 120 | } |
| 121 | |
| 122 | |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 123 | void vmw_cursor_update_position(struct vmw_private *dev_priv, |
| 124 | bool show, int x, int y) |
| 125 | { |
Thomas Hellstrom | b76ff5e | 2015-10-28 10:44:04 +0100 | [diff] [blame] | 126 | u32 *fifo_mem = dev_priv->mmio_virt; |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 127 | uint32_t count; |
| 128 | |
Thomas Hellstrom | b76ff5e | 2015-10-28 10:44:04 +0100 | [diff] [blame] | 129 | vmw_mmio_write(show ? 1 : 0, fifo_mem + SVGA_FIFO_CURSOR_ON); |
| 130 | vmw_mmio_write(x, fifo_mem + SVGA_FIFO_CURSOR_X); |
| 131 | vmw_mmio_write(y, fifo_mem + SVGA_FIFO_CURSOR_Y); |
| 132 | count = vmw_mmio_read(fifo_mem + SVGA_FIFO_CURSOR_COUNT); |
| 133 | vmw_mmio_write(++count, fifo_mem + SVGA_FIFO_CURSOR_COUNT); |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 134 | } |
| 135 | |
| 136 | int vmw_du_crtc_cursor_set(struct drm_crtc *crtc, struct drm_file *file_priv, |
| 137 | uint32_t handle, uint32_t width, uint32_t height) |
| 138 | { |
| 139 | struct vmw_private *dev_priv = vmw_priv(crtc->dev); |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 140 | struct vmw_display_unit *du = vmw_crtc_to_du(crtc); |
| 141 | struct vmw_surface *surface = NULL; |
| 142 | struct vmw_dma_buffer *dmabuf = NULL; |
| 143 | int ret; |
| 144 | |
Daniel Vetter | bfb8992 | 2012-12-02 13:48:21 +0100 | [diff] [blame] | 145 | /* |
| 146 | * FIXME: Unclear whether there's any global state touched by the |
| 147 | * cursor_set function, especially vmw_cursor_update_position looks |
| 148 | * suspicious. For now take the easy route and reacquire all locks. We |
| 149 | * can do this since the caller in the drm core doesn't check anything |
| 150 | * which is protected by any looks. |
| 151 | */ |
Rob Clark | 21e8862 | 2014-10-30 13:39:04 -0400 | [diff] [blame] | 152 | drm_modeset_unlock_crtc(crtc); |
Daniel Vetter | bfb8992 | 2012-12-02 13:48:21 +0100 | [diff] [blame] | 153 | drm_modeset_lock_all(dev_priv->dev); |
| 154 | |
Jakob Bornecrantz | baa91d64 | 2011-11-09 10:25:28 +0100 | [diff] [blame] | 155 | /* A lot of the code assumes this */ |
Daniel Vetter | bfb8992 | 2012-12-02 13:48:21 +0100 | [diff] [blame] | 156 | if (handle && (width != 64 || height != 64)) { |
| 157 | ret = -EINVAL; |
| 158 | goto out; |
| 159 | } |
Jakob Bornecrantz | baa91d64 | 2011-11-09 10:25:28 +0100 | [diff] [blame] | 160 | |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 161 | if (handle) { |
Ville Syrjälä | a5d0f57 | 2013-06-03 16:10:41 +0300 | [diff] [blame] | 162 | struct ttm_object_file *tfile = vmw_fpriv(file_priv)->tfile; |
| 163 | |
Jakob Bornecrantz | e7ac921 | 2011-11-28 13:19:12 +0100 | [diff] [blame] | 164 | ret = vmw_user_lookup_handle(dev_priv, tfile, |
| 165 | handle, &surface, &dmabuf); |
| 166 | if (ret) { |
| 167 | DRM_ERROR("failed to find surface or dmabuf: %i\n", ret); |
Daniel Vetter | bfb8992 | 2012-12-02 13:48:21 +0100 | [diff] [blame] | 168 | ret = -EINVAL; |
| 169 | goto out; |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 170 | } |
| 171 | } |
| 172 | |
Jakob Bornecrantz | e7ac921 | 2011-11-28 13:19:12 +0100 | [diff] [blame] | 173 | /* need to do this before taking down old image */ |
| 174 | if (surface && !surface->snooper.image) { |
| 175 | DRM_ERROR("surface not suitable for cursor\n"); |
| 176 | vmw_surface_unreference(&surface); |
Daniel Vetter | bfb8992 | 2012-12-02 13:48:21 +0100 | [diff] [blame] | 177 | ret = -EINVAL; |
| 178 | goto out; |
Jakob Bornecrantz | e7ac921 | 2011-11-28 13:19:12 +0100 | [diff] [blame] | 179 | } |
| 180 | |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 181 | /* takedown old cursor */ |
| 182 | if (du->cursor_surface) { |
| 183 | du->cursor_surface->snooper.crtc = NULL; |
| 184 | vmw_surface_unreference(&du->cursor_surface); |
| 185 | } |
| 186 | if (du->cursor_dmabuf) |
| 187 | vmw_dmabuf_unreference(&du->cursor_dmabuf); |
| 188 | |
| 189 | /* setup new image */ |
| 190 | if (surface) { |
| 191 | /* vmw_user_surface_lookup takes one reference */ |
| 192 | du->cursor_surface = surface; |
| 193 | |
| 194 | du->cursor_surface->snooper.crtc = crtc; |
| 195 | du->cursor_age = du->cursor_surface->snooper.age; |
| 196 | vmw_cursor_update_image(dev_priv, surface->snooper.image, |
| 197 | 64, 64, du->hotspot_x, du->hotspot_y); |
| 198 | } else if (dmabuf) { |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 199 | /* vmw_user_surface_lookup takes one reference */ |
| 200 | du->cursor_dmabuf = dmabuf; |
| 201 | |
Jakob Bornecrantz | 6a91d97 | 2011-11-28 13:19:10 +0100 | [diff] [blame] | 202 | ret = vmw_cursor_update_dmabuf(dev_priv, dmabuf, width, height, |
| 203 | du->hotspot_x, du->hotspot_y); |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 204 | } else { |
| 205 | vmw_cursor_update_position(dev_priv, false, 0, 0); |
Daniel Vetter | bfb8992 | 2012-12-02 13:48:21 +0100 | [diff] [blame] | 206 | ret = 0; |
| 207 | goto out; |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 208 | } |
| 209 | |
Thomas Hellstrom | da7653d | 2011-11-02 09:43:12 +0100 | [diff] [blame] | 210 | vmw_cursor_update_position(dev_priv, true, |
| 211 | du->cursor_x + du->hotspot_x, |
| 212 | du->cursor_y + du->hotspot_y); |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 213 | |
Daniel Vetter | bfb8992 | 2012-12-02 13:48:21 +0100 | [diff] [blame] | 214 | ret = 0; |
| 215 | out: |
| 216 | drm_modeset_unlock_all(dev_priv->dev); |
Daniel Vetter | 4d02e2d | 2014-11-11 10:12:00 +0100 | [diff] [blame] | 217 | drm_modeset_lock_crtc(crtc, crtc->cursor); |
Daniel Vetter | bfb8992 | 2012-12-02 13:48:21 +0100 | [diff] [blame] | 218 | |
| 219 | return ret; |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 220 | } |
| 221 | |
| 222 | int vmw_du_crtc_cursor_move(struct drm_crtc *crtc, int x, int y) |
| 223 | { |
| 224 | struct vmw_private *dev_priv = vmw_priv(crtc->dev); |
| 225 | struct vmw_display_unit *du = vmw_crtc_to_du(crtc); |
| 226 | bool shown = du->cursor_surface || du->cursor_dmabuf ? true : false; |
| 227 | |
| 228 | du->cursor_x = x + crtc->x; |
| 229 | du->cursor_y = y + crtc->y; |
| 230 | |
Daniel Vetter | dac3566 | 2012-12-02 15:24:10 +0100 | [diff] [blame] | 231 | /* |
| 232 | * FIXME: Unclear whether there's any global state touched by the |
| 233 | * cursor_set function, especially vmw_cursor_update_position looks |
| 234 | * suspicious. For now take the easy route and reacquire all locks. We |
| 235 | * can do this since the caller in the drm core doesn't check anything |
| 236 | * which is protected by any looks. |
| 237 | */ |
Rob Clark | 21e8862 | 2014-10-30 13:39:04 -0400 | [diff] [blame] | 238 | drm_modeset_unlock_crtc(crtc); |
Daniel Vetter | dac3566 | 2012-12-02 15:24:10 +0100 | [diff] [blame] | 239 | drm_modeset_lock_all(dev_priv->dev); |
| 240 | |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 241 | vmw_cursor_update_position(dev_priv, shown, |
Thomas Hellstrom | da7653d | 2011-11-02 09:43:12 +0100 | [diff] [blame] | 242 | du->cursor_x + du->hotspot_x, |
| 243 | du->cursor_y + du->hotspot_y); |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 244 | |
Daniel Vetter | dac3566 | 2012-12-02 15:24:10 +0100 | [diff] [blame] | 245 | drm_modeset_unlock_all(dev_priv->dev); |
Daniel Vetter | 4d02e2d | 2014-11-11 10:12:00 +0100 | [diff] [blame] | 246 | drm_modeset_lock_crtc(crtc, crtc->cursor); |
Daniel Vetter | dac3566 | 2012-12-02 15:24:10 +0100 | [diff] [blame] | 247 | |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 248 | return 0; |
| 249 | } |
| 250 | |
| 251 | void vmw_kms_cursor_snoop(struct vmw_surface *srf, |
| 252 | struct ttm_object_file *tfile, |
| 253 | struct ttm_buffer_object *bo, |
| 254 | SVGA3dCmdHeader *header) |
| 255 | { |
| 256 | struct ttm_bo_kmap_obj map; |
| 257 | unsigned long kmap_offset; |
| 258 | unsigned long kmap_num; |
| 259 | SVGA3dCopyBox *box; |
| 260 | unsigned box_count; |
| 261 | void *virtual; |
| 262 | bool dummy; |
| 263 | struct vmw_dma_cmd { |
| 264 | SVGA3dCmdHeader header; |
| 265 | SVGA3dCmdSurfaceDMA dma; |
| 266 | } *cmd; |
Jakob Bornecrantz | 2ac8637 | 2011-11-03 21:03:08 +0100 | [diff] [blame] | 267 | int i, ret; |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 268 | |
| 269 | cmd = container_of(header, struct vmw_dma_cmd, header); |
| 270 | |
| 271 | /* No snooper installed */ |
| 272 | if (!srf->snooper.image) |
| 273 | return; |
| 274 | |
| 275 | if (cmd->dma.host.face != 0 || cmd->dma.host.mipmap != 0) { |
| 276 | DRM_ERROR("face and mipmap for cursors should never != 0\n"); |
| 277 | return; |
| 278 | } |
| 279 | |
| 280 | if (cmd->header.size < 64) { |
| 281 | DRM_ERROR("at least one full copy box must be given\n"); |
| 282 | return; |
| 283 | } |
| 284 | |
| 285 | box = (SVGA3dCopyBox *)&cmd[1]; |
| 286 | box_count = (cmd->header.size - sizeof(SVGA3dCmdSurfaceDMA)) / |
| 287 | sizeof(SVGA3dCopyBox); |
| 288 | |
Jakob Bornecrantz | 2ac8637 | 2011-11-03 21:03:08 +0100 | [diff] [blame] | 289 | if (cmd->dma.guest.ptr.offset % PAGE_SIZE || |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 290 | box->x != 0 || box->y != 0 || box->z != 0 || |
| 291 | box->srcx != 0 || box->srcy != 0 || box->srcz != 0 || |
Jakob Bornecrantz | 2ac8637 | 2011-11-03 21:03:08 +0100 | [diff] [blame] | 292 | box->d != 1 || box_count != 1) { |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 293 | /* TODO handle none page aligned offsets */ |
Jakob Bornecrantz | 2ac8637 | 2011-11-03 21:03:08 +0100 | [diff] [blame] | 294 | /* TODO handle more dst & src != 0 */ |
| 295 | /* TODO handle more then one copy */ |
| 296 | DRM_ERROR("Cant snoop dma request for cursor!\n"); |
| 297 | DRM_ERROR("(%u, %u, %u) (%u, %u, %u) (%ux%ux%u) %u %u\n", |
| 298 | box->srcx, box->srcy, box->srcz, |
| 299 | box->x, box->y, box->z, |
| 300 | box->w, box->h, box->d, box_count, |
| 301 | cmd->dma.guest.ptr.offset); |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 302 | return; |
| 303 | } |
| 304 | |
| 305 | kmap_offset = cmd->dma.guest.ptr.offset >> PAGE_SHIFT; |
| 306 | kmap_num = (64*64*4) >> PAGE_SHIFT; |
| 307 | |
Thierry Reding | ee3939e | 2014-07-21 13:15:51 +0200 | [diff] [blame] | 308 | ret = ttm_bo_reserve(bo, true, false, false, NULL); |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 309 | if (unlikely(ret != 0)) { |
| 310 | DRM_ERROR("reserve failed\n"); |
| 311 | return; |
| 312 | } |
| 313 | |
| 314 | ret = ttm_bo_kmap(bo, kmap_offset, kmap_num, &map); |
| 315 | if (unlikely(ret != 0)) |
| 316 | goto err_unreserve; |
| 317 | |
| 318 | virtual = ttm_kmap_obj_virtual(&map, &dummy); |
| 319 | |
Jakob Bornecrantz | 2ac8637 | 2011-11-03 21:03:08 +0100 | [diff] [blame] | 320 | if (box->w == 64 && cmd->dma.guest.pitch == 64*4) { |
| 321 | memcpy(srf->snooper.image, virtual, 64*64*4); |
| 322 | } else { |
| 323 | /* Image is unsigned pointer. */ |
| 324 | for (i = 0; i < box->h; i++) |
| 325 | memcpy(srf->snooper.image + i * 64, |
| 326 | virtual + i * cmd->dma.guest.pitch, |
| 327 | box->w * 4); |
| 328 | } |
| 329 | |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 330 | srf->snooper.age++; |
| 331 | |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 332 | ttm_bo_kunmap(&map); |
| 333 | err_unreserve: |
| 334 | ttm_bo_unreserve(bo); |
| 335 | } |
| 336 | |
| 337 | void vmw_kms_cursor_post_execbuf(struct vmw_private *dev_priv) |
| 338 | { |
| 339 | struct drm_device *dev = dev_priv->dev; |
| 340 | struct vmw_display_unit *du; |
| 341 | struct drm_crtc *crtc; |
| 342 | |
| 343 | mutex_lock(&dev->mode_config.mutex); |
| 344 | |
| 345 | list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) { |
| 346 | du = vmw_crtc_to_du(crtc); |
| 347 | if (!du->cursor_surface || |
| 348 | du->cursor_age == du->cursor_surface->snooper.age) |
| 349 | continue; |
| 350 | |
| 351 | du->cursor_age = du->cursor_surface->snooper.age; |
| 352 | vmw_cursor_update_image(dev_priv, |
| 353 | du->cursor_surface->snooper.image, |
| 354 | 64, 64, du->hotspot_x, du->hotspot_y); |
| 355 | } |
| 356 | |
| 357 | mutex_unlock(&dev->mode_config.mutex); |
| 358 | } |
| 359 | |
| 360 | /* |
| 361 | * Generic framebuffer code |
| 362 | */ |
| 363 | |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 364 | /* |
| 365 | * Surface framebuffer code |
| 366 | */ |
| 367 | |
Rashika Kheria | 847c596 | 2014-01-06 22:18:10 +0530 | [diff] [blame] | 368 | static void vmw_framebuffer_surface_destroy(struct drm_framebuffer *framebuffer) |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 369 | { |
Thomas Hellstrom | 3a939a5 | 2010-10-05 12:43:03 +0200 | [diff] [blame] | 370 | struct vmw_framebuffer_surface *vfbs = |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 371 | vmw_framebuffer_to_vfbs(framebuffer); |
| 372 | |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 373 | drm_framebuffer_cleanup(framebuffer); |
Thomas Hellstrom | 3a939a5 | 2010-10-05 12:43:03 +0200 | [diff] [blame] | 374 | vmw_surface_unreference(&vfbs->surface); |
Thomas Hellstrom | a278724 | 2015-06-29 12:55:07 -0700 | [diff] [blame] | 375 | if (vfbs->base.user_obj) |
| 376 | ttm_base_object_unref(&vfbs->base.user_obj); |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 377 | |
Thomas Hellstrom | 3a939a5 | 2010-10-05 12:43:03 +0200 | [diff] [blame] | 378 | kfree(vfbs); |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 379 | } |
| 380 | |
Rashika Kheria | 847c596 | 2014-01-06 22:18:10 +0530 | [diff] [blame] | 381 | static int vmw_framebuffer_surface_dirty(struct drm_framebuffer *framebuffer, |
Thomas Hellstrom | 02b0016 | 2010-10-05 12:43:02 +0200 | [diff] [blame] | 382 | struct drm_file *file_priv, |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 383 | unsigned flags, unsigned color, |
| 384 | struct drm_clip_rect *clips, |
| 385 | unsigned num_clips) |
| 386 | { |
| 387 | struct vmw_private *dev_priv = vmw_priv(framebuffer->dev); |
| 388 | struct vmw_framebuffer_surface *vfbs = |
| 389 | vmw_framebuffer_to_vfbs(framebuffer); |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 390 | struct drm_clip_rect norect; |
Jakob Bornecrantz | 5deb65c | 2011-10-04 20:13:18 +0200 | [diff] [blame] | 391 | int ret, inc = 1; |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 392 | |
Sinclair Yeh | c8261a9 | 2015-06-26 01:23:42 -0700 | [diff] [blame] | 393 | /* Legacy Display Unit does not support 3D */ |
| 394 | if (dev_priv->active_display_unit == vmw_du_legacy) |
Jakob Bornecrantz | 01e8141 | 2011-10-04 20:13:24 +0200 | [diff] [blame] | 395 | return -EINVAL; |
| 396 | |
Ville Syrjälä | 73e9efd | 2013-12-04 14:13:58 +0200 | [diff] [blame] | 397 | drm_modeset_lock_all(dev_priv->dev); |
| 398 | |
Thomas Hellstrom | 294adf7 | 2014-02-27 12:34:51 +0100 | [diff] [blame] | 399 | ret = ttm_read_lock(&dev_priv->reservation_sem, true); |
Ville Syrjälä | 73e9efd | 2013-12-04 14:13:58 +0200 | [diff] [blame] | 400 | if (unlikely(ret != 0)) { |
| 401 | drm_modeset_unlock_all(dev_priv->dev); |
Thomas Hellstrom | 3a939a5 | 2010-10-05 12:43:03 +0200 | [diff] [blame] | 402 | return ret; |
Ville Syrjälä | 73e9efd | 2013-12-04 14:13:58 +0200 | [diff] [blame] | 403 | } |
Thomas Hellstrom | 3a939a5 | 2010-10-05 12:43:03 +0200 | [diff] [blame] | 404 | |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 405 | if (!num_clips) { |
| 406 | num_clips = 1; |
| 407 | clips = &norect; |
| 408 | norect.x1 = norect.y1 = 0; |
| 409 | norect.x2 = framebuffer->width; |
| 410 | norect.y2 = framebuffer->height; |
| 411 | } else if (flags & DRM_MODE_FB_DIRTY_ANNOTATE_COPY) { |
| 412 | num_clips /= 2; |
| 413 | inc = 2; /* skip source rects */ |
| 414 | } |
| 415 | |
Sinclair Yeh | c8261a9 | 2015-06-26 01:23:42 -0700 | [diff] [blame] | 416 | if (dev_priv->active_display_unit == vmw_du_screen_object) |
Thomas Hellstrom | 10b1e0c | 2015-06-26 02:14:27 -0700 | [diff] [blame] | 417 | ret = vmw_kms_sou_do_surface_dirty(dev_priv, &vfbs->base, |
| 418 | clips, NULL, NULL, 0, 0, |
| 419 | num_clips, inc, NULL); |
Sinclair Yeh | 35c0512 | 2015-06-26 01:42:06 -0700 | [diff] [blame] | 420 | else |
Thomas Hellstrom | 6bf6bf0 | 2015-06-26 02:22:40 -0700 | [diff] [blame] | 421 | ret = vmw_kms_stdu_surface_dirty(dev_priv, &vfbs->base, |
| 422 | clips, NULL, NULL, 0, 0, |
| 423 | num_clips, inc, NULL); |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 424 | |
Thomas Hellstrom | 3eab3d9 | 2015-06-25 11:57:56 -0700 | [diff] [blame] | 425 | vmw_fifo_flush(dev_priv, false); |
Thomas Hellstrom | 294adf7 | 2014-02-27 12:34:51 +0100 | [diff] [blame] | 426 | ttm_read_unlock(&dev_priv->reservation_sem); |
Ville Syrjälä | 73e9efd | 2013-12-04 14:13:58 +0200 | [diff] [blame] | 427 | |
| 428 | drm_modeset_unlock_all(dev_priv->dev); |
| 429 | |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 430 | return 0; |
| 431 | } |
| 432 | |
Thomas Hellstrom | 10b1e0c | 2015-06-26 02:14:27 -0700 | [diff] [blame] | 433 | /** |
| 434 | * vmw_kms_readback - Perform a readback from the screen system to |
| 435 | * a dma-buffer backed framebuffer. |
| 436 | * |
| 437 | * @dev_priv: Pointer to the device private structure. |
| 438 | * @file_priv: Pointer to a struct drm_file identifying the caller. |
| 439 | * Must be set to NULL if @user_fence_rep is NULL. |
| 440 | * @vfb: Pointer to the dma-buffer backed framebuffer. |
| 441 | * @user_fence_rep: User-space provided structure for fence information. |
| 442 | * Must be set to non-NULL if @file_priv is non-NULL. |
| 443 | * @vclips: Array of clip rects. |
| 444 | * @num_clips: Number of clip rects in @vclips. |
| 445 | * |
| 446 | * Returns 0 on success, negative error code on failure. -ERESTARTSYS if |
| 447 | * interrupted. |
| 448 | */ |
| 449 | int vmw_kms_readback(struct vmw_private *dev_priv, |
| 450 | struct drm_file *file_priv, |
| 451 | struct vmw_framebuffer *vfb, |
| 452 | struct drm_vmw_fence_rep __user *user_fence_rep, |
| 453 | struct drm_vmw_rect *vclips, |
| 454 | uint32_t num_clips) |
| 455 | { |
| 456 | switch (dev_priv->active_display_unit) { |
| 457 | case vmw_du_screen_object: |
| 458 | return vmw_kms_sou_readback(dev_priv, file_priv, vfb, |
| 459 | user_fence_rep, vclips, num_clips); |
Thomas Hellstrom | 6bf6bf0 | 2015-06-26 02:22:40 -0700 | [diff] [blame] | 460 | case vmw_du_screen_target: |
| 461 | return vmw_kms_stdu_dma(dev_priv, file_priv, vfb, |
| 462 | user_fence_rep, NULL, vclips, num_clips, |
| 463 | 1, false, true); |
Thomas Hellstrom | 10b1e0c | 2015-06-26 02:14:27 -0700 | [diff] [blame] | 464 | default: |
| 465 | WARN_ONCE(true, |
| 466 | "Readback called with invalid display system.\n"); |
Thomas Hellstrom | 6bf6bf0 | 2015-06-26 02:22:40 -0700 | [diff] [blame] | 467 | } |
Thomas Hellstrom | 10b1e0c | 2015-06-26 02:14:27 -0700 | [diff] [blame] | 468 | |
| 469 | return -ENOSYS; |
| 470 | } |
| 471 | |
| 472 | |
Ville Syrjälä | d7955fc | 2015-12-15 12:21:15 +0100 | [diff] [blame^] | 473 | static const struct drm_framebuffer_funcs vmw_framebuffer_surface_funcs = { |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 474 | .destroy = vmw_framebuffer_surface_destroy, |
| 475 | .dirty = vmw_framebuffer_surface_dirty, |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 476 | }; |
| 477 | |
Thomas Hellstrom | d3216a0 | 2010-10-05 12:42:59 +0200 | [diff] [blame] | 478 | static int vmw_kms_new_framebuffer_surface(struct vmw_private *dev_priv, |
| 479 | struct vmw_surface *surface, |
| 480 | struct vmw_framebuffer **out, |
| 481 | const struct drm_mode_fb_cmd |
Sinclair Yeh | f89c6c3 | 2015-06-26 01:54:28 -0700 | [diff] [blame] | 482 | *mode_cmd, |
| 483 | bool is_dmabuf_proxy) |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 484 | |
| 485 | { |
| 486 | struct drm_device *dev = dev_priv->dev; |
| 487 | struct vmw_framebuffer_surface *vfbs; |
Thomas Hellstrom | d3216a0 | 2010-10-05 12:42:59 +0200 | [diff] [blame] | 488 | enum SVGA3dSurfaceFormat format; |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 489 | int ret; |
| 490 | |
Sinclair Yeh | c8261a9 | 2015-06-26 01:23:42 -0700 | [diff] [blame] | 491 | /* 3D is only supported on HWv8 and newer hosts */ |
| 492 | if (dev_priv->active_display_unit == vmw_du_legacy) |
Jakob Bornecrantz | 01e8141 | 2011-10-04 20:13:24 +0200 | [diff] [blame] | 493 | return -ENOSYS; |
| 494 | |
Thomas Hellstrom | d3216a0 | 2010-10-05 12:42:59 +0200 | [diff] [blame] | 495 | /* |
| 496 | * Sanity checks. |
| 497 | */ |
| 498 | |
Jakob Bornecrantz | e7ac921 | 2011-11-28 13:19:12 +0100 | [diff] [blame] | 499 | /* Surface must be marked as a scanout. */ |
| 500 | if (unlikely(!surface->scanout)) |
| 501 | return -EINVAL; |
| 502 | |
Thomas Hellstrom | d3216a0 | 2010-10-05 12:42:59 +0200 | [diff] [blame] | 503 | if (unlikely(surface->mip_levels[0] != 1 || |
| 504 | surface->num_sizes != 1 || |
Thomas Hellstrom | b360a3c | 2014-01-15 08:51:36 +0100 | [diff] [blame] | 505 | surface->base_size.width < mode_cmd->width || |
| 506 | surface->base_size.height < mode_cmd->height || |
| 507 | surface->base_size.depth != 1)) { |
Thomas Hellstrom | d3216a0 | 2010-10-05 12:42:59 +0200 | [diff] [blame] | 508 | DRM_ERROR("Incompatible surface dimensions " |
| 509 | "for requested mode.\n"); |
| 510 | return -EINVAL; |
| 511 | } |
| 512 | |
| 513 | switch (mode_cmd->depth) { |
| 514 | case 32: |
| 515 | format = SVGA3D_A8R8G8B8; |
| 516 | break; |
| 517 | case 24: |
| 518 | format = SVGA3D_X8R8G8B8; |
| 519 | break; |
| 520 | case 16: |
| 521 | format = SVGA3D_R5G6B5; |
| 522 | break; |
| 523 | case 15: |
| 524 | format = SVGA3D_A1R5G5B5; |
| 525 | break; |
| 526 | default: |
| 527 | DRM_ERROR("Invalid color depth: %d\n", mode_cmd->depth); |
| 528 | return -EINVAL; |
| 529 | } |
| 530 | |
Thomas Hellstrom | d80efd5 | 2015-08-10 10:39:35 -0700 | [diff] [blame] | 531 | /* |
| 532 | * For DX, surface format validation is done when surface->scanout |
| 533 | * is set. |
| 534 | */ |
| 535 | if (!dev_priv->has_dx && format != surface->format) { |
Thomas Hellstrom | d3216a0 | 2010-10-05 12:42:59 +0200 | [diff] [blame] | 536 | DRM_ERROR("Invalid surface format for requested mode.\n"); |
| 537 | return -EINVAL; |
| 538 | } |
| 539 | |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 540 | vfbs = kzalloc(sizeof(*vfbs), GFP_KERNEL); |
| 541 | if (!vfbs) { |
| 542 | ret = -ENOMEM; |
| 543 | goto out_err1; |
| 544 | } |
| 545 | |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 546 | /* XXX get the first 3 from the surface info */ |
Thomas Hellstrom | d3216a0 | 2010-10-05 12:42:59 +0200 | [diff] [blame] | 547 | vfbs->base.base.bits_per_pixel = mode_cmd->bpp; |
Ville Syrjälä | 01f2c77 | 2011-12-20 00:06:49 +0200 | [diff] [blame] | 548 | vfbs->base.base.pitches[0] = mode_cmd->pitch; |
Thomas Hellstrom | d3216a0 | 2010-10-05 12:42:59 +0200 | [diff] [blame] | 549 | vfbs->base.base.depth = mode_cmd->depth; |
| 550 | vfbs->base.base.width = mode_cmd->width; |
| 551 | vfbs->base.base.height = mode_cmd->height; |
Sinclair Yeh | 05c9501 | 2015-08-11 22:53:39 -0700 | [diff] [blame] | 552 | vfbs->surface = vmw_surface_reference(surface); |
Thomas Hellstrom | 90ff18b | 2011-10-04 20:13:32 +0200 | [diff] [blame] | 553 | vfbs->base.user_handle = mode_cmd->handle; |
Sinclair Yeh | f89c6c3 | 2015-06-26 01:54:28 -0700 | [diff] [blame] | 554 | vfbs->is_dmabuf_proxy = is_dmabuf_proxy; |
Thomas Hellstrom | 3a939a5 | 2010-10-05 12:43:03 +0200 | [diff] [blame] | 555 | |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 556 | *out = &vfbs->base; |
| 557 | |
Daniel Vetter | 80f0b5a | 2012-12-13 23:39:01 +0100 | [diff] [blame] | 558 | ret = drm_framebuffer_init(dev, &vfbs->base.base, |
| 559 | &vmw_framebuffer_surface_funcs); |
| 560 | if (ret) |
Sinclair Yeh | 05c9501 | 2015-08-11 22:53:39 -0700 | [diff] [blame] | 561 | goto out_err2; |
Daniel Vetter | 80f0b5a | 2012-12-13 23:39:01 +0100 | [diff] [blame] | 562 | |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 563 | return 0; |
| 564 | |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 565 | out_err2: |
Sinclair Yeh | 05c9501 | 2015-08-11 22:53:39 -0700 | [diff] [blame] | 566 | vmw_surface_unreference(&surface); |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 567 | kfree(vfbs); |
| 568 | out_err1: |
| 569 | return ret; |
| 570 | } |
| 571 | |
| 572 | /* |
| 573 | * Dmabuf framebuffer code |
| 574 | */ |
| 575 | |
Rashika Kheria | 847c596 | 2014-01-06 22:18:10 +0530 | [diff] [blame] | 576 | static void vmw_framebuffer_dmabuf_destroy(struct drm_framebuffer *framebuffer) |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 577 | { |
| 578 | struct vmw_framebuffer_dmabuf *vfbd = |
| 579 | vmw_framebuffer_to_vfbd(framebuffer); |
| 580 | |
| 581 | drm_framebuffer_cleanup(framebuffer); |
| 582 | vmw_dmabuf_unreference(&vfbd->buffer); |
Thomas Hellstrom | a278724 | 2015-06-29 12:55:07 -0700 | [diff] [blame] | 583 | if (vfbd->base.user_obj) |
| 584 | ttm_base_object_unref(&vfbd->base.user_obj); |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 585 | |
| 586 | kfree(vfbd); |
| 587 | } |
| 588 | |
Rashika Kheria | 847c596 | 2014-01-06 22:18:10 +0530 | [diff] [blame] | 589 | static int vmw_framebuffer_dmabuf_dirty(struct drm_framebuffer *framebuffer, |
Thomas Hellstrom | 02b0016 | 2010-10-05 12:43:02 +0200 | [diff] [blame] | 590 | struct drm_file *file_priv, |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 591 | unsigned flags, unsigned color, |
| 592 | struct drm_clip_rect *clips, |
| 593 | unsigned num_clips) |
| 594 | { |
| 595 | struct vmw_private *dev_priv = vmw_priv(framebuffer->dev); |
Jakob Bornecrantz | 5deb65c | 2011-10-04 20:13:18 +0200 | [diff] [blame] | 596 | struct vmw_framebuffer_dmabuf *vfbd = |
| 597 | vmw_framebuffer_to_vfbd(framebuffer); |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 598 | struct drm_clip_rect norect; |
Jakob Bornecrantz | 5deb65c | 2011-10-04 20:13:18 +0200 | [diff] [blame] | 599 | int ret, increment = 1; |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 600 | |
Ville Syrjälä | 73e9efd | 2013-12-04 14:13:58 +0200 | [diff] [blame] | 601 | drm_modeset_lock_all(dev_priv->dev); |
| 602 | |
Thomas Hellstrom | 294adf7 | 2014-02-27 12:34:51 +0100 | [diff] [blame] | 603 | ret = ttm_read_lock(&dev_priv->reservation_sem, true); |
Ville Syrjälä | 73e9efd | 2013-12-04 14:13:58 +0200 | [diff] [blame] | 604 | if (unlikely(ret != 0)) { |
| 605 | drm_modeset_unlock_all(dev_priv->dev); |
Thomas Hellstrom | 3a939a5 | 2010-10-05 12:43:03 +0200 | [diff] [blame] | 606 | return ret; |
Ville Syrjälä | 73e9efd | 2013-12-04 14:13:58 +0200 | [diff] [blame] | 607 | } |
Thomas Hellstrom | 3a939a5 | 2010-10-05 12:43:03 +0200 | [diff] [blame] | 608 | |
Thomas Hellstrom | df1c93b | 2010-01-13 22:28:36 +0100 | [diff] [blame] | 609 | if (!num_clips) { |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 610 | num_clips = 1; |
| 611 | clips = &norect; |
| 612 | norect.x1 = norect.y1 = 0; |
| 613 | norect.x2 = framebuffer->width; |
| 614 | norect.y2 = framebuffer->height; |
| 615 | } else if (flags & DRM_MODE_FB_DIRTY_ANNOTATE_COPY) { |
| 616 | num_clips /= 2; |
| 617 | increment = 2; |
| 618 | } |
| 619 | |
Thomas Hellstrom | 6bf6bf0 | 2015-06-26 02:22:40 -0700 | [diff] [blame] | 620 | switch (dev_priv->active_display_unit) { |
| 621 | case vmw_du_screen_target: |
| 622 | ret = vmw_kms_stdu_dma(dev_priv, NULL, &vfbd->base, NULL, |
| 623 | clips, NULL, num_clips, increment, |
| 624 | true, true); |
| 625 | break; |
| 626 | case vmw_du_screen_object: |
Thomas Hellstrom | 10b1e0c | 2015-06-26 02:14:27 -0700 | [diff] [blame] | 627 | ret = vmw_kms_sou_do_dmabuf_dirty(dev_priv, &vfbd->base, |
Sinclair Yeh | c8261a9 | 2015-06-26 01:23:42 -0700 | [diff] [blame] | 628 | clips, num_clips, increment, |
Thomas Hellstrom | 10b1e0c | 2015-06-26 02:14:27 -0700 | [diff] [blame] | 629 | true, |
Sinclair Yeh | c8261a9 | 2015-06-26 01:23:42 -0700 | [diff] [blame] | 630 | NULL); |
Thomas Hellstrom | 6bf6bf0 | 2015-06-26 02:22:40 -0700 | [diff] [blame] | 631 | break; |
Thomas Hellstrom | 352b20d | 2015-06-29 12:57:37 -0700 | [diff] [blame] | 632 | case vmw_du_legacy: |
| 633 | ret = vmw_kms_ldu_do_dmabuf_dirty(dev_priv, &vfbd->base, 0, 0, |
| 634 | clips, num_clips, increment); |
| 635 | break; |
Thomas Hellstrom | 6bf6bf0 | 2015-06-26 02:22:40 -0700 | [diff] [blame] | 636 | default: |
Thomas Hellstrom | 352b20d | 2015-06-29 12:57:37 -0700 | [diff] [blame] | 637 | ret = -EINVAL; |
| 638 | WARN_ONCE(true, "Dirty called with invalid display system.\n"); |
Thomas Hellstrom | 6bf6bf0 | 2015-06-26 02:22:40 -0700 | [diff] [blame] | 639 | break; |
Jakob Bornecrantz | 56d1c78 | 2011-10-04 20:13:22 +0200 | [diff] [blame] | 640 | } |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 641 | |
Thomas Hellstrom | 3eab3d9 | 2015-06-25 11:57:56 -0700 | [diff] [blame] | 642 | vmw_fifo_flush(dev_priv, false); |
Thomas Hellstrom | 294adf7 | 2014-02-27 12:34:51 +0100 | [diff] [blame] | 643 | ttm_read_unlock(&dev_priv->reservation_sem); |
Ville Syrjälä | 73e9efd | 2013-12-04 14:13:58 +0200 | [diff] [blame] | 644 | |
| 645 | drm_modeset_unlock_all(dev_priv->dev); |
| 646 | |
Jakob Bornecrantz | 5deb65c | 2011-10-04 20:13:18 +0200 | [diff] [blame] | 647 | return ret; |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 648 | } |
| 649 | |
Ville Syrjälä | d7955fc | 2015-12-15 12:21:15 +0100 | [diff] [blame^] | 650 | static const struct drm_framebuffer_funcs vmw_framebuffer_dmabuf_funcs = { |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 651 | .destroy = vmw_framebuffer_dmabuf_destroy, |
| 652 | .dirty = vmw_framebuffer_dmabuf_dirty, |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 653 | }; |
| 654 | |
Jakob Bornecrantz | 497a3ff | 2011-10-04 20:13:14 +0200 | [diff] [blame] | 655 | /** |
Jakob Bornecrantz | 497a3ff | 2011-10-04 20:13:14 +0200 | [diff] [blame] | 656 | * Pin the dmabuffer to the start of vram. |
| 657 | */ |
Thomas Hellstrom | fd006a4 | 2015-06-28 02:50:56 -0700 | [diff] [blame] | 658 | static int vmw_framebuffer_pin(struct vmw_framebuffer *vfb) |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 659 | { |
| 660 | struct vmw_private *dev_priv = vmw_priv(vfb->base.dev); |
Thomas Hellstrom | fd006a4 | 2015-06-28 02:50:56 -0700 | [diff] [blame] | 661 | struct vmw_dma_buffer *buf; |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 662 | int ret; |
| 663 | |
Thomas Hellstrom | fd006a4 | 2015-06-28 02:50:56 -0700 | [diff] [blame] | 664 | buf = vfb->dmabuf ? vmw_framebuffer_to_vfbd(&vfb->base)->buffer : |
| 665 | vmw_framebuffer_to_vfbs(&vfb->base)->surface->res.backup; |
Jakob Bornecrantz | d7e1958 | 2010-05-28 11:21:59 +0200 | [diff] [blame] | 666 | |
Thomas Hellstrom | fd006a4 | 2015-06-28 02:50:56 -0700 | [diff] [blame] | 667 | if (!buf) |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 668 | return 0; |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 669 | |
Thomas Hellstrom | fd006a4 | 2015-06-28 02:50:56 -0700 | [diff] [blame] | 670 | switch (dev_priv->active_display_unit) { |
| 671 | case vmw_du_legacy: |
| 672 | vmw_overlay_pause_all(dev_priv); |
| 673 | ret = vmw_dmabuf_pin_in_start_of_vram(dev_priv, buf, false); |
| 674 | vmw_overlay_resume_all(dev_priv); |
| 675 | break; |
| 676 | case vmw_du_screen_object: |
| 677 | case vmw_du_screen_target: |
| 678 | if (vfb->dmabuf) |
| 679 | return vmw_dmabuf_pin_in_vram_or_gmr(dev_priv, buf, |
| 680 | false); |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 681 | |
Thomas Hellstrom | fd006a4 | 2015-06-28 02:50:56 -0700 | [diff] [blame] | 682 | return vmw_dmabuf_pin_in_placement(dev_priv, buf, |
| 683 | &vmw_mob_placement, false); |
| 684 | default: |
| 685 | return -EINVAL; |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 686 | } |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 687 | |
Thomas Hellstrom | fd006a4 | 2015-06-28 02:50:56 -0700 | [diff] [blame] | 688 | return ret; |
| 689 | } |
| 690 | |
| 691 | static int vmw_framebuffer_unpin(struct vmw_framebuffer *vfb) |
| 692 | { |
| 693 | struct vmw_private *dev_priv = vmw_priv(vfb->base.dev); |
| 694 | struct vmw_dma_buffer *buf; |
| 695 | |
| 696 | buf = vfb->dmabuf ? vmw_framebuffer_to_vfbd(&vfb->base)->buffer : |
| 697 | vmw_framebuffer_to_vfbs(&vfb->base)->surface->res.backup; |
| 698 | |
| 699 | if (WARN_ON(!buf)) |
| 700 | return 0; |
| 701 | |
| 702 | return vmw_dmabuf_unpin(dev_priv, buf, false); |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 703 | } |
| 704 | |
Sinclair Yeh | f89c6c3 | 2015-06-26 01:54:28 -0700 | [diff] [blame] | 705 | /** |
| 706 | * vmw_create_dmabuf_proxy - create a proxy surface for the DMA buf |
| 707 | * |
| 708 | * @dev: DRM device |
| 709 | * @mode_cmd: parameters for the new surface |
| 710 | * @dmabuf_mob: MOB backing the DMA buf |
| 711 | * @srf_out: newly created surface |
| 712 | * |
| 713 | * When the content FB is a DMA buf, we create a surface as a proxy to the |
| 714 | * same buffer. This way we can do a surface copy rather than a surface DMA. |
| 715 | * This is a more efficient approach |
| 716 | * |
| 717 | * RETURNS: |
| 718 | * 0 on success, error code otherwise |
| 719 | */ |
| 720 | static int vmw_create_dmabuf_proxy(struct drm_device *dev, |
Thomas Hellstrom | fd006a4 | 2015-06-28 02:50:56 -0700 | [diff] [blame] | 721 | const struct drm_mode_fb_cmd *mode_cmd, |
Sinclair Yeh | f89c6c3 | 2015-06-26 01:54:28 -0700 | [diff] [blame] | 722 | struct vmw_dma_buffer *dmabuf_mob, |
| 723 | struct vmw_surface **srf_out) |
| 724 | { |
| 725 | uint32_t format; |
| 726 | struct drm_vmw_size content_base_size; |
Thomas Hellstrom | 6bf6bf0 | 2015-06-26 02:22:40 -0700 | [diff] [blame] | 727 | struct vmw_resource *res; |
Sinclair Yeh | f89c6c3 | 2015-06-26 01:54:28 -0700 | [diff] [blame] | 728 | int ret; |
| 729 | |
Sinclair Yeh | f89c6c3 | 2015-06-26 01:54:28 -0700 | [diff] [blame] | 730 | switch (mode_cmd->depth) { |
| 731 | case 32: |
| 732 | case 24: |
| 733 | format = SVGA3D_X8R8G8B8; |
| 734 | break; |
| 735 | |
| 736 | case 16: |
| 737 | case 15: |
| 738 | format = SVGA3D_R5G6B5; |
| 739 | break; |
| 740 | |
| 741 | case 8: |
| 742 | format = SVGA3D_P8; |
| 743 | break; |
| 744 | |
| 745 | default: |
| 746 | DRM_ERROR("Invalid framebuffer format %d\n", mode_cmd->depth); |
| 747 | return -EINVAL; |
| 748 | } |
| 749 | |
| 750 | content_base_size.width = mode_cmd->width; |
| 751 | content_base_size.height = mode_cmd->height; |
| 752 | content_base_size.depth = 1; |
| 753 | |
| 754 | ret = vmw_surface_gb_priv_define(dev, |
| 755 | 0, /* kernel visible only */ |
| 756 | 0, /* flags */ |
| 757 | format, |
| 758 | true, /* can be a scanout buffer */ |
| 759 | 1, /* num of mip levels */ |
| 760 | 0, |
Thomas Hellstrom | d80efd5 | 2015-08-10 10:39:35 -0700 | [diff] [blame] | 761 | 0, |
Sinclair Yeh | f89c6c3 | 2015-06-26 01:54:28 -0700 | [diff] [blame] | 762 | content_base_size, |
| 763 | srf_out); |
| 764 | if (ret) { |
| 765 | DRM_ERROR("Failed to allocate proxy content buffer\n"); |
| 766 | return ret; |
| 767 | } |
| 768 | |
Thomas Hellstrom | 6bf6bf0 | 2015-06-26 02:22:40 -0700 | [diff] [blame] | 769 | res = &(*srf_out)->res; |
Sinclair Yeh | f89c6c3 | 2015-06-26 01:54:28 -0700 | [diff] [blame] | 770 | |
Thomas Hellstrom | 6bf6bf0 | 2015-06-26 02:22:40 -0700 | [diff] [blame] | 771 | /* Reserve and switch the backing mob. */ |
| 772 | mutex_lock(&res->dev_priv->cmdbuf_mutex); |
| 773 | (void) vmw_resource_reserve(res, false, true); |
| 774 | vmw_dmabuf_unreference(&res->backup); |
| 775 | res->backup = vmw_dmabuf_reference(dmabuf_mob); |
| 776 | res->backup_offset = 0; |
Thomas Hellstrom | d80efd5 | 2015-08-10 10:39:35 -0700 | [diff] [blame] | 777 | vmw_resource_unreserve(res, false, NULL, 0); |
Thomas Hellstrom | 6bf6bf0 | 2015-06-26 02:22:40 -0700 | [diff] [blame] | 778 | mutex_unlock(&res->dev_priv->cmdbuf_mutex); |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 779 | |
| 780 | return 0; |
| 781 | } |
| 782 | |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 783 | |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 784 | |
Thomas Hellstrom | d3216a0 | 2010-10-05 12:42:59 +0200 | [diff] [blame] | 785 | static int vmw_kms_new_framebuffer_dmabuf(struct vmw_private *dev_priv, |
| 786 | struct vmw_dma_buffer *dmabuf, |
| 787 | struct vmw_framebuffer **out, |
| 788 | const struct drm_mode_fb_cmd |
| 789 | *mode_cmd) |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 790 | |
| 791 | { |
| 792 | struct drm_device *dev = dev_priv->dev; |
| 793 | struct vmw_framebuffer_dmabuf *vfbd; |
Thomas Hellstrom | d3216a0 | 2010-10-05 12:42:59 +0200 | [diff] [blame] | 794 | unsigned int requested_size; |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 795 | int ret; |
| 796 | |
Thomas Hellstrom | d3216a0 | 2010-10-05 12:42:59 +0200 | [diff] [blame] | 797 | requested_size = mode_cmd->height * mode_cmd->pitch; |
| 798 | if (unlikely(requested_size > dmabuf->base.num_pages * PAGE_SIZE)) { |
| 799 | DRM_ERROR("Screen buffer object size is too small " |
| 800 | "for requested mode.\n"); |
| 801 | return -EINVAL; |
| 802 | } |
| 803 | |
Jakob Bornecrantz | c337ada | 2011-10-04 20:13:34 +0200 | [diff] [blame] | 804 | /* Limited framebuffer color depth support for screen objects */ |
Sinclair Yeh | c8261a9 | 2015-06-26 01:23:42 -0700 | [diff] [blame] | 805 | if (dev_priv->active_display_unit == vmw_du_screen_object) { |
Jakob Bornecrantz | c337ada | 2011-10-04 20:13:34 +0200 | [diff] [blame] | 806 | switch (mode_cmd->depth) { |
| 807 | case 32: |
| 808 | case 24: |
| 809 | /* Only support 32 bpp for 32 and 24 depth fbs */ |
| 810 | if (mode_cmd->bpp == 32) |
| 811 | break; |
| 812 | |
| 813 | DRM_ERROR("Invalid color depth/bbp: %d %d\n", |
| 814 | mode_cmd->depth, mode_cmd->bpp); |
| 815 | return -EINVAL; |
| 816 | case 16: |
| 817 | case 15: |
| 818 | /* Only support 16 bpp for 16 and 15 depth fbs */ |
| 819 | if (mode_cmd->bpp == 16) |
| 820 | break; |
| 821 | |
| 822 | DRM_ERROR("Invalid color depth/bbp: %d %d\n", |
| 823 | mode_cmd->depth, mode_cmd->bpp); |
| 824 | return -EINVAL; |
| 825 | default: |
| 826 | DRM_ERROR("Invalid color depth: %d\n", mode_cmd->depth); |
| 827 | return -EINVAL; |
| 828 | } |
| 829 | } |
| 830 | |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 831 | vfbd = kzalloc(sizeof(*vfbd), GFP_KERNEL); |
| 832 | if (!vfbd) { |
| 833 | ret = -ENOMEM; |
| 834 | goto out_err1; |
| 835 | } |
| 836 | |
Thomas Hellstrom | d3216a0 | 2010-10-05 12:42:59 +0200 | [diff] [blame] | 837 | vfbd->base.base.bits_per_pixel = mode_cmd->bpp; |
Ville Syrjälä | 01f2c77 | 2011-12-20 00:06:49 +0200 | [diff] [blame] | 838 | vfbd->base.base.pitches[0] = mode_cmd->pitch; |
Thomas Hellstrom | d3216a0 | 2010-10-05 12:42:59 +0200 | [diff] [blame] | 839 | vfbd->base.base.depth = mode_cmd->depth; |
| 840 | vfbd->base.base.width = mode_cmd->width; |
| 841 | vfbd->base.base.height = mode_cmd->height; |
Jakob Bornecrantz | 2fcd5a7 | 2011-10-04 20:13:26 +0200 | [diff] [blame] | 842 | vfbd->base.dmabuf = true; |
Sinclair Yeh | 05c9501 | 2015-08-11 22:53:39 -0700 | [diff] [blame] | 843 | vfbd->buffer = vmw_dmabuf_reference(dmabuf); |
Thomas Hellstrom | 90ff18b | 2011-10-04 20:13:32 +0200 | [diff] [blame] | 844 | vfbd->base.user_handle = mode_cmd->handle; |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 845 | *out = &vfbd->base; |
| 846 | |
Daniel Vetter | 80f0b5a | 2012-12-13 23:39:01 +0100 | [diff] [blame] | 847 | ret = drm_framebuffer_init(dev, &vfbd->base.base, |
| 848 | &vmw_framebuffer_dmabuf_funcs); |
| 849 | if (ret) |
Sinclair Yeh | 05c9501 | 2015-08-11 22:53:39 -0700 | [diff] [blame] | 850 | goto out_err2; |
Daniel Vetter | 80f0b5a | 2012-12-13 23:39:01 +0100 | [diff] [blame] | 851 | |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 852 | return 0; |
| 853 | |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 854 | out_err2: |
Sinclair Yeh | 05c9501 | 2015-08-11 22:53:39 -0700 | [diff] [blame] | 855 | vmw_dmabuf_unreference(&dmabuf); |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 856 | kfree(vfbd); |
| 857 | out_err1: |
| 858 | return ret; |
| 859 | } |
| 860 | |
Thomas Hellstrom | fd006a4 | 2015-06-28 02:50:56 -0700 | [diff] [blame] | 861 | /** |
| 862 | * vmw_kms_new_framebuffer - Create a new framebuffer. |
| 863 | * |
| 864 | * @dev_priv: Pointer to device private struct. |
| 865 | * @dmabuf: Pointer to dma buffer to wrap the kms framebuffer around. |
| 866 | * Either @dmabuf or @surface must be NULL. |
| 867 | * @surface: Pointer to a surface to wrap the kms framebuffer around. |
| 868 | * Either @dmabuf or @surface must be NULL. |
| 869 | * @only_2d: No presents will occur to this dma buffer based framebuffer. This |
| 870 | * Helps the code to do some important optimizations. |
| 871 | * @mode_cmd: Frame-buffer metadata. |
| 872 | */ |
| 873 | struct vmw_framebuffer * |
| 874 | vmw_kms_new_framebuffer(struct vmw_private *dev_priv, |
| 875 | struct vmw_dma_buffer *dmabuf, |
| 876 | struct vmw_surface *surface, |
| 877 | bool only_2d, |
| 878 | const struct drm_mode_fb_cmd *mode_cmd) |
| 879 | { |
Sinclair Yeh | 05c9501 | 2015-08-11 22:53:39 -0700 | [diff] [blame] | 880 | struct vmw_framebuffer *vfb = NULL; |
Thomas Hellstrom | fd006a4 | 2015-06-28 02:50:56 -0700 | [diff] [blame] | 881 | bool is_dmabuf_proxy = false; |
| 882 | int ret; |
| 883 | |
| 884 | /* |
| 885 | * We cannot use the SurfaceDMA command in an non-accelerated VM, |
| 886 | * therefore, wrap the DMA buf in a surface so we can use the |
| 887 | * SurfaceCopy command. |
| 888 | */ |
| 889 | if (dmabuf && only_2d && |
| 890 | dev_priv->active_display_unit == vmw_du_screen_target) { |
| 891 | ret = vmw_create_dmabuf_proxy(dev_priv->dev, mode_cmd, |
| 892 | dmabuf, &surface); |
| 893 | if (ret) |
| 894 | return ERR_PTR(ret); |
| 895 | |
| 896 | is_dmabuf_proxy = true; |
| 897 | } |
| 898 | |
| 899 | /* Create the new framebuffer depending one what we have */ |
Sinclair Yeh | 05c9501 | 2015-08-11 22:53:39 -0700 | [diff] [blame] | 900 | if (surface) { |
Thomas Hellstrom | fd006a4 | 2015-06-28 02:50:56 -0700 | [diff] [blame] | 901 | ret = vmw_kms_new_framebuffer_surface(dev_priv, surface, &vfb, |
| 902 | mode_cmd, |
| 903 | is_dmabuf_proxy); |
Sinclair Yeh | 05c9501 | 2015-08-11 22:53:39 -0700 | [diff] [blame] | 904 | |
| 905 | /* |
| 906 | * vmw_create_dmabuf_proxy() adds a reference that is no longer |
| 907 | * needed |
| 908 | */ |
| 909 | if (is_dmabuf_proxy) |
| 910 | vmw_surface_unreference(&surface); |
| 911 | } else if (dmabuf) { |
Thomas Hellstrom | fd006a4 | 2015-06-28 02:50:56 -0700 | [diff] [blame] | 912 | ret = vmw_kms_new_framebuffer_dmabuf(dev_priv, dmabuf, &vfb, |
| 913 | mode_cmd); |
Sinclair Yeh | 05c9501 | 2015-08-11 22:53:39 -0700 | [diff] [blame] | 914 | } else { |
Thomas Hellstrom | fd006a4 | 2015-06-28 02:50:56 -0700 | [diff] [blame] | 915 | BUG(); |
Sinclair Yeh | 05c9501 | 2015-08-11 22:53:39 -0700 | [diff] [blame] | 916 | } |
Thomas Hellstrom | fd006a4 | 2015-06-28 02:50:56 -0700 | [diff] [blame] | 917 | |
| 918 | if (ret) |
| 919 | return ERR_PTR(ret); |
| 920 | |
| 921 | vfb->pin = vmw_framebuffer_pin; |
| 922 | vfb->unpin = vmw_framebuffer_unpin; |
| 923 | |
| 924 | return vfb; |
| 925 | } |
| 926 | |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 927 | /* |
| 928 | * Generic Kernel modesetting functions |
| 929 | */ |
| 930 | |
| 931 | static struct drm_framebuffer *vmw_kms_fb_create(struct drm_device *dev, |
| 932 | struct drm_file *file_priv, |
Ville Syrjälä | 1eb8345 | 2015-11-11 19:11:29 +0200 | [diff] [blame] | 933 | const struct drm_mode_fb_cmd2 *mode_cmd2) |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 934 | { |
| 935 | struct vmw_private *dev_priv = vmw_priv(dev); |
| 936 | struct ttm_object_file *tfile = vmw_fpriv(file_priv)->tfile; |
| 937 | struct vmw_framebuffer *vfb = NULL; |
| 938 | struct vmw_surface *surface = NULL; |
| 939 | struct vmw_dma_buffer *bo = NULL; |
Thomas Hellstrom | 90ff18b | 2011-10-04 20:13:32 +0200 | [diff] [blame] | 940 | struct ttm_base_object *user_obj; |
Jesse Barnes | 308e5bc | 2011-11-14 14:51:28 -0800 | [diff] [blame] | 941 | struct drm_mode_fb_cmd mode_cmd; |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 942 | int ret; |
| 943 | |
Jesse Barnes | 308e5bc | 2011-11-14 14:51:28 -0800 | [diff] [blame] | 944 | mode_cmd.width = mode_cmd2->width; |
| 945 | mode_cmd.height = mode_cmd2->height; |
| 946 | mode_cmd.pitch = mode_cmd2->pitches[0]; |
| 947 | mode_cmd.handle = mode_cmd2->handles[0]; |
Dave Airlie | 248dbc2 | 2011-11-29 20:02:54 +0000 | [diff] [blame] | 948 | drm_fb_get_bpp_depth(mode_cmd2->pixel_format, &mode_cmd.depth, |
Jesse Barnes | 308e5bc | 2011-11-14 14:51:28 -0800 | [diff] [blame] | 949 | &mode_cmd.bpp); |
| 950 | |
Thomas Hellstrom | d3216a0 | 2010-10-05 12:42:59 +0200 | [diff] [blame] | 951 | /** |
| 952 | * This code should be conditioned on Screen Objects not being used. |
| 953 | * If screen objects are used, we can allocate a GMR to hold the |
| 954 | * requested framebuffer. |
| 955 | */ |
| 956 | |
Xi Wang | 8a78389 | 2011-12-21 05:18:33 -0500 | [diff] [blame] | 957 | if (!vmw_kms_validate_mode_vram(dev_priv, |
Linus Torvalds | 1a464cb | 2012-01-10 11:04:36 -0800 | [diff] [blame] | 958 | mode_cmd.pitch, |
| 959 | mode_cmd.height)) { |
Sinclair Yeh | c8261a9 | 2015-06-26 01:23:42 -0700 | [diff] [blame] | 960 | DRM_ERROR("Requested mode exceed bounding box limit.\n"); |
Jakob Bornecrantz | d982640 | 2011-11-03 21:03:04 +0100 | [diff] [blame] | 961 | return ERR_PTR(-ENOMEM); |
Thomas Hellstrom | d3216a0 | 2010-10-05 12:42:59 +0200 | [diff] [blame] | 962 | } |
| 963 | |
Thomas Hellstrom | 90ff18b | 2011-10-04 20:13:32 +0200 | [diff] [blame] | 964 | /* |
| 965 | * Take a reference on the user object of the resource |
| 966 | * backing the kms fb. This ensures that user-space handle |
| 967 | * lookups on that resource will always work as long as |
| 968 | * it's registered with a kms framebuffer. This is important, |
| 969 | * since vmw_execbuf_process identifies resources in the |
| 970 | * command stream using user-space handles. |
| 971 | */ |
| 972 | |
Jesse Barnes | 308e5bc | 2011-11-14 14:51:28 -0800 | [diff] [blame] | 973 | user_obj = ttm_base_object_lookup(tfile, mode_cmd.handle); |
Thomas Hellstrom | 90ff18b | 2011-10-04 20:13:32 +0200 | [diff] [blame] | 974 | if (unlikely(user_obj == NULL)) { |
| 975 | DRM_ERROR("Could not locate requested kms frame buffer.\n"); |
| 976 | return ERR_PTR(-ENOENT); |
| 977 | } |
| 978 | |
Thomas Hellstrom | d3216a0 | 2010-10-05 12:42:59 +0200 | [diff] [blame] | 979 | /** |
| 980 | * End conditioned code. |
| 981 | */ |
| 982 | |
Jakob Bornecrantz | e7ac921 | 2011-11-28 13:19:12 +0100 | [diff] [blame] | 983 | /* returns either a dmabuf or surface */ |
| 984 | ret = vmw_user_lookup_handle(dev_priv, tfile, |
Dave Airlie | 4cf7312 | 2011-12-21 09:50:56 +0000 | [diff] [blame] | 985 | mode_cmd.handle, |
Jakob Bornecrantz | e7ac921 | 2011-11-28 13:19:12 +0100 | [diff] [blame] | 986 | &surface, &bo); |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 987 | if (ret) |
Jakob Bornecrantz | e7ac921 | 2011-11-28 13:19:12 +0100 | [diff] [blame] | 988 | goto err_out; |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 989 | |
Thomas Hellstrom | fd006a4 | 2015-06-28 02:50:56 -0700 | [diff] [blame] | 990 | vfb = vmw_kms_new_framebuffer(dev_priv, bo, surface, |
| 991 | !(dev_priv->capabilities & SVGA_CAP_3D), |
| 992 | &mode_cmd); |
| 993 | if (IS_ERR(vfb)) { |
| 994 | ret = PTR_ERR(vfb); |
| 995 | goto err_out; |
| 996 | } |
Jakob Bornecrantz | 5ffdb65 | 2010-01-30 03:38:08 +0000 | [diff] [blame] | 997 | |
Jakob Bornecrantz | e7ac921 | 2011-11-28 13:19:12 +0100 | [diff] [blame] | 998 | err_out: |
| 999 | /* vmw_user_lookup_handle takes one ref so does new_fb */ |
| 1000 | if (bo) |
| 1001 | vmw_dmabuf_unreference(&bo); |
| 1002 | if (surface) |
| 1003 | vmw_surface_unreference(&surface); |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 1004 | |
| 1005 | if (ret) { |
| 1006 | DRM_ERROR("failed to create vmw_framebuffer: %i\n", ret); |
Thomas Hellstrom | 90ff18b | 2011-10-04 20:13:32 +0200 | [diff] [blame] | 1007 | ttm_base_object_unref(&user_obj); |
Chris Wilson | cce13ff | 2010-08-08 13:36:38 +0100 | [diff] [blame] | 1008 | return ERR_PTR(ret); |
Thomas Hellstrom | 90ff18b | 2011-10-04 20:13:32 +0200 | [diff] [blame] | 1009 | } else |
| 1010 | vfb->user_obj = user_obj; |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 1011 | |
| 1012 | return &vfb->base; |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 1013 | } |
| 1014 | |
Laurent Pinchart | e6ecefa | 2012-05-17 13:27:23 +0200 | [diff] [blame] | 1015 | static const struct drm_mode_config_funcs vmw_kms_funcs = { |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 1016 | .fb_create = vmw_kms_fb_create, |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 1017 | }; |
| 1018 | |
Thomas Hellstrom | b9eb1a6 | 2015-04-02 02:39:45 -0700 | [diff] [blame] | 1019 | static int vmw_kms_generic_present(struct vmw_private *dev_priv, |
| 1020 | struct drm_file *file_priv, |
| 1021 | struct vmw_framebuffer *vfb, |
| 1022 | struct vmw_surface *surface, |
| 1023 | uint32_t sid, |
| 1024 | int32_t destX, int32_t destY, |
| 1025 | struct drm_vmw_rect *clips, |
| 1026 | uint32_t num_clips) |
Jakob Bornecrantz | 2fcd5a7 | 2011-10-04 20:13:26 +0200 | [diff] [blame] | 1027 | { |
Thomas Hellstrom | 10b1e0c | 2015-06-26 02:14:27 -0700 | [diff] [blame] | 1028 | return vmw_kms_sou_do_surface_dirty(dev_priv, vfb, NULL, clips, |
| 1029 | &surface->res, destX, destY, |
| 1030 | num_clips, 1, NULL); |
Jakob Bornecrantz | 2fcd5a7 | 2011-10-04 20:13:26 +0200 | [diff] [blame] | 1031 | } |
| 1032 | |
Thomas Hellstrom | 6bf6bf0 | 2015-06-26 02:22:40 -0700 | [diff] [blame] | 1033 | |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 1034 | int vmw_kms_present(struct vmw_private *dev_priv, |
| 1035 | struct drm_file *file_priv, |
| 1036 | struct vmw_framebuffer *vfb, |
| 1037 | struct vmw_surface *surface, |
| 1038 | uint32_t sid, |
| 1039 | int32_t destX, int32_t destY, |
| 1040 | struct drm_vmw_rect *clips, |
| 1041 | uint32_t num_clips) |
| 1042 | { |
Sinclair Yeh | 35c0512 | 2015-06-26 01:42:06 -0700 | [diff] [blame] | 1043 | int ret; |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 1044 | |
Thomas Hellstrom | 6bf6bf0 | 2015-06-26 02:22:40 -0700 | [diff] [blame] | 1045 | switch (dev_priv->active_display_unit) { |
| 1046 | case vmw_du_screen_target: |
| 1047 | ret = vmw_kms_stdu_surface_dirty(dev_priv, vfb, NULL, clips, |
| 1048 | &surface->res, destX, destY, |
| 1049 | num_clips, 1, NULL); |
| 1050 | break; |
| 1051 | case vmw_du_screen_object: |
| 1052 | ret = vmw_kms_generic_present(dev_priv, file_priv, vfb, surface, |
| 1053 | sid, destX, destY, clips, |
| 1054 | num_clips); |
| 1055 | break; |
| 1056 | default: |
| 1057 | WARN_ONCE(true, |
| 1058 | "Present called with invalid display system.\n"); |
| 1059 | ret = -ENOSYS; |
| 1060 | break; |
Jakob Bornecrantz | d7e1958 | 2010-05-28 11:21:59 +0200 | [diff] [blame] | 1061 | } |
Sinclair Yeh | 35c0512 | 2015-06-26 01:42:06 -0700 | [diff] [blame] | 1062 | if (ret) |
| 1063 | return ret; |
Jakob Bornecrantz | d7e1958 | 2010-05-28 11:21:59 +0200 | [diff] [blame] | 1064 | |
Sinclair Yeh | 35c0512 | 2015-06-26 01:42:06 -0700 | [diff] [blame] | 1065 | vmw_fifo_flush(dev_priv, false); |
Michel Dänzer | 0bef23f | 2011-08-31 07:42:50 +0000 | [diff] [blame] | 1066 | |
Sinclair Yeh | 35c0512 | 2015-06-26 01:42:06 -0700 | [diff] [blame] | 1067 | return 0; |
Thomas Hellstrom | 7c4f778 | 2010-06-01 11:38:17 +0200 | [diff] [blame] | 1068 | } |
| 1069 | |
| 1070 | int vmw_kms_init(struct vmw_private *dev_priv) |
| 1071 | { |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 1072 | struct drm_device *dev = dev_priv->dev; |
| 1073 | int ret; |
Jakob Bornecrantz | d8bd19d | 2010-06-01 11:54:20 +0200 | [diff] [blame] | 1074 | |
Thomas Hellstrom | e133e73 | 2010-10-05 12:43:04 +0200 | [diff] [blame] | 1075 | drm_mode_config_init(dev); |
| 1076 | dev->mode_config.funcs = &vmw_kms_funcs; |
| 1077 | dev->mode_config.min_width = 1; |
| 1078 | dev->mode_config.min_height = 1; |
Sinclair Yeh | 65ade7d | 2015-07-16 10:49:13 -0700 | [diff] [blame] | 1079 | dev->mode_config.max_width = dev_priv->texture_max_width; |
| 1080 | dev->mode_config.max_height = dev_priv->texture_max_height; |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 1081 | |
Sinclair Yeh | 35c0512 | 2015-06-26 01:42:06 -0700 | [diff] [blame] | 1082 | ret = vmw_kms_stdu_init_display(dev_priv); |
| 1083 | if (ret) { |
| 1084 | ret = vmw_kms_sou_init_display(dev_priv); |
| 1085 | if (ret) /* Fallback */ |
| 1086 | ret = vmw_kms_ldu_init_display(dev_priv); |
| 1087 | } |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 1088 | |
Sinclair Yeh | c8261a9 | 2015-06-26 01:23:42 -0700 | [diff] [blame] | 1089 | return ret; |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 1090 | } |
| 1091 | |
| 1092 | int vmw_kms_close(struct vmw_private *dev_priv) |
| 1093 | { |
Sinclair Yeh | c8261a9 | 2015-06-26 01:23:42 -0700 | [diff] [blame] | 1094 | int ret; |
| 1095 | |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 1096 | /* |
| 1097 | * Docs says we should take the lock before calling this function |
| 1098 | * but since it destroys encoders and our destructor calls |
| 1099 | * drm_encoder_cleanup which takes the lock we deadlock. |
| 1100 | */ |
| 1101 | drm_mode_config_cleanup(dev_priv->dev); |
Sinclair Yeh | c8261a9 | 2015-06-26 01:23:42 -0700 | [diff] [blame] | 1102 | if (dev_priv->active_display_unit == vmw_du_screen_object) |
| 1103 | ret = vmw_kms_sou_close_display(dev_priv); |
Sinclair Yeh | 35c0512 | 2015-06-26 01:42:06 -0700 | [diff] [blame] | 1104 | else if (dev_priv->active_display_unit == vmw_du_screen_target) |
| 1105 | ret = vmw_kms_stdu_close_display(dev_priv); |
Jakob Bornecrantz | c0d1831 | 2011-11-09 10:25:26 +0100 | [diff] [blame] | 1106 | else |
Sinclair Yeh | c8261a9 | 2015-06-26 01:23:42 -0700 | [diff] [blame] | 1107 | ret = vmw_kms_ldu_close_display(dev_priv); |
| 1108 | |
| 1109 | return ret; |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 1110 | } |
| 1111 | |
| 1112 | int vmw_kms_cursor_bypass_ioctl(struct drm_device *dev, void *data, |
| 1113 | struct drm_file *file_priv) |
| 1114 | { |
| 1115 | struct drm_vmw_cursor_bypass_arg *arg = data; |
| 1116 | struct vmw_display_unit *du; |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 1117 | struct drm_crtc *crtc; |
| 1118 | int ret = 0; |
| 1119 | |
| 1120 | |
| 1121 | mutex_lock(&dev->mode_config.mutex); |
| 1122 | if (arg->flags & DRM_VMW_CURSOR_BYPASS_ALL) { |
| 1123 | |
| 1124 | list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) { |
| 1125 | du = vmw_crtc_to_du(crtc); |
| 1126 | du->hotspot_x = arg->xhot; |
| 1127 | du->hotspot_y = arg->yhot; |
| 1128 | } |
| 1129 | |
| 1130 | mutex_unlock(&dev->mode_config.mutex); |
| 1131 | return 0; |
| 1132 | } |
| 1133 | |
Rob Clark | a4cd5d6 | 2014-07-17 23:30:02 -0400 | [diff] [blame] | 1134 | crtc = drm_crtc_find(dev, arg->crtc_id); |
| 1135 | if (!crtc) { |
Ville Syrjälä | 4ae87ff | 2013-10-17 13:35:05 +0300 | [diff] [blame] | 1136 | ret = -ENOENT; |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 1137 | goto out; |
| 1138 | } |
| 1139 | |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 1140 | du = vmw_crtc_to_du(crtc); |
| 1141 | |
| 1142 | du->hotspot_x = arg->xhot; |
| 1143 | du->hotspot_y = arg->yhot; |
| 1144 | |
| 1145 | out: |
| 1146 | mutex_unlock(&dev->mode_config.mutex); |
| 1147 | |
| 1148 | return ret; |
| 1149 | } |
| 1150 | |
| 1151 | int vmw_kms_write_svga(struct vmw_private *vmw_priv, |
| 1152 | unsigned width, unsigned height, unsigned pitch, |
| 1153 | unsigned bpp, unsigned depth) |
| 1154 | { |
| 1155 | if (vmw_priv->capabilities & SVGA_CAP_PITCHLOCK) |
| 1156 | vmw_write(vmw_priv, SVGA_REG_PITCHLOCK, pitch); |
| 1157 | else if (vmw_fifo_have_pitchlock(vmw_priv)) |
Thomas Hellstrom | b76ff5e | 2015-10-28 10:44:04 +0100 | [diff] [blame] | 1158 | vmw_mmio_write(pitch, vmw_priv->mmio_virt + |
| 1159 | SVGA_FIFO_PITCHLOCK); |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 1160 | vmw_write(vmw_priv, SVGA_REG_WIDTH, width); |
| 1161 | vmw_write(vmw_priv, SVGA_REG_HEIGHT, height); |
| 1162 | vmw_write(vmw_priv, SVGA_REG_BITS_PER_PIXEL, bpp); |
| 1163 | |
| 1164 | if (vmw_read(vmw_priv, SVGA_REG_DEPTH) != depth) { |
| 1165 | DRM_ERROR("Invalid depth %u for %u bpp, host expects %u\n", |
| 1166 | depth, bpp, vmw_read(vmw_priv, SVGA_REG_DEPTH)); |
| 1167 | return -EINVAL; |
| 1168 | } |
| 1169 | |
| 1170 | return 0; |
| 1171 | } |
| 1172 | |
| 1173 | int vmw_kms_save_vga(struct vmw_private *vmw_priv) |
| 1174 | { |
| 1175 | struct vmw_vga_topology_state *save; |
| 1176 | uint32_t i; |
| 1177 | |
| 1178 | vmw_priv->vga_width = vmw_read(vmw_priv, SVGA_REG_WIDTH); |
| 1179 | vmw_priv->vga_height = vmw_read(vmw_priv, SVGA_REG_HEIGHT); |
| 1180 | vmw_priv->vga_bpp = vmw_read(vmw_priv, SVGA_REG_BITS_PER_PIXEL); |
| 1181 | if (vmw_priv->capabilities & SVGA_CAP_PITCHLOCK) |
| 1182 | vmw_priv->vga_pitchlock = |
| 1183 | vmw_read(vmw_priv, SVGA_REG_PITCHLOCK); |
| 1184 | else if (vmw_fifo_have_pitchlock(vmw_priv)) |
Thomas Hellstrom | b76ff5e | 2015-10-28 10:44:04 +0100 | [diff] [blame] | 1185 | vmw_priv->vga_pitchlock = vmw_mmio_read(vmw_priv->mmio_virt + |
| 1186 | SVGA_FIFO_PITCHLOCK); |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 1187 | |
| 1188 | if (!(vmw_priv->capabilities & SVGA_CAP_DISPLAY_TOPOLOGY)) |
| 1189 | return 0; |
| 1190 | |
| 1191 | vmw_priv->num_displays = vmw_read(vmw_priv, |
| 1192 | SVGA_REG_NUM_GUEST_DISPLAYS); |
| 1193 | |
| 1194 | if (vmw_priv->num_displays == 0) |
| 1195 | vmw_priv->num_displays = 1; |
| 1196 | |
| 1197 | for (i = 0; i < vmw_priv->num_displays; ++i) { |
| 1198 | save = &vmw_priv->vga_save[i]; |
| 1199 | vmw_write(vmw_priv, SVGA_REG_DISPLAY_ID, i); |
| 1200 | save->primary = vmw_read(vmw_priv, SVGA_REG_DISPLAY_IS_PRIMARY); |
| 1201 | save->pos_x = vmw_read(vmw_priv, SVGA_REG_DISPLAY_POSITION_X); |
| 1202 | save->pos_y = vmw_read(vmw_priv, SVGA_REG_DISPLAY_POSITION_Y); |
| 1203 | save->width = vmw_read(vmw_priv, SVGA_REG_DISPLAY_WIDTH); |
| 1204 | save->height = vmw_read(vmw_priv, SVGA_REG_DISPLAY_HEIGHT); |
| 1205 | vmw_write(vmw_priv, SVGA_REG_DISPLAY_ID, SVGA_ID_INVALID); |
| 1206 | if (i == 0 && vmw_priv->num_displays == 1 && |
| 1207 | save->width == 0 && save->height == 0) { |
| 1208 | |
| 1209 | /* |
| 1210 | * It should be fairly safe to assume that these |
| 1211 | * values are uninitialized. |
| 1212 | */ |
| 1213 | |
| 1214 | save->width = vmw_priv->vga_width - save->pos_x; |
| 1215 | save->height = vmw_priv->vga_height - save->pos_y; |
| 1216 | } |
| 1217 | } |
| 1218 | |
| 1219 | return 0; |
| 1220 | } |
| 1221 | |
| 1222 | int vmw_kms_restore_vga(struct vmw_private *vmw_priv) |
| 1223 | { |
| 1224 | struct vmw_vga_topology_state *save; |
| 1225 | uint32_t i; |
| 1226 | |
| 1227 | vmw_write(vmw_priv, SVGA_REG_WIDTH, vmw_priv->vga_width); |
| 1228 | vmw_write(vmw_priv, SVGA_REG_HEIGHT, vmw_priv->vga_height); |
| 1229 | vmw_write(vmw_priv, SVGA_REG_BITS_PER_PIXEL, vmw_priv->vga_bpp); |
| 1230 | if (vmw_priv->capabilities & SVGA_CAP_PITCHLOCK) |
| 1231 | vmw_write(vmw_priv, SVGA_REG_PITCHLOCK, |
| 1232 | vmw_priv->vga_pitchlock); |
| 1233 | else if (vmw_fifo_have_pitchlock(vmw_priv)) |
Thomas Hellstrom | b76ff5e | 2015-10-28 10:44:04 +0100 | [diff] [blame] | 1234 | vmw_mmio_write(vmw_priv->vga_pitchlock, |
| 1235 | vmw_priv->mmio_virt + SVGA_FIFO_PITCHLOCK); |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 1236 | |
| 1237 | if (!(vmw_priv->capabilities & SVGA_CAP_DISPLAY_TOPOLOGY)) |
| 1238 | return 0; |
| 1239 | |
| 1240 | for (i = 0; i < vmw_priv->num_displays; ++i) { |
| 1241 | save = &vmw_priv->vga_save[i]; |
| 1242 | vmw_write(vmw_priv, SVGA_REG_DISPLAY_ID, i); |
| 1243 | vmw_write(vmw_priv, SVGA_REG_DISPLAY_IS_PRIMARY, save->primary); |
| 1244 | vmw_write(vmw_priv, SVGA_REG_DISPLAY_POSITION_X, save->pos_x); |
| 1245 | vmw_write(vmw_priv, SVGA_REG_DISPLAY_POSITION_Y, save->pos_y); |
| 1246 | vmw_write(vmw_priv, SVGA_REG_DISPLAY_WIDTH, save->width); |
| 1247 | vmw_write(vmw_priv, SVGA_REG_DISPLAY_HEIGHT, save->height); |
| 1248 | vmw_write(vmw_priv, SVGA_REG_DISPLAY_ID, SVGA_ID_INVALID); |
| 1249 | } |
| 1250 | |
| 1251 | return 0; |
| 1252 | } |
Jakob Bornecrantz | d8bd19d | 2010-06-01 11:54:20 +0200 | [diff] [blame] | 1253 | |
| 1254 | bool vmw_kms_validate_mode_vram(struct vmw_private *dev_priv, |
| 1255 | uint32_t pitch, |
| 1256 | uint32_t height) |
| 1257 | { |
Sinclair Yeh | 35c0512 | 2015-06-26 01:42:06 -0700 | [diff] [blame] | 1258 | return ((u64) pitch * (u64) height) < (u64) |
| 1259 | ((dev_priv->active_display_unit == vmw_du_screen_target) ? |
| 1260 | dev_priv->prim_bb_mem : dev_priv->vram_size); |
Thomas Hellstrom | e133e73 | 2010-10-05 12:43:04 +0200 | [diff] [blame] | 1261 | } |
| 1262 | |
Jakob Bornecrantz | 1c482ab | 2011-10-17 11:59:45 +0200 | [diff] [blame] | 1263 | |
| 1264 | /** |
| 1265 | * Function called by DRM code called with vbl_lock held. |
| 1266 | */ |
Thierry Reding | 88e7271 | 2015-09-24 18:35:31 +0200 | [diff] [blame] | 1267 | u32 vmw_get_vblank_counter(struct drm_device *dev, unsigned int pipe) |
Thomas Hellstrom | 7a1c2f6 | 2010-10-01 10:21:49 +0200 | [diff] [blame] | 1268 | { |
| 1269 | return 0; |
| 1270 | } |
Jakob Bornecrantz | 626ab77 | 2011-10-04 20:13:20 +0200 | [diff] [blame] | 1271 | |
Jakob Bornecrantz | 1c482ab | 2011-10-17 11:59:45 +0200 | [diff] [blame] | 1272 | /** |
| 1273 | * Function called by DRM code called with vbl_lock held. |
| 1274 | */ |
Thierry Reding | 88e7271 | 2015-09-24 18:35:31 +0200 | [diff] [blame] | 1275 | int vmw_enable_vblank(struct drm_device *dev, unsigned int pipe) |
Jakob Bornecrantz | 1c482ab | 2011-10-17 11:59:45 +0200 | [diff] [blame] | 1276 | { |
| 1277 | return -ENOSYS; |
| 1278 | } |
| 1279 | |
| 1280 | /** |
| 1281 | * Function called by DRM code called with vbl_lock held. |
| 1282 | */ |
Thierry Reding | 88e7271 | 2015-09-24 18:35:31 +0200 | [diff] [blame] | 1283 | void vmw_disable_vblank(struct drm_device *dev, unsigned int pipe) |
Jakob Bornecrantz | 1c482ab | 2011-10-17 11:59:45 +0200 | [diff] [blame] | 1284 | { |
| 1285 | } |
| 1286 | |
Jakob Bornecrantz | 626ab77 | 2011-10-04 20:13:20 +0200 | [diff] [blame] | 1287 | |
| 1288 | /* |
| 1289 | * Small shared kms functions. |
| 1290 | */ |
| 1291 | |
Rashika Kheria | 847c596 | 2014-01-06 22:18:10 +0530 | [diff] [blame] | 1292 | static int vmw_du_update_layout(struct vmw_private *dev_priv, unsigned num, |
Jakob Bornecrantz | 626ab77 | 2011-10-04 20:13:20 +0200 | [diff] [blame] | 1293 | struct drm_vmw_rect *rects) |
| 1294 | { |
| 1295 | struct drm_device *dev = dev_priv->dev; |
| 1296 | struct vmw_display_unit *du; |
| 1297 | struct drm_connector *con; |
Jakob Bornecrantz | 626ab77 | 2011-10-04 20:13:20 +0200 | [diff] [blame] | 1298 | |
| 1299 | mutex_lock(&dev->mode_config.mutex); |
| 1300 | |
| 1301 | #if 0 |
Thomas Hellstrom | 6ea77d1 | 2011-10-04 20:13:36 +0200 | [diff] [blame] | 1302 | { |
| 1303 | unsigned int i; |
| 1304 | |
| 1305 | DRM_INFO("%s: new layout ", __func__); |
| 1306 | for (i = 0; i < num; i++) |
| 1307 | DRM_INFO("(%i, %i %ux%u) ", rects[i].x, rects[i].y, |
| 1308 | rects[i].w, rects[i].h); |
| 1309 | DRM_INFO("\n"); |
| 1310 | } |
Jakob Bornecrantz | 626ab77 | 2011-10-04 20:13:20 +0200 | [diff] [blame] | 1311 | #endif |
| 1312 | |
| 1313 | list_for_each_entry(con, &dev->mode_config.connector_list, head) { |
| 1314 | du = vmw_connector_to_du(con); |
| 1315 | if (num > du->unit) { |
| 1316 | du->pref_width = rects[du->unit].w; |
| 1317 | du->pref_height = rects[du->unit].h; |
| 1318 | du->pref_active = true; |
Thomas Hellstrom | cd2b89e | 2011-10-25 23:35:53 +0200 | [diff] [blame] | 1319 | du->gui_x = rects[du->unit].x; |
| 1320 | du->gui_y = rects[du->unit].y; |
Jakob Bornecrantz | 626ab77 | 2011-10-04 20:13:20 +0200 | [diff] [blame] | 1321 | } else { |
| 1322 | du->pref_width = 800; |
| 1323 | du->pref_height = 600; |
| 1324 | du->pref_active = false; |
| 1325 | } |
| 1326 | con->status = vmw_du_connector_detect(con, true); |
| 1327 | } |
| 1328 | |
| 1329 | mutex_unlock(&dev->mode_config.mutex); |
| 1330 | |
| 1331 | return 0; |
| 1332 | } |
| 1333 | |
Jakob Bornecrantz | 626ab77 | 2011-10-04 20:13:20 +0200 | [diff] [blame] | 1334 | void vmw_du_crtc_gamma_set(struct drm_crtc *crtc, |
| 1335 | u16 *r, u16 *g, u16 *b, |
| 1336 | uint32_t start, uint32_t size) |
| 1337 | { |
| 1338 | struct vmw_private *dev_priv = vmw_priv(crtc->dev); |
| 1339 | int i; |
| 1340 | |
| 1341 | for (i = 0; i < size; i++) { |
| 1342 | DRM_DEBUG("%d r/g/b = 0x%04x / 0x%04x / 0x%04x\n", i, |
| 1343 | r[i], g[i], b[i]); |
| 1344 | vmw_write(dev_priv, SVGA_PALETTE_BASE + i * 3 + 0, r[i] >> 8); |
| 1345 | vmw_write(dev_priv, SVGA_PALETTE_BASE + i * 3 + 1, g[i] >> 8); |
| 1346 | vmw_write(dev_priv, SVGA_PALETTE_BASE + i * 3 + 2, b[i] >> 8); |
| 1347 | } |
| 1348 | } |
| 1349 | |
Maarten Lankhorst | 9a69a9a | 2015-07-21 11:34:55 +0200 | [diff] [blame] | 1350 | int vmw_du_connector_dpms(struct drm_connector *connector, int mode) |
Jakob Bornecrantz | 626ab77 | 2011-10-04 20:13:20 +0200 | [diff] [blame] | 1351 | { |
Maarten Lankhorst | 9a69a9a | 2015-07-21 11:34:55 +0200 | [diff] [blame] | 1352 | return 0; |
Jakob Bornecrantz | 626ab77 | 2011-10-04 20:13:20 +0200 | [diff] [blame] | 1353 | } |
| 1354 | |
Jakob Bornecrantz | 626ab77 | 2011-10-04 20:13:20 +0200 | [diff] [blame] | 1355 | enum drm_connector_status |
| 1356 | vmw_du_connector_detect(struct drm_connector *connector, bool force) |
| 1357 | { |
| 1358 | uint32_t num_displays; |
| 1359 | struct drm_device *dev = connector->dev; |
| 1360 | struct vmw_private *dev_priv = vmw_priv(dev); |
Thomas Hellstrom | cd2b89e | 2011-10-25 23:35:53 +0200 | [diff] [blame] | 1361 | struct vmw_display_unit *du = vmw_connector_to_du(connector); |
Jakob Bornecrantz | 626ab77 | 2011-10-04 20:13:20 +0200 | [diff] [blame] | 1362 | |
Jakob Bornecrantz | 626ab77 | 2011-10-04 20:13:20 +0200 | [diff] [blame] | 1363 | num_displays = vmw_read(dev_priv, SVGA_REG_NUM_DISPLAYS); |
Jakob Bornecrantz | 626ab77 | 2011-10-04 20:13:20 +0200 | [diff] [blame] | 1364 | |
Thomas Hellstrom | cd2b89e | 2011-10-25 23:35:53 +0200 | [diff] [blame] | 1365 | return ((vmw_connector_to_du(connector)->unit < num_displays && |
| 1366 | du->pref_active) ? |
Jakob Bornecrantz | 626ab77 | 2011-10-04 20:13:20 +0200 | [diff] [blame] | 1367 | connector_status_connected : connector_status_disconnected); |
| 1368 | } |
| 1369 | |
| 1370 | static struct drm_display_mode vmw_kms_connector_builtin[] = { |
| 1371 | /* 640x480@60Hz */ |
| 1372 | { DRM_MODE("640x480", DRM_MODE_TYPE_DRIVER, 25175, 640, 656, |
| 1373 | 752, 800, 0, 480, 489, 492, 525, 0, |
| 1374 | DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) }, |
| 1375 | /* 800x600@60Hz */ |
| 1376 | { DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER, 40000, 800, 840, |
| 1377 | 968, 1056, 0, 600, 601, 605, 628, 0, |
| 1378 | DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, |
| 1379 | /* 1024x768@60Hz */ |
| 1380 | { DRM_MODE("1024x768", DRM_MODE_TYPE_DRIVER, 65000, 1024, 1048, |
| 1381 | 1184, 1344, 0, 768, 771, 777, 806, 0, |
| 1382 | DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) }, |
| 1383 | /* 1152x864@75Hz */ |
| 1384 | { DRM_MODE("1152x864", DRM_MODE_TYPE_DRIVER, 108000, 1152, 1216, |
| 1385 | 1344, 1600, 0, 864, 865, 868, 900, 0, |
| 1386 | DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, |
| 1387 | /* 1280x768@60Hz */ |
| 1388 | { DRM_MODE("1280x768", DRM_MODE_TYPE_DRIVER, 79500, 1280, 1344, |
| 1389 | 1472, 1664, 0, 768, 771, 778, 798, 0, |
| 1390 | DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) }, |
| 1391 | /* 1280x800@60Hz */ |
| 1392 | { DRM_MODE("1280x800", DRM_MODE_TYPE_DRIVER, 83500, 1280, 1352, |
| 1393 | 1480, 1680, 0, 800, 803, 809, 831, 0, |
| 1394 | DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) }, |
| 1395 | /* 1280x960@60Hz */ |
| 1396 | { DRM_MODE("1280x960", DRM_MODE_TYPE_DRIVER, 108000, 1280, 1376, |
| 1397 | 1488, 1800, 0, 960, 961, 964, 1000, 0, |
| 1398 | DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, |
| 1399 | /* 1280x1024@60Hz */ |
| 1400 | { DRM_MODE("1280x1024", DRM_MODE_TYPE_DRIVER, 108000, 1280, 1328, |
| 1401 | 1440, 1688, 0, 1024, 1025, 1028, 1066, 0, |
| 1402 | DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, |
| 1403 | /* 1360x768@60Hz */ |
| 1404 | { DRM_MODE("1360x768", DRM_MODE_TYPE_DRIVER, 85500, 1360, 1424, |
| 1405 | 1536, 1792, 0, 768, 771, 777, 795, 0, |
| 1406 | DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, |
| 1407 | /* 1440x1050@60Hz */ |
| 1408 | { DRM_MODE("1400x1050", DRM_MODE_TYPE_DRIVER, 121750, 1400, 1488, |
| 1409 | 1632, 1864, 0, 1050, 1053, 1057, 1089, 0, |
| 1410 | DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) }, |
| 1411 | /* 1440x900@60Hz */ |
| 1412 | { DRM_MODE("1440x900", DRM_MODE_TYPE_DRIVER, 106500, 1440, 1520, |
| 1413 | 1672, 1904, 0, 900, 903, 909, 934, 0, |
| 1414 | DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) }, |
| 1415 | /* 1600x1200@60Hz */ |
| 1416 | { DRM_MODE("1600x1200", DRM_MODE_TYPE_DRIVER, 162000, 1600, 1664, |
| 1417 | 1856, 2160, 0, 1200, 1201, 1204, 1250, 0, |
| 1418 | DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, |
| 1419 | /* 1680x1050@60Hz */ |
| 1420 | { DRM_MODE("1680x1050", DRM_MODE_TYPE_DRIVER, 146250, 1680, 1784, |
| 1421 | 1960, 2240, 0, 1050, 1053, 1059, 1089, 0, |
| 1422 | DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) }, |
| 1423 | /* 1792x1344@60Hz */ |
| 1424 | { DRM_MODE("1792x1344", DRM_MODE_TYPE_DRIVER, 204750, 1792, 1920, |
| 1425 | 2120, 2448, 0, 1344, 1345, 1348, 1394, 0, |
| 1426 | DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) }, |
| 1427 | /* 1853x1392@60Hz */ |
| 1428 | { DRM_MODE("1856x1392", DRM_MODE_TYPE_DRIVER, 218250, 1856, 1952, |
| 1429 | 2176, 2528, 0, 1392, 1393, 1396, 1439, 0, |
| 1430 | DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) }, |
| 1431 | /* 1920x1200@60Hz */ |
| 1432 | { DRM_MODE("1920x1200", DRM_MODE_TYPE_DRIVER, 193250, 1920, 2056, |
| 1433 | 2256, 2592, 0, 1200, 1203, 1209, 1245, 0, |
| 1434 | DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) }, |
| 1435 | /* 1920x1440@60Hz */ |
| 1436 | { DRM_MODE("1920x1440", DRM_MODE_TYPE_DRIVER, 234000, 1920, 2048, |
| 1437 | 2256, 2600, 0, 1440, 1441, 1444, 1500, 0, |
| 1438 | DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) }, |
| 1439 | /* 2560x1600@60Hz */ |
| 1440 | { DRM_MODE("2560x1600", DRM_MODE_TYPE_DRIVER, 348500, 2560, 2752, |
| 1441 | 3032, 3504, 0, 1600, 1603, 1609, 1658, 0, |
| 1442 | DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) }, |
| 1443 | /* Terminate */ |
| 1444 | { DRM_MODE("", 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0) }, |
| 1445 | }; |
| 1446 | |
Thomas Hellstrom | 1543b4d | 2011-11-02 09:43:10 +0100 | [diff] [blame] | 1447 | /** |
| 1448 | * vmw_guess_mode_timing - Provide fake timings for a |
| 1449 | * 60Hz vrefresh mode. |
| 1450 | * |
| 1451 | * @mode - Pointer to a struct drm_display_mode with hdisplay and vdisplay |
| 1452 | * members filled in. |
| 1453 | */ |
Thomas Hellstrom | a278724 | 2015-06-29 12:55:07 -0700 | [diff] [blame] | 1454 | void vmw_guess_mode_timing(struct drm_display_mode *mode) |
Thomas Hellstrom | 1543b4d | 2011-11-02 09:43:10 +0100 | [diff] [blame] | 1455 | { |
| 1456 | mode->hsync_start = mode->hdisplay + 50; |
| 1457 | mode->hsync_end = mode->hsync_start + 50; |
| 1458 | mode->htotal = mode->hsync_end + 50; |
| 1459 | |
| 1460 | mode->vsync_start = mode->vdisplay + 50; |
| 1461 | mode->vsync_end = mode->vsync_start + 50; |
| 1462 | mode->vtotal = mode->vsync_end + 50; |
| 1463 | |
| 1464 | mode->clock = (u32)mode->htotal * (u32)mode->vtotal / 100 * 6; |
| 1465 | mode->vrefresh = drm_mode_vrefresh(mode); |
| 1466 | } |
| 1467 | |
| 1468 | |
Jakob Bornecrantz | 626ab77 | 2011-10-04 20:13:20 +0200 | [diff] [blame] | 1469 | int vmw_du_connector_fill_modes(struct drm_connector *connector, |
| 1470 | uint32_t max_width, uint32_t max_height) |
| 1471 | { |
| 1472 | struct vmw_display_unit *du = vmw_connector_to_du(connector); |
| 1473 | struct drm_device *dev = connector->dev; |
| 1474 | struct vmw_private *dev_priv = vmw_priv(dev); |
| 1475 | struct drm_display_mode *mode = NULL; |
| 1476 | struct drm_display_mode *bmode; |
| 1477 | struct drm_display_mode prefmode = { DRM_MODE("preferred", |
| 1478 | DRM_MODE_TYPE_DRIVER | DRM_MODE_TYPE_PREFERRED, |
| 1479 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 1480 | DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) |
| 1481 | }; |
| 1482 | int i; |
Sinclair Yeh | 9a72384 | 2014-10-31 09:58:06 +0100 | [diff] [blame] | 1483 | u32 assumed_bpp = 2; |
| 1484 | |
| 1485 | /* |
| 1486 | * If using screen objects, then assume 32-bpp because that's what the |
| 1487 | * SVGA device is assuming |
| 1488 | */ |
Sinclair Yeh | c8261a9 | 2015-06-26 01:23:42 -0700 | [diff] [blame] | 1489 | if (dev_priv->active_display_unit == vmw_du_screen_object) |
Sinclair Yeh | 9a72384 | 2014-10-31 09:58:06 +0100 | [diff] [blame] | 1490 | assumed_bpp = 4; |
Jakob Bornecrantz | 626ab77 | 2011-10-04 20:13:20 +0200 | [diff] [blame] | 1491 | |
Sinclair Yeh | 35c0512 | 2015-06-26 01:42:06 -0700 | [diff] [blame] | 1492 | if (dev_priv->active_display_unit == vmw_du_screen_target) { |
| 1493 | max_width = min(max_width, dev_priv->stdu_max_width); |
| 1494 | max_height = min(max_height, dev_priv->stdu_max_height); |
Jakob Bornecrantz | 626ab77 | 2011-10-04 20:13:20 +0200 | [diff] [blame] | 1495 | } |
| 1496 | |
| 1497 | /* Add preferred mode */ |
Sinclair Yeh | c8261a9 | 2015-06-26 01:23:42 -0700 | [diff] [blame] | 1498 | mode = drm_mode_duplicate(dev, &prefmode); |
| 1499 | if (!mode) |
| 1500 | return 0; |
| 1501 | mode->hdisplay = du->pref_width; |
| 1502 | mode->vdisplay = du->pref_height; |
| 1503 | vmw_guess_mode_timing(mode); |
Jakob Bornecrantz | 626ab77 | 2011-10-04 20:13:20 +0200 | [diff] [blame] | 1504 | |
Sinclair Yeh | c8261a9 | 2015-06-26 01:23:42 -0700 | [diff] [blame] | 1505 | if (vmw_kms_validate_mode_vram(dev_priv, |
| 1506 | mode->hdisplay * assumed_bpp, |
| 1507 | mode->vdisplay)) { |
| 1508 | drm_mode_probed_add(connector, mode); |
| 1509 | } else { |
| 1510 | drm_mode_destroy(dev, mode); |
| 1511 | mode = NULL; |
Jakob Bornecrantz | 626ab77 | 2011-10-04 20:13:20 +0200 | [diff] [blame] | 1512 | } |
| 1513 | |
Sinclair Yeh | c8261a9 | 2015-06-26 01:23:42 -0700 | [diff] [blame] | 1514 | if (du->pref_mode) { |
| 1515 | list_del_init(&du->pref_mode->head); |
| 1516 | drm_mode_destroy(dev, du->pref_mode); |
| 1517 | } |
| 1518 | |
| 1519 | /* mode might be null here, this is intended */ |
| 1520 | du->pref_mode = mode; |
| 1521 | |
Jakob Bornecrantz | 626ab77 | 2011-10-04 20:13:20 +0200 | [diff] [blame] | 1522 | for (i = 0; vmw_kms_connector_builtin[i].type != 0; i++) { |
| 1523 | bmode = &vmw_kms_connector_builtin[i]; |
| 1524 | if (bmode->hdisplay > max_width || |
| 1525 | bmode->vdisplay > max_height) |
| 1526 | continue; |
| 1527 | |
Sinclair Yeh | 9a72384 | 2014-10-31 09:58:06 +0100 | [diff] [blame] | 1528 | if (!vmw_kms_validate_mode_vram(dev_priv, |
| 1529 | bmode->hdisplay * assumed_bpp, |
Jakob Bornecrantz | 626ab77 | 2011-10-04 20:13:20 +0200 | [diff] [blame] | 1530 | bmode->vdisplay)) |
| 1531 | continue; |
| 1532 | |
| 1533 | mode = drm_mode_duplicate(dev, bmode); |
| 1534 | if (!mode) |
| 1535 | return 0; |
| 1536 | mode->vrefresh = drm_mode_vrefresh(mode); |
| 1537 | |
| 1538 | drm_mode_probed_add(connector, mode); |
| 1539 | } |
| 1540 | |
Ville Syrjälä | 6af3e65 | 2015-12-03 23:14:14 +0200 | [diff] [blame] | 1541 | drm_mode_connector_list_update(connector); |
Thomas Hellstrom | f6b0500 | 2015-06-29 12:59:58 -0700 | [diff] [blame] | 1542 | /* Move the prefered mode first, help apps pick the right mode. */ |
| 1543 | drm_mode_sort(&connector->modes); |
Jakob Bornecrantz | 626ab77 | 2011-10-04 20:13:20 +0200 | [diff] [blame] | 1544 | |
| 1545 | return 1; |
| 1546 | } |
| 1547 | |
| 1548 | int vmw_du_connector_set_property(struct drm_connector *connector, |
| 1549 | struct drm_property *property, |
| 1550 | uint64_t val) |
| 1551 | { |
| 1552 | return 0; |
| 1553 | } |
Thomas Hellstrom | cd2b89e | 2011-10-25 23:35:53 +0200 | [diff] [blame] | 1554 | |
| 1555 | |
| 1556 | int vmw_kms_update_layout_ioctl(struct drm_device *dev, void *data, |
| 1557 | struct drm_file *file_priv) |
| 1558 | { |
| 1559 | struct vmw_private *dev_priv = vmw_priv(dev); |
| 1560 | struct drm_vmw_update_layout_arg *arg = |
| 1561 | (struct drm_vmw_update_layout_arg *)data; |
Thomas Hellstrom | cd2b89e | 2011-10-25 23:35:53 +0200 | [diff] [blame] | 1562 | void __user *user_rects; |
| 1563 | struct drm_vmw_rect *rects; |
| 1564 | unsigned rects_size; |
| 1565 | int ret; |
| 1566 | int i; |
Sinclair Yeh | 65ade7d | 2015-07-16 10:49:13 -0700 | [diff] [blame] | 1567 | u64 total_pixels = 0; |
Thomas Hellstrom | cd2b89e | 2011-10-25 23:35:53 +0200 | [diff] [blame] | 1568 | struct drm_mode_config *mode_config = &dev->mode_config; |
Sinclair Yeh | c8261a9 | 2015-06-26 01:23:42 -0700 | [diff] [blame] | 1569 | struct drm_vmw_rect bounding_box = {0}; |
Thomas Hellstrom | cd2b89e | 2011-10-25 23:35:53 +0200 | [diff] [blame] | 1570 | |
Thomas Hellstrom | cd2b89e | 2011-10-25 23:35:53 +0200 | [diff] [blame] | 1571 | if (!arg->num_outputs) { |
| 1572 | struct drm_vmw_rect def_rect = {0, 0, 800, 600}; |
| 1573 | vmw_du_update_layout(dev_priv, 1, &def_rect); |
Thomas Hellstrom | 5151adb | 2015-03-09 01:56:21 -0700 | [diff] [blame] | 1574 | return 0; |
Thomas Hellstrom | cd2b89e | 2011-10-25 23:35:53 +0200 | [diff] [blame] | 1575 | } |
| 1576 | |
| 1577 | rects_size = arg->num_outputs * sizeof(struct drm_vmw_rect); |
Xi Wang | bab9efc | 2011-11-28 12:25:43 +0100 | [diff] [blame] | 1578 | rects = kcalloc(arg->num_outputs, sizeof(struct drm_vmw_rect), |
| 1579 | GFP_KERNEL); |
Thomas Hellstrom | 5151adb | 2015-03-09 01:56:21 -0700 | [diff] [blame] | 1580 | if (unlikely(!rects)) |
| 1581 | return -ENOMEM; |
Thomas Hellstrom | cd2b89e | 2011-10-25 23:35:53 +0200 | [diff] [blame] | 1582 | |
| 1583 | user_rects = (void __user *)(unsigned long)arg->rects; |
| 1584 | ret = copy_from_user(rects, user_rects, rects_size); |
| 1585 | if (unlikely(ret != 0)) { |
| 1586 | DRM_ERROR("Failed to get rects.\n"); |
| 1587 | ret = -EFAULT; |
| 1588 | goto out_free; |
| 1589 | } |
| 1590 | |
| 1591 | for (i = 0; i < arg->num_outputs; ++i) { |
Xi Wang | bab9efc | 2011-11-28 12:25:43 +0100 | [diff] [blame] | 1592 | if (rects[i].x < 0 || |
| 1593 | rects[i].y < 0 || |
| 1594 | rects[i].x + rects[i].w > mode_config->max_width || |
| 1595 | rects[i].y + rects[i].h > mode_config->max_height) { |
Thomas Hellstrom | cd2b89e | 2011-10-25 23:35:53 +0200 | [diff] [blame] | 1596 | DRM_ERROR("Invalid GUI layout.\n"); |
| 1597 | ret = -EINVAL; |
| 1598 | goto out_free; |
| 1599 | } |
Sinclair Yeh | c8261a9 | 2015-06-26 01:23:42 -0700 | [diff] [blame] | 1600 | |
| 1601 | /* |
| 1602 | * bounding_box.w and bunding_box.h are used as |
| 1603 | * lower-right coordinates |
| 1604 | */ |
| 1605 | if (rects[i].x + rects[i].w > bounding_box.w) |
| 1606 | bounding_box.w = rects[i].x + rects[i].w; |
| 1607 | |
| 1608 | if (rects[i].y + rects[i].h > bounding_box.h) |
| 1609 | bounding_box.h = rects[i].y + rects[i].h; |
Sinclair Yeh | 65ade7d | 2015-07-16 10:49:13 -0700 | [diff] [blame] | 1610 | |
| 1611 | total_pixels += (u64) rects[i].w * (u64) rects[i].h; |
Thomas Hellstrom | cd2b89e | 2011-10-25 23:35:53 +0200 | [diff] [blame] | 1612 | } |
| 1613 | |
Sinclair Yeh | 65ade7d | 2015-07-16 10:49:13 -0700 | [diff] [blame] | 1614 | if (dev_priv->active_display_unit == vmw_du_screen_target) { |
| 1615 | /* |
| 1616 | * For Screen Targets, the limits for a toplogy are: |
| 1617 | * 1. Bounding box (assuming 32bpp) must be < prim_bb_mem |
| 1618 | * 2. Total pixels (assuming 32bpp) must be < prim_bb_mem |
| 1619 | */ |
| 1620 | u64 bb_mem = bounding_box.w * bounding_box.h * 4; |
| 1621 | u64 pixel_mem = total_pixels * 4; |
| 1622 | |
| 1623 | if (bb_mem > dev_priv->prim_bb_mem) { |
| 1624 | DRM_ERROR("Topology is beyond supported limits.\n"); |
Sinclair Yeh | 35c0512 | 2015-06-26 01:42:06 -0700 | [diff] [blame] | 1625 | ret = -EINVAL; |
| 1626 | goto out_free; |
| 1627 | } |
| 1628 | |
Sinclair Yeh | 65ade7d | 2015-07-16 10:49:13 -0700 | [diff] [blame] | 1629 | if (pixel_mem > dev_priv->prim_bb_mem) { |
| 1630 | DRM_ERROR("Combined output size too large\n"); |
| 1631 | ret = -EINVAL; |
| 1632 | goto out_free; |
| 1633 | } |
Thomas Hellstrom | cd2b89e | 2011-10-25 23:35:53 +0200 | [diff] [blame] | 1634 | } |
| 1635 | |
| 1636 | vmw_du_update_layout(dev_priv, arg->num_outputs, rects); |
| 1637 | |
| 1638 | out_free: |
| 1639 | kfree(rects); |
Thomas Hellstrom | cd2b89e | 2011-10-25 23:35:53 +0200 | [diff] [blame] | 1640 | return ret; |
| 1641 | } |
Thomas Hellstrom | 1a4b172 | 2015-06-26 02:03:53 -0700 | [diff] [blame] | 1642 | |
| 1643 | /** |
| 1644 | * vmw_kms_helper_dirty - Helper to build commands and perform actions based |
| 1645 | * on a set of cliprects and a set of display units. |
| 1646 | * |
| 1647 | * @dev_priv: Pointer to a device private structure. |
| 1648 | * @framebuffer: Pointer to the framebuffer on which to perform the actions. |
| 1649 | * @clips: A set of struct drm_clip_rect. Either this os @vclips must be NULL. |
| 1650 | * Cliprects are given in framebuffer coordinates. |
| 1651 | * @vclips: A set of struct drm_vmw_rect cliprects. Either this or @clips must |
| 1652 | * be NULL. Cliprects are given in source coordinates. |
| 1653 | * @dest_x: X coordinate offset for the crtc / destination clip rects. |
| 1654 | * @dest_y: Y coordinate offset for the crtc / destination clip rects. |
| 1655 | * @num_clips: Number of cliprects in the @clips or @vclips array. |
| 1656 | * @increment: Integer with which to increment the clip counter when looping. |
| 1657 | * Used to skip a predetermined number of clip rects. |
| 1658 | * @dirty: Closure structure. See the description of struct vmw_kms_dirty. |
| 1659 | */ |
| 1660 | int vmw_kms_helper_dirty(struct vmw_private *dev_priv, |
| 1661 | struct vmw_framebuffer *framebuffer, |
| 1662 | const struct drm_clip_rect *clips, |
| 1663 | const struct drm_vmw_rect *vclips, |
| 1664 | s32 dest_x, s32 dest_y, |
| 1665 | int num_clips, |
| 1666 | int increment, |
| 1667 | struct vmw_kms_dirty *dirty) |
| 1668 | { |
| 1669 | struct vmw_display_unit *units[VMWGFX_NUM_DISPLAY_UNITS]; |
| 1670 | struct drm_crtc *crtc; |
| 1671 | u32 num_units = 0; |
| 1672 | u32 i, k; |
Thomas Hellstrom | 1a4b172 | 2015-06-26 02:03:53 -0700 | [diff] [blame] | 1673 | |
| 1674 | dirty->dev_priv = dev_priv; |
| 1675 | |
| 1676 | list_for_each_entry(crtc, &dev_priv->dev->mode_config.crtc_list, head) { |
| 1677 | if (crtc->primary->fb != &framebuffer->base) |
| 1678 | continue; |
| 1679 | units[num_units++] = vmw_crtc_to_du(crtc); |
| 1680 | } |
| 1681 | |
| 1682 | for (k = 0; k < num_units; k++) { |
| 1683 | struct vmw_display_unit *unit = units[k]; |
| 1684 | s32 crtc_x = unit->crtc.x; |
| 1685 | s32 crtc_y = unit->crtc.y; |
| 1686 | s32 crtc_width = unit->crtc.mode.hdisplay; |
| 1687 | s32 crtc_height = unit->crtc.mode.vdisplay; |
| 1688 | const struct drm_clip_rect *clips_ptr = clips; |
| 1689 | const struct drm_vmw_rect *vclips_ptr = vclips; |
| 1690 | |
| 1691 | dirty->unit = unit; |
| 1692 | if (dirty->fifo_reserve_size > 0) { |
| 1693 | dirty->cmd = vmw_fifo_reserve(dev_priv, |
| 1694 | dirty->fifo_reserve_size); |
| 1695 | if (!dirty->cmd) { |
| 1696 | DRM_ERROR("Couldn't reserve fifo space " |
| 1697 | "for dirty blits.\n"); |
Christian Engelmayer | f3b8c0c | 2015-09-19 00:32:24 +0200 | [diff] [blame] | 1698 | return -ENOMEM; |
Thomas Hellstrom | 1a4b172 | 2015-06-26 02:03:53 -0700 | [diff] [blame] | 1699 | } |
| 1700 | memset(dirty->cmd, 0, dirty->fifo_reserve_size); |
| 1701 | } |
| 1702 | dirty->num_hits = 0; |
| 1703 | for (i = 0; i < num_clips; i++, clips_ptr += increment, |
| 1704 | vclips_ptr += increment) { |
| 1705 | s32 clip_left; |
| 1706 | s32 clip_top; |
| 1707 | |
| 1708 | /* |
| 1709 | * Select clip array type. Note that integer type |
| 1710 | * in @clips is unsigned short, whereas in @vclips |
| 1711 | * it's 32-bit. |
| 1712 | */ |
| 1713 | if (clips) { |
| 1714 | dirty->fb_x = (s32) clips_ptr->x1; |
| 1715 | dirty->fb_y = (s32) clips_ptr->y1; |
| 1716 | dirty->unit_x2 = (s32) clips_ptr->x2 + dest_x - |
| 1717 | crtc_x; |
| 1718 | dirty->unit_y2 = (s32) clips_ptr->y2 + dest_y - |
| 1719 | crtc_y; |
| 1720 | } else { |
| 1721 | dirty->fb_x = vclips_ptr->x; |
| 1722 | dirty->fb_y = vclips_ptr->y; |
| 1723 | dirty->unit_x2 = dirty->fb_x + vclips_ptr->w + |
| 1724 | dest_x - crtc_x; |
| 1725 | dirty->unit_y2 = dirty->fb_y + vclips_ptr->h + |
| 1726 | dest_y - crtc_y; |
| 1727 | } |
| 1728 | |
| 1729 | dirty->unit_x1 = dirty->fb_x + dest_x - crtc_x; |
| 1730 | dirty->unit_y1 = dirty->fb_y + dest_y - crtc_y; |
| 1731 | |
| 1732 | /* Skip this clip if it's outside the crtc region */ |
| 1733 | if (dirty->unit_x1 >= crtc_width || |
| 1734 | dirty->unit_y1 >= crtc_height || |
| 1735 | dirty->unit_x2 <= 0 || dirty->unit_y2 <= 0) |
| 1736 | continue; |
| 1737 | |
| 1738 | /* Clip right and bottom to crtc limits */ |
| 1739 | dirty->unit_x2 = min_t(s32, dirty->unit_x2, |
| 1740 | crtc_width); |
| 1741 | dirty->unit_y2 = min_t(s32, dirty->unit_y2, |
| 1742 | crtc_height); |
| 1743 | |
| 1744 | /* Clip left and top to crtc limits */ |
| 1745 | clip_left = min_t(s32, dirty->unit_x1, 0); |
| 1746 | clip_top = min_t(s32, dirty->unit_y1, 0); |
| 1747 | dirty->unit_x1 -= clip_left; |
| 1748 | dirty->unit_y1 -= clip_top; |
| 1749 | dirty->fb_x -= clip_left; |
| 1750 | dirty->fb_y -= clip_top; |
| 1751 | |
| 1752 | dirty->clip(dirty); |
| 1753 | } |
| 1754 | |
| 1755 | dirty->fifo_commit(dirty); |
| 1756 | } |
| 1757 | |
| 1758 | return 0; |
| 1759 | } |
| 1760 | |
| 1761 | /** |
| 1762 | * vmw_kms_helper_buffer_prepare - Reserve and validate a buffer object before |
| 1763 | * command submission. |
| 1764 | * |
| 1765 | * @dev_priv. Pointer to a device private structure. |
| 1766 | * @buf: The buffer object |
| 1767 | * @interruptible: Whether to perform waits as interruptible. |
| 1768 | * @validate_as_mob: Whether the buffer should be validated as a MOB. If false, |
| 1769 | * The buffer will be validated as a GMR. Already pinned buffers will not be |
| 1770 | * validated. |
| 1771 | * |
| 1772 | * Returns 0 on success, negative error code on failure, -ERESTARTSYS if |
| 1773 | * interrupted by a signal. |
| 1774 | */ |
| 1775 | int vmw_kms_helper_buffer_prepare(struct vmw_private *dev_priv, |
| 1776 | struct vmw_dma_buffer *buf, |
| 1777 | bool interruptible, |
| 1778 | bool validate_as_mob) |
| 1779 | { |
| 1780 | struct ttm_buffer_object *bo = &buf->base; |
| 1781 | int ret; |
| 1782 | |
Thomas Hellstrom | b9eb1a6 | 2015-04-02 02:39:45 -0700 | [diff] [blame] | 1783 | ttm_bo_reserve(bo, false, false, interruptible, NULL); |
Thomas Hellstrom | 1a4b172 | 2015-06-26 02:03:53 -0700 | [diff] [blame] | 1784 | ret = vmw_validate_single_buffer(dev_priv, bo, interruptible, |
| 1785 | validate_as_mob); |
| 1786 | if (ret) |
| 1787 | ttm_bo_unreserve(bo); |
| 1788 | |
| 1789 | return ret; |
| 1790 | } |
| 1791 | |
| 1792 | /** |
| 1793 | * vmw_kms_helper_buffer_revert - Undo the actions of |
| 1794 | * vmw_kms_helper_buffer_prepare. |
| 1795 | * |
| 1796 | * @res: Pointer to the buffer object. |
| 1797 | * |
| 1798 | * Helper to be used if an error forces the caller to undo the actions of |
| 1799 | * vmw_kms_helper_buffer_prepare. |
| 1800 | */ |
| 1801 | void vmw_kms_helper_buffer_revert(struct vmw_dma_buffer *buf) |
| 1802 | { |
| 1803 | if (buf) |
| 1804 | ttm_bo_unreserve(&buf->base); |
| 1805 | } |
| 1806 | |
| 1807 | /** |
| 1808 | * vmw_kms_helper_buffer_finish - Unreserve and fence a buffer object after |
| 1809 | * kms command submission. |
| 1810 | * |
| 1811 | * @dev_priv: Pointer to a device private structure. |
| 1812 | * @file_priv: Pointer to a struct drm_file representing the caller's |
| 1813 | * connection. Must be set to NULL if @user_fence_rep is NULL, and conversely |
| 1814 | * if non-NULL, @user_fence_rep must be non-NULL. |
| 1815 | * @buf: The buffer object. |
| 1816 | * @out_fence: Optional pointer to a fence pointer. If non-NULL, a |
| 1817 | * ref-counted fence pointer is returned here. |
| 1818 | * @user_fence_rep: Optional pointer to a user-space provided struct |
| 1819 | * drm_vmw_fence_rep. If provided, @file_priv must also be provided and the |
| 1820 | * function copies fence data to user-space in a fail-safe manner. |
| 1821 | */ |
| 1822 | void vmw_kms_helper_buffer_finish(struct vmw_private *dev_priv, |
| 1823 | struct drm_file *file_priv, |
| 1824 | struct vmw_dma_buffer *buf, |
| 1825 | struct vmw_fence_obj **out_fence, |
| 1826 | struct drm_vmw_fence_rep __user * |
| 1827 | user_fence_rep) |
| 1828 | { |
| 1829 | struct vmw_fence_obj *fence; |
| 1830 | uint32_t handle; |
| 1831 | int ret; |
| 1832 | |
| 1833 | ret = vmw_execbuf_fence_commands(file_priv, dev_priv, &fence, |
| 1834 | file_priv ? &handle : NULL); |
| 1835 | if (buf) |
| 1836 | vmw_fence_single_bo(&buf->base, fence); |
| 1837 | if (file_priv) |
| 1838 | vmw_execbuf_copy_fence_user(dev_priv, vmw_fpriv(file_priv), |
| 1839 | ret, user_fence_rep, fence, |
| 1840 | handle); |
| 1841 | if (out_fence) |
| 1842 | *out_fence = fence; |
| 1843 | else |
| 1844 | vmw_fence_obj_unreference(&fence); |
| 1845 | |
| 1846 | vmw_kms_helper_buffer_revert(buf); |
| 1847 | } |
| 1848 | |
| 1849 | |
| 1850 | /** |
| 1851 | * vmw_kms_helper_resource_revert - Undo the actions of |
| 1852 | * vmw_kms_helper_resource_prepare. |
| 1853 | * |
| 1854 | * @res: Pointer to the resource. Typically a surface. |
| 1855 | * |
| 1856 | * Helper to be used if an error forces the caller to undo the actions of |
| 1857 | * vmw_kms_helper_resource_prepare. |
| 1858 | */ |
| 1859 | void vmw_kms_helper_resource_revert(struct vmw_resource *res) |
| 1860 | { |
| 1861 | vmw_kms_helper_buffer_revert(res->backup); |
Thomas Hellstrom | d80efd5 | 2015-08-10 10:39:35 -0700 | [diff] [blame] | 1862 | vmw_resource_unreserve(res, false, NULL, 0); |
Thomas Hellstrom | 1a4b172 | 2015-06-26 02:03:53 -0700 | [diff] [blame] | 1863 | mutex_unlock(&res->dev_priv->cmdbuf_mutex); |
| 1864 | } |
| 1865 | |
| 1866 | /** |
| 1867 | * vmw_kms_helper_resource_prepare - Reserve and validate a resource before |
| 1868 | * command submission. |
| 1869 | * |
| 1870 | * @res: Pointer to the resource. Typically a surface. |
| 1871 | * @interruptible: Whether to perform waits as interruptible. |
| 1872 | * |
| 1873 | * Reserves and validates also the backup buffer if a guest-backed resource. |
| 1874 | * Returns 0 on success, negative error code on failure. -ERESTARTSYS if |
| 1875 | * interrupted by a signal. |
| 1876 | */ |
| 1877 | int vmw_kms_helper_resource_prepare(struct vmw_resource *res, |
| 1878 | bool interruptible) |
| 1879 | { |
| 1880 | int ret = 0; |
| 1881 | |
| 1882 | if (interruptible) |
| 1883 | ret = mutex_lock_interruptible(&res->dev_priv->cmdbuf_mutex); |
| 1884 | else |
| 1885 | mutex_lock(&res->dev_priv->cmdbuf_mutex); |
| 1886 | |
| 1887 | if (unlikely(ret != 0)) |
| 1888 | return -ERESTARTSYS; |
| 1889 | |
| 1890 | ret = vmw_resource_reserve(res, interruptible, false); |
| 1891 | if (ret) |
| 1892 | goto out_unlock; |
| 1893 | |
| 1894 | if (res->backup) { |
| 1895 | ret = vmw_kms_helper_buffer_prepare(res->dev_priv, res->backup, |
| 1896 | interruptible, |
| 1897 | res->dev_priv->has_mob); |
| 1898 | if (ret) |
| 1899 | goto out_unreserve; |
| 1900 | } |
| 1901 | ret = vmw_resource_validate(res); |
| 1902 | if (ret) |
| 1903 | goto out_revert; |
| 1904 | return 0; |
| 1905 | |
| 1906 | out_revert: |
| 1907 | vmw_kms_helper_buffer_revert(res->backup); |
| 1908 | out_unreserve: |
Thomas Hellstrom | d80efd5 | 2015-08-10 10:39:35 -0700 | [diff] [blame] | 1909 | vmw_resource_unreserve(res, false, NULL, 0); |
Thomas Hellstrom | 1a4b172 | 2015-06-26 02:03:53 -0700 | [diff] [blame] | 1910 | out_unlock: |
| 1911 | mutex_unlock(&res->dev_priv->cmdbuf_mutex); |
| 1912 | return ret; |
| 1913 | } |
| 1914 | |
| 1915 | /** |
| 1916 | * vmw_kms_helper_resource_finish - Unreserve and fence a resource after |
| 1917 | * kms command submission. |
| 1918 | * |
| 1919 | * @res: Pointer to the resource. Typically a surface. |
| 1920 | * @out_fence: Optional pointer to a fence pointer. If non-NULL, a |
| 1921 | * ref-counted fence pointer is returned here. |
| 1922 | */ |
| 1923 | void vmw_kms_helper_resource_finish(struct vmw_resource *res, |
| 1924 | struct vmw_fence_obj **out_fence) |
| 1925 | { |
| 1926 | if (res->backup || out_fence) |
| 1927 | vmw_kms_helper_buffer_finish(res->dev_priv, NULL, res->backup, |
| 1928 | out_fence, NULL); |
| 1929 | |
Thomas Hellstrom | d80efd5 | 2015-08-10 10:39:35 -0700 | [diff] [blame] | 1930 | vmw_resource_unreserve(res, false, NULL, 0); |
Thomas Hellstrom | 1a4b172 | 2015-06-26 02:03:53 -0700 | [diff] [blame] | 1931 | mutex_unlock(&res->dev_priv->cmdbuf_mutex); |
| 1932 | } |
Thomas Hellstrom | 6bf6bf0 | 2015-06-26 02:22:40 -0700 | [diff] [blame] | 1933 | |
| 1934 | /** |
| 1935 | * vmw_kms_update_proxy - Helper function to update a proxy surface from |
| 1936 | * its backing MOB. |
| 1937 | * |
| 1938 | * @res: Pointer to the surface resource |
| 1939 | * @clips: Clip rects in framebuffer (surface) space. |
| 1940 | * @num_clips: Number of clips in @clips. |
| 1941 | * @increment: Integer with which to increment the clip counter when looping. |
| 1942 | * Used to skip a predetermined number of clip rects. |
| 1943 | * |
| 1944 | * This function makes sure the proxy surface is updated from its backing MOB |
| 1945 | * using the region given by @clips. The surface resource @res and its backing |
| 1946 | * MOB needs to be reserved and validated on call. |
| 1947 | */ |
| 1948 | int vmw_kms_update_proxy(struct vmw_resource *res, |
| 1949 | const struct drm_clip_rect *clips, |
| 1950 | unsigned num_clips, |
| 1951 | int increment) |
| 1952 | { |
| 1953 | struct vmw_private *dev_priv = res->dev_priv; |
| 1954 | struct drm_vmw_size *size = &vmw_res_to_srf(res)->base_size; |
| 1955 | struct { |
| 1956 | SVGA3dCmdHeader header; |
| 1957 | SVGA3dCmdUpdateGBImage body; |
| 1958 | } *cmd; |
| 1959 | SVGA3dBox *box; |
| 1960 | size_t copy_size = 0; |
| 1961 | int i; |
| 1962 | |
| 1963 | if (!clips) |
| 1964 | return 0; |
| 1965 | |
| 1966 | cmd = vmw_fifo_reserve(dev_priv, sizeof(*cmd) * num_clips); |
| 1967 | if (!cmd) { |
| 1968 | DRM_ERROR("Couldn't reserve fifo space for proxy surface " |
| 1969 | "update.\n"); |
| 1970 | return -ENOMEM; |
| 1971 | } |
| 1972 | |
| 1973 | for (i = 0; i < num_clips; ++i, clips += increment, ++cmd) { |
| 1974 | box = &cmd->body.box; |
| 1975 | |
| 1976 | cmd->header.id = SVGA_3D_CMD_UPDATE_GB_IMAGE; |
| 1977 | cmd->header.size = sizeof(cmd->body); |
| 1978 | cmd->body.image.sid = res->id; |
| 1979 | cmd->body.image.face = 0; |
| 1980 | cmd->body.image.mipmap = 0; |
| 1981 | |
| 1982 | if (clips->x1 > size->width || clips->x2 > size->width || |
| 1983 | clips->y1 > size->height || clips->y2 > size->height) { |
| 1984 | DRM_ERROR("Invalid clips outsize of framebuffer.\n"); |
| 1985 | return -EINVAL; |
| 1986 | } |
| 1987 | |
| 1988 | box->x = clips->x1; |
| 1989 | box->y = clips->y1; |
| 1990 | box->z = 0; |
| 1991 | box->w = clips->x2 - clips->x1; |
| 1992 | box->h = clips->y2 - clips->y1; |
| 1993 | box->d = 1; |
| 1994 | |
| 1995 | copy_size += sizeof(*cmd); |
| 1996 | } |
| 1997 | |
| 1998 | vmw_fifo_commit(dev_priv, copy_size); |
| 1999 | |
| 2000 | return 0; |
| 2001 | } |
Thomas Hellstrom | a278724 | 2015-06-29 12:55:07 -0700 | [diff] [blame] | 2002 | |
| 2003 | int vmw_kms_fbdev_init_data(struct vmw_private *dev_priv, |
| 2004 | unsigned unit, |
| 2005 | u32 max_width, |
| 2006 | u32 max_height, |
| 2007 | struct drm_connector **p_con, |
| 2008 | struct drm_crtc **p_crtc, |
| 2009 | struct drm_display_mode **p_mode) |
| 2010 | { |
| 2011 | struct drm_connector *con; |
| 2012 | struct vmw_display_unit *du; |
| 2013 | struct drm_display_mode *mode; |
| 2014 | int i = 0; |
| 2015 | |
| 2016 | list_for_each_entry(con, &dev_priv->dev->mode_config.connector_list, |
| 2017 | head) { |
| 2018 | if (i == unit) |
| 2019 | break; |
| 2020 | |
| 2021 | ++i; |
| 2022 | } |
| 2023 | |
| 2024 | if (i != unit) { |
| 2025 | DRM_ERROR("Could not find initial display unit.\n"); |
| 2026 | return -EINVAL; |
| 2027 | } |
| 2028 | |
| 2029 | if (list_empty(&con->modes)) |
| 2030 | (void) vmw_du_connector_fill_modes(con, max_width, max_height); |
| 2031 | |
| 2032 | if (list_empty(&con->modes)) { |
| 2033 | DRM_ERROR("Could not find initial display mode.\n"); |
| 2034 | return -EINVAL; |
| 2035 | } |
| 2036 | |
| 2037 | du = vmw_connector_to_du(con); |
| 2038 | *p_con = con; |
| 2039 | *p_crtc = &du->crtc; |
| 2040 | |
| 2041 | list_for_each_entry(mode, &con->modes, head) { |
| 2042 | if (mode->type & DRM_MODE_TYPE_PREFERRED) |
| 2043 | break; |
| 2044 | } |
| 2045 | |
| 2046 | if (mode->type & DRM_MODE_TYPE_PREFERRED) |
| 2047 | *p_mode = mode; |
| 2048 | else { |
| 2049 | WARN_ONCE(true, "Could not find initial preferred mode.\n"); |
| 2050 | *p_mode = list_first_entry(&con->modes, |
| 2051 | struct drm_display_mode, |
| 2052 | head); |
| 2053 | } |
| 2054 | |
| 2055 | return 0; |
| 2056 | } |