Jakob Bornecrantz | d991ef0 | 2011-10-04 20:13:21 +0200 | [diff] [blame] | 1 | /************************************************************************** |
| 2 | * |
Sinclair Yeh | 54fbde8 | 2015-07-29 12:38:02 -0700 | [diff] [blame] | 3 | * Copyright © 2011-2015 VMware, Inc., Palo Alto, CA., USA |
Jakob Bornecrantz | d991ef0 | 2011-10-04 20:13:21 +0200 | [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 | |
David Howells | 760285e | 2012-10-02 18:01:07 +0100 | [diff] [blame] | 28 | #include <drm/ttm/ttm_placement.h> |
Jakob Bornecrantz | d991ef0 | 2011-10-04 20:13:21 +0200 | [diff] [blame] | 29 | |
David Howells | 760285e | 2012-10-02 18:01:07 +0100 | [diff] [blame] | 30 | #include <drm/drmP.h> |
Jakob Bornecrantz | d991ef0 | 2011-10-04 20:13:21 +0200 | [diff] [blame] | 31 | #include "vmwgfx_drv.h" |
| 32 | |
| 33 | |
| 34 | /** |
Thomas Hellstrom | 459d0fa | 2015-06-26 00:25:37 -0700 | [diff] [blame] | 35 | * vmw_dmabuf_pin_in_placement - Validate a buffer to placement. |
Jakob Bornecrantz | d991ef0 | 2011-10-04 20:13:21 +0200 | [diff] [blame] | 36 | * |
Thomas Hellstrom | b37a6b9 | 2011-10-04 20:13:28 +0200 | [diff] [blame] | 37 | * @dev_priv: Driver private. |
| 38 | * @buf: DMA buffer to move. |
Thomas Hellstrom | 459d0fa | 2015-06-26 00:25:37 -0700 | [diff] [blame] | 39 | * @placement: The placement to pin it. |
Thomas Hellstrom | b37a6b9 | 2011-10-04 20:13:28 +0200 | [diff] [blame] | 40 | * @interruptible: Use interruptible wait. |
| 41 | * |
Jakob Bornecrantz | d991ef0 | 2011-10-04 20:13:21 +0200 | [diff] [blame] | 42 | * Returns |
| 43 | * -ERESTARTSYS if interrupted by a signal. |
| 44 | */ |
Thomas Hellstrom | 459d0fa | 2015-06-26 00:25:37 -0700 | [diff] [blame] | 45 | int vmw_dmabuf_pin_in_placement(struct vmw_private *dev_priv, |
| 46 | struct vmw_dma_buffer *buf, |
| 47 | struct ttm_placement *placement, |
| 48 | bool interruptible) |
Jakob Bornecrantz | d991ef0 | 2011-10-04 20:13:21 +0200 | [diff] [blame] | 49 | { |
Jakob Bornecrantz | d991ef0 | 2011-10-04 20:13:21 +0200 | [diff] [blame] | 50 | struct ttm_buffer_object *bo = &buf->base; |
| 51 | int ret; |
Sinclair Yeh | 4ed7e22 | 2016-06-29 13:20:26 -0700 | [diff] [blame] | 52 | uint32_t new_flags; |
Jakob Bornecrantz | d991ef0 | 2011-10-04 20:13:21 +0200 | [diff] [blame] | 53 | |
Thomas Hellstrom | 294adf7 | 2014-02-27 12:34:51 +0100 | [diff] [blame] | 54 | ret = ttm_write_lock(&dev_priv->reservation_sem, interruptible); |
Jakob Bornecrantz | d991ef0 | 2011-10-04 20:13:21 +0200 | [diff] [blame] | 55 | if (unlikely(ret != 0)) |
| 56 | return ret; |
| 57 | |
Thomas Hellstrom | c0951b7 | 2012-11-20 12:19:35 +0000 | [diff] [blame] | 58 | vmw_execbuf_release_pinned_bo(dev_priv); |
Thomas Hellstrom | e2fa3a7 | 2011-10-04 20:13:30 +0200 | [diff] [blame] | 59 | |
Christian König | dfd5e50 | 2016-04-06 11:12:03 +0200 | [diff] [blame] | 60 | ret = ttm_bo_reserve(bo, interruptible, false, NULL); |
Jakob Bornecrantz | d991ef0 | 2011-10-04 20:13:21 +0200 | [diff] [blame] | 61 | if (unlikely(ret != 0)) |
| 62 | goto err; |
| 63 | |
Sinclair Yeh | 4ed7e22 | 2016-06-29 13:20:26 -0700 | [diff] [blame] | 64 | if (buf->pin_count > 0) |
| 65 | ret = ttm_bo_mem_compat(placement, &bo->mem, |
| 66 | &new_flags) == true ? 0 : -EINVAL; |
| 67 | else |
| 68 | ret = ttm_bo_validate(bo, placement, interruptible, false); |
| 69 | |
Thomas Hellstrom | 459d0fa | 2015-06-26 00:25:37 -0700 | [diff] [blame] | 70 | if (!ret) |
| 71 | vmw_bo_pin_reserved(buf, true); |
Jakob Bornecrantz | d991ef0 | 2011-10-04 20:13:21 +0200 | [diff] [blame] | 72 | |
| 73 | ttm_bo_unreserve(bo); |
| 74 | |
| 75 | err: |
Thomas Hellstrom | 294adf7 | 2014-02-27 12:34:51 +0100 | [diff] [blame] | 76 | ttm_write_unlock(&dev_priv->reservation_sem); |
Jakob Bornecrantz | d991ef0 | 2011-10-04 20:13:21 +0200 | [diff] [blame] | 77 | return ret; |
| 78 | } |
| 79 | |
| 80 | /** |
Thomas Hellstrom | 459d0fa | 2015-06-26 00:25:37 -0700 | [diff] [blame] | 81 | * vmw_dmabuf_pin_in_vram_or_gmr - Move a buffer to vram or gmr. |
Jakob Bornecrantz | d991ef0 | 2011-10-04 20:13:21 +0200 | [diff] [blame] | 82 | * |
Thomas Hellstrom | 459d0fa | 2015-06-26 00:25:37 -0700 | [diff] [blame] | 83 | * This function takes the reservation_sem in write mode. |
| 84 | * Flushes and unpins the query bo to avoid failures. |
Jakob Bornecrantz | d991ef0 | 2011-10-04 20:13:21 +0200 | [diff] [blame] | 85 | * |
| 86 | * @dev_priv: Driver private. |
| 87 | * @buf: DMA buffer to move. |
| 88 | * @pin: Pin buffer if true. |
| 89 | * @interruptible: Use interruptible wait. |
| 90 | * |
| 91 | * Returns |
| 92 | * -ERESTARTSYS if interrupted by a signal. |
| 93 | */ |
Thomas Hellstrom | 459d0fa | 2015-06-26 00:25:37 -0700 | [diff] [blame] | 94 | int vmw_dmabuf_pin_in_vram_or_gmr(struct vmw_private *dev_priv, |
| 95 | struct vmw_dma_buffer *buf, |
| 96 | bool interruptible) |
Jakob Bornecrantz | d991ef0 | 2011-10-04 20:13:21 +0200 | [diff] [blame] | 97 | { |
Jakob Bornecrantz | d991ef0 | 2011-10-04 20:13:21 +0200 | [diff] [blame] | 98 | struct ttm_buffer_object *bo = &buf->base; |
Jakob Bornecrantz | d991ef0 | 2011-10-04 20:13:21 +0200 | [diff] [blame] | 99 | int ret; |
Sinclair Yeh | 4ed7e22 | 2016-06-29 13:20:26 -0700 | [diff] [blame] | 100 | uint32_t new_flags; |
Jakob Bornecrantz | d991ef0 | 2011-10-04 20:13:21 +0200 | [diff] [blame] | 101 | |
Thomas Hellstrom | 294adf7 | 2014-02-27 12:34:51 +0100 | [diff] [blame] | 102 | ret = ttm_write_lock(&dev_priv->reservation_sem, interruptible); |
Jakob Bornecrantz | d991ef0 | 2011-10-04 20:13:21 +0200 | [diff] [blame] | 103 | if (unlikely(ret != 0)) |
| 104 | return ret; |
| 105 | |
Thomas Hellstrom | 459d0fa | 2015-06-26 00:25:37 -0700 | [diff] [blame] | 106 | vmw_execbuf_release_pinned_bo(dev_priv); |
Thomas Hellstrom | e2fa3a7 | 2011-10-04 20:13:30 +0200 | [diff] [blame] | 107 | |
Christian König | dfd5e50 | 2016-04-06 11:12:03 +0200 | [diff] [blame] | 108 | ret = ttm_bo_reserve(bo, interruptible, false, NULL); |
Jakob Bornecrantz | d991ef0 | 2011-10-04 20:13:21 +0200 | [diff] [blame] | 109 | if (unlikely(ret != 0)) |
| 110 | goto err; |
| 111 | |
Sinclair Yeh | 4ed7e22 | 2016-06-29 13:20:26 -0700 | [diff] [blame] | 112 | if (buf->pin_count > 0) { |
| 113 | ret = ttm_bo_mem_compat(&vmw_vram_gmr_placement, &bo->mem, |
| 114 | &new_flags) == true ? 0 : -EINVAL; |
| 115 | goto out_unreserve; |
| 116 | } |
| 117 | |
Thomas Hellstrom | 459d0fa | 2015-06-26 00:25:37 -0700 | [diff] [blame] | 118 | ret = ttm_bo_validate(bo, &vmw_vram_gmr_placement, interruptible, |
| 119 | false); |
Jakob Bornecrantz | d991ef0 | 2011-10-04 20:13:21 +0200 | [diff] [blame] | 120 | if (likely(ret == 0) || ret == -ERESTARTSYS) |
Thomas Hellstrom | 459d0fa | 2015-06-26 00:25:37 -0700 | [diff] [blame] | 121 | goto out_unreserve; |
Jakob Bornecrantz | d991ef0 | 2011-10-04 20:13:21 +0200 | [diff] [blame] | 122 | |
Thomas Hellstrom | 459d0fa | 2015-06-26 00:25:37 -0700 | [diff] [blame] | 123 | ret = ttm_bo_validate(bo, &vmw_vram_placement, interruptible, false); |
Jakob Bornecrantz | d991ef0 | 2011-10-04 20:13:21 +0200 | [diff] [blame] | 124 | |
Thomas Hellstrom | 459d0fa | 2015-06-26 00:25:37 -0700 | [diff] [blame] | 125 | out_unreserve: |
| 126 | if (!ret) |
| 127 | vmw_bo_pin_reserved(buf, true); |
Jakob Bornecrantz | d991ef0 | 2011-10-04 20:13:21 +0200 | [diff] [blame] | 128 | |
Jakob Bornecrantz | d991ef0 | 2011-10-04 20:13:21 +0200 | [diff] [blame] | 129 | ttm_bo_unreserve(bo); |
| 130 | err: |
Thomas Hellstrom | 294adf7 | 2014-02-27 12:34:51 +0100 | [diff] [blame] | 131 | ttm_write_unlock(&dev_priv->reservation_sem); |
Jakob Bornecrantz | d991ef0 | 2011-10-04 20:13:21 +0200 | [diff] [blame] | 132 | return ret; |
| 133 | } |
| 134 | |
| 135 | /** |
Thomas Hellstrom | 459d0fa | 2015-06-26 00:25:37 -0700 | [diff] [blame] | 136 | * vmw_dmabuf_pin_in_vram - Move a buffer to vram. |
Jakob Bornecrantz | d991ef0 | 2011-10-04 20:13:21 +0200 | [diff] [blame] | 137 | * |
Thomas Hellstrom | 459d0fa | 2015-06-26 00:25:37 -0700 | [diff] [blame] | 138 | * This function takes the reservation_sem in write mode. |
| 139 | * Flushes and unpins the query bo to avoid failures. |
Jakob Bornecrantz | d991ef0 | 2011-10-04 20:13:21 +0200 | [diff] [blame] | 140 | * |
| 141 | * @dev_priv: Driver private. |
| 142 | * @buf: DMA buffer to move. |
Jakob Bornecrantz | d991ef0 | 2011-10-04 20:13:21 +0200 | [diff] [blame] | 143 | * @interruptible: Use interruptible wait. |
| 144 | * |
| 145 | * Returns |
| 146 | * -ERESTARTSYS if interrupted by a signal. |
| 147 | */ |
Thomas Hellstrom | 459d0fa | 2015-06-26 00:25:37 -0700 | [diff] [blame] | 148 | int vmw_dmabuf_pin_in_vram(struct vmw_private *dev_priv, |
| 149 | struct vmw_dma_buffer *buf, |
| 150 | bool interruptible) |
Jakob Bornecrantz | d991ef0 | 2011-10-04 20:13:21 +0200 | [diff] [blame] | 151 | { |
Thomas Hellstrom | 459d0fa | 2015-06-26 00:25:37 -0700 | [diff] [blame] | 152 | return vmw_dmabuf_pin_in_placement(dev_priv, buf, &vmw_vram_placement, |
| 153 | interruptible); |
Jakob Bornecrantz | d991ef0 | 2011-10-04 20:13:21 +0200 | [diff] [blame] | 154 | } |
| 155 | |
| 156 | /** |
Thomas Hellstrom | 459d0fa | 2015-06-26 00:25:37 -0700 | [diff] [blame] | 157 | * vmw_dmabuf_pin_in_start_of_vram - Move a buffer to start of vram. |
Jakob Bornecrantz | d991ef0 | 2011-10-04 20:13:21 +0200 | [diff] [blame] | 158 | * |
Thomas Hellstrom | 459d0fa | 2015-06-26 00:25:37 -0700 | [diff] [blame] | 159 | * This function takes the reservation_sem in write mode. |
| 160 | * Flushes and unpins the query bo to avoid failures. |
Jakob Bornecrantz | d991ef0 | 2011-10-04 20:13:21 +0200 | [diff] [blame] | 161 | * |
| 162 | * @dev_priv: Driver private. |
Thomas Hellstrom | 459d0fa | 2015-06-26 00:25:37 -0700 | [diff] [blame] | 163 | * @buf: DMA buffer to pin. |
Jakob Bornecrantz | d991ef0 | 2011-10-04 20:13:21 +0200 | [diff] [blame] | 164 | * @interruptible: Use interruptible wait. |
| 165 | * |
| 166 | * Returns |
| 167 | * -ERESTARTSYS if interrupted by a signal. |
| 168 | */ |
Thomas Hellstrom | 459d0fa | 2015-06-26 00:25:37 -0700 | [diff] [blame] | 169 | int vmw_dmabuf_pin_in_start_of_vram(struct vmw_private *dev_priv, |
| 170 | struct vmw_dma_buffer *buf, |
| 171 | bool interruptible) |
Jakob Bornecrantz | d991ef0 | 2011-10-04 20:13:21 +0200 | [diff] [blame] | 172 | { |
Jakob Bornecrantz | d991ef0 | 2011-10-04 20:13:21 +0200 | [diff] [blame] | 173 | struct ttm_buffer_object *bo = &buf->base; |
| 174 | struct ttm_placement placement; |
Christian König | f1217ed | 2014-08-27 13:16:04 +0200 | [diff] [blame] | 175 | struct ttm_place place; |
Jakob Bornecrantz | d991ef0 | 2011-10-04 20:13:21 +0200 | [diff] [blame] | 176 | int ret = 0; |
Sinclair Yeh | 4ed7e22 | 2016-06-29 13:20:26 -0700 | [diff] [blame] | 177 | uint32_t new_flags; |
Jakob Bornecrantz | d991ef0 | 2011-10-04 20:13:21 +0200 | [diff] [blame] | 178 | |
Thomas Hellstrom | 459d0fa | 2015-06-26 00:25:37 -0700 | [diff] [blame] | 179 | place = vmw_vram_placement.placement[0]; |
Christian König | f1217ed | 2014-08-27 13:16:04 +0200 | [diff] [blame] | 180 | place.lpfn = bo->num_pages; |
Christian König | f1217ed | 2014-08-27 13:16:04 +0200 | [diff] [blame] | 181 | placement.num_placement = 1; |
| 182 | placement.placement = &place; |
| 183 | placement.num_busy_placement = 1; |
| 184 | placement.busy_placement = &place; |
Jakob Bornecrantz | d991ef0 | 2011-10-04 20:13:21 +0200 | [diff] [blame] | 185 | |
Thomas Hellstrom | 294adf7 | 2014-02-27 12:34:51 +0100 | [diff] [blame] | 186 | ret = ttm_write_lock(&dev_priv->reservation_sem, interruptible); |
Jakob Bornecrantz | d991ef0 | 2011-10-04 20:13:21 +0200 | [diff] [blame] | 187 | if (unlikely(ret != 0)) |
| 188 | return ret; |
| 189 | |
Thomas Hellstrom | 459d0fa | 2015-06-26 00:25:37 -0700 | [diff] [blame] | 190 | vmw_execbuf_release_pinned_bo(dev_priv); |
Christian König | dfd5e50 | 2016-04-06 11:12:03 +0200 | [diff] [blame] | 191 | ret = ttm_bo_reserve(bo, interruptible, false, NULL); |
Jakob Bornecrantz | d991ef0 | 2011-10-04 20:13:21 +0200 | [diff] [blame] | 192 | if (unlikely(ret != 0)) |
| 193 | goto err_unlock; |
| 194 | |
Thomas Hellstrom | 459d0fa | 2015-06-26 00:25:37 -0700 | [diff] [blame] | 195 | /* |
| 196 | * Is this buffer already in vram but not at the start of it? |
| 197 | * In that case, evict it first because TTM isn't good at handling |
| 198 | * that situation. |
| 199 | */ |
Jakob Bornecrantz | d991ef0 | 2011-10-04 20:13:21 +0200 | [diff] [blame] | 200 | if (bo->mem.mem_type == TTM_PL_VRAM && |
| 201 | bo->mem.start < bo->num_pages && |
Sinclair Yeh | 4ed7e22 | 2016-06-29 13:20:26 -0700 | [diff] [blame] | 202 | bo->mem.start > 0 && |
| 203 | buf->pin_count == 0) |
Maarten Lankhorst | 97a875c | 2012-11-28 11:25:44 +0000 | [diff] [blame] | 204 | (void) ttm_bo_validate(bo, &vmw_sys_placement, false, false); |
Jakob Bornecrantz | d991ef0 | 2011-10-04 20:13:21 +0200 | [diff] [blame] | 205 | |
Sinclair Yeh | 4ed7e22 | 2016-06-29 13:20:26 -0700 | [diff] [blame] | 206 | if (buf->pin_count > 0) |
| 207 | ret = ttm_bo_mem_compat(&placement, &bo->mem, |
| 208 | &new_flags) == true ? 0 : -EINVAL; |
| 209 | else |
| 210 | ret = ttm_bo_validate(bo, &placement, interruptible, false); |
Jakob Bornecrantz | d991ef0 | 2011-10-04 20:13:21 +0200 | [diff] [blame] | 211 | |
Thomas Hellstrom | 459d0fa | 2015-06-26 00:25:37 -0700 | [diff] [blame] | 212 | /* For some reason we didn't end up at the start of vram */ |
Jakob Bornecrantz | d991ef0 | 2011-10-04 20:13:21 +0200 | [diff] [blame] | 213 | WARN_ON(ret == 0 && bo->offset != 0); |
Thomas Hellstrom | 459d0fa | 2015-06-26 00:25:37 -0700 | [diff] [blame] | 214 | if (!ret) |
| 215 | vmw_bo_pin_reserved(buf, true); |
Jakob Bornecrantz | d991ef0 | 2011-10-04 20:13:21 +0200 | [diff] [blame] | 216 | |
| 217 | ttm_bo_unreserve(bo); |
| 218 | err_unlock: |
Thomas Hellstrom | 294adf7 | 2014-02-27 12:34:51 +0100 | [diff] [blame] | 219 | ttm_write_unlock(&dev_priv->reservation_sem); |
Jakob Bornecrantz | d991ef0 | 2011-10-04 20:13:21 +0200 | [diff] [blame] | 220 | |
| 221 | return ret; |
| 222 | } |
| 223 | |
| 224 | /** |
Thomas Hellstrom | 459d0fa | 2015-06-26 00:25:37 -0700 | [diff] [blame] | 225 | * vmw_dmabuf_unpin - Unpin the buffer given buffer, does not move the buffer. |
Jakob Bornecrantz | d991ef0 | 2011-10-04 20:13:21 +0200 | [diff] [blame] | 226 | * |
Thomas Hellstrom | 459d0fa | 2015-06-26 00:25:37 -0700 | [diff] [blame] | 227 | * This function takes the reservation_sem in write mode. |
Jakob Bornecrantz | d991ef0 | 2011-10-04 20:13:21 +0200 | [diff] [blame] | 228 | * |
| 229 | * @dev_priv: Driver private. |
| 230 | * @buf: DMA buffer to unpin. |
| 231 | * @interruptible: Use interruptible wait. |
| 232 | * |
| 233 | * Returns |
| 234 | * -ERESTARTSYS if interrupted by a signal. |
| 235 | */ |
| 236 | int vmw_dmabuf_unpin(struct vmw_private *dev_priv, |
| 237 | struct vmw_dma_buffer *buf, |
| 238 | bool interruptible) |
| 239 | { |
Thomas Hellstrom | 459d0fa | 2015-06-26 00:25:37 -0700 | [diff] [blame] | 240 | struct ttm_buffer_object *bo = &buf->base; |
| 241 | int ret; |
Jakob Bornecrantz | d991ef0 | 2011-10-04 20:13:21 +0200 | [diff] [blame] | 242 | |
Thomas Hellstrom | 459d0fa | 2015-06-26 00:25:37 -0700 | [diff] [blame] | 243 | ret = ttm_read_lock(&dev_priv->reservation_sem, interruptible); |
| 244 | if (unlikely(ret != 0)) |
| 245 | return ret; |
| 246 | |
Christian König | dfd5e50 | 2016-04-06 11:12:03 +0200 | [diff] [blame] | 247 | ret = ttm_bo_reserve(bo, interruptible, false, NULL); |
Thomas Hellstrom | 459d0fa | 2015-06-26 00:25:37 -0700 | [diff] [blame] | 248 | if (unlikely(ret != 0)) |
| 249 | goto err; |
| 250 | |
| 251 | vmw_bo_pin_reserved(buf, false); |
| 252 | |
| 253 | ttm_bo_unreserve(bo); |
| 254 | |
| 255 | err: |
| 256 | ttm_read_unlock(&dev_priv->reservation_sem); |
| 257 | return ret; |
| 258 | } |
Thomas Hellstrom | b37a6b9 | 2011-10-04 20:13:28 +0200 | [diff] [blame] | 259 | |
Jakob Bornecrantz | d991ef0 | 2011-10-04 20:13:21 +0200 | [diff] [blame] | 260 | /** |
Thomas Hellstrom | b37a6b9 | 2011-10-04 20:13:28 +0200 | [diff] [blame] | 261 | * vmw_bo_get_guest_ptr - Get the guest ptr representing the current placement |
| 262 | * of a buffer. |
Jakob Bornecrantz | d991ef0 | 2011-10-04 20:13:21 +0200 | [diff] [blame] | 263 | * |
Thomas Hellstrom | b37a6b9 | 2011-10-04 20:13:28 +0200 | [diff] [blame] | 264 | * @bo: Pointer to a struct ttm_buffer_object. Must be pinned or reserved. |
| 265 | * @ptr: SVGAGuestPtr returning the result. |
Jakob Bornecrantz | d991ef0 | 2011-10-04 20:13:21 +0200 | [diff] [blame] | 266 | */ |
Thomas Hellstrom | b37a6b9 | 2011-10-04 20:13:28 +0200 | [diff] [blame] | 267 | void vmw_bo_get_guest_ptr(const struct ttm_buffer_object *bo, |
| 268 | SVGAGuestPtr *ptr) |
Jakob Bornecrantz | d991ef0 | 2011-10-04 20:13:21 +0200 | [diff] [blame] | 269 | { |
Thomas Hellstrom | b37a6b9 | 2011-10-04 20:13:28 +0200 | [diff] [blame] | 270 | if (bo->mem.mem_type == TTM_PL_VRAM) { |
Jakob Bornecrantz | d991ef0 | 2011-10-04 20:13:21 +0200 | [diff] [blame] | 271 | ptr->gmrId = SVGA_GMR_FRAMEBUFFER; |
Thomas Hellstrom | b37a6b9 | 2011-10-04 20:13:28 +0200 | [diff] [blame] | 272 | ptr->offset = bo->offset; |
Jakob Bornecrantz | d991ef0 | 2011-10-04 20:13:21 +0200 | [diff] [blame] | 273 | } else { |
Thomas Hellstrom | b37a6b9 | 2011-10-04 20:13:28 +0200 | [diff] [blame] | 274 | ptr->gmrId = bo->mem.start; |
Jakob Bornecrantz | d991ef0 | 2011-10-04 20:13:21 +0200 | [diff] [blame] | 275 | ptr->offset = 0; |
| 276 | } |
| 277 | } |
Thomas Hellstrom | e2fa3a7 | 2011-10-04 20:13:30 +0200 | [diff] [blame] | 278 | |
| 279 | |
| 280 | /** |
Thomas Hellstrom | 459d0fa | 2015-06-26 00:25:37 -0700 | [diff] [blame] | 281 | * vmw_bo_pin_reserved - Pin or unpin a buffer object without moving it. |
Thomas Hellstrom | e2fa3a7 | 2011-10-04 20:13:30 +0200 | [diff] [blame] | 282 | * |
Thomas Hellstrom | 459d0fa | 2015-06-26 00:25:37 -0700 | [diff] [blame] | 283 | * @vbo: The buffer object. Must be reserved. |
Thomas Hellstrom | e2fa3a7 | 2011-10-04 20:13:30 +0200 | [diff] [blame] | 284 | * @pin: Whether to pin or unpin. |
| 285 | * |
| 286 | */ |
Thomas Hellstrom | 459d0fa | 2015-06-26 00:25:37 -0700 | [diff] [blame] | 287 | void vmw_bo_pin_reserved(struct vmw_dma_buffer *vbo, bool pin) |
Thomas Hellstrom | e2fa3a7 | 2011-10-04 20:13:30 +0200 | [diff] [blame] | 288 | { |
Christian König | f1217ed | 2014-08-27 13:16:04 +0200 | [diff] [blame] | 289 | struct ttm_place pl; |
Thomas Hellstrom | e2fa3a7 | 2011-10-04 20:13:30 +0200 | [diff] [blame] | 290 | struct ttm_placement placement; |
Thomas Hellstrom | 459d0fa | 2015-06-26 00:25:37 -0700 | [diff] [blame] | 291 | struct ttm_buffer_object *bo = &vbo->base; |
Thomas Hellstrom | e2fa3a7 | 2011-10-04 20:13:30 +0200 | [diff] [blame] | 292 | uint32_t old_mem_type = bo->mem.mem_type; |
| 293 | int ret; |
| 294 | |
Maarten Lankhorst | 8bd4ce5 | 2013-06-27 13:48:27 +0200 | [diff] [blame] | 295 | lockdep_assert_held(&bo->resv->lock.base); |
Thomas Hellstrom | e2fa3a7 | 2011-10-04 20:13:30 +0200 | [diff] [blame] | 296 | |
Thomas Hellstrom | 459d0fa | 2015-06-26 00:25:37 -0700 | [diff] [blame] | 297 | if (pin) { |
| 298 | if (vbo->pin_count++ > 0) |
| 299 | return; |
| 300 | } else { |
| 301 | WARN_ON(vbo->pin_count <= 0); |
| 302 | if (--vbo->pin_count > 0) |
| 303 | return; |
| 304 | } |
| 305 | |
Christian König | f1217ed | 2014-08-27 13:16:04 +0200 | [diff] [blame] | 306 | pl.fpfn = 0; |
| 307 | pl.lpfn = 0; |
| 308 | pl.flags = TTM_PL_FLAG_VRAM | VMW_PL_FLAG_GMR | VMW_PL_FLAG_MOB |
Thomas Hellstrom | 4b9e45e | 2013-10-10 09:52:52 -0700 | [diff] [blame] | 309 | | TTM_PL_FLAG_SYSTEM | TTM_PL_FLAG_CACHED; |
Thomas Hellstrom | e2fa3a7 | 2011-10-04 20:13:30 +0200 | [diff] [blame] | 310 | if (pin) |
Christian König | f1217ed | 2014-08-27 13:16:04 +0200 | [diff] [blame] | 311 | pl.flags |= TTM_PL_FLAG_NO_EVICT; |
Thomas Hellstrom | e2fa3a7 | 2011-10-04 20:13:30 +0200 | [diff] [blame] | 312 | |
| 313 | memset(&placement, 0, sizeof(placement)); |
| 314 | placement.num_placement = 1; |
Christian König | f1217ed | 2014-08-27 13:16:04 +0200 | [diff] [blame] | 315 | placement.placement = &pl; |
Thomas Hellstrom | e2fa3a7 | 2011-10-04 20:13:30 +0200 | [diff] [blame] | 316 | |
Maarten Lankhorst | 97a875c | 2012-11-28 11:25:44 +0000 | [diff] [blame] | 317 | ret = ttm_bo_validate(bo, &placement, false, true); |
Thomas Hellstrom | e2fa3a7 | 2011-10-04 20:13:30 +0200 | [diff] [blame] | 318 | |
| 319 | BUG_ON(ret != 0 || bo->mem.mem_type != old_mem_type); |
| 320 | } |