Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2007 Dave Airlied |
| 3 | * All Rights Reserved. |
| 4 | * |
| 5 | * Permission is hereby granted, free of charge, to any person obtaining a |
| 6 | * copy of this software and associated documentation files (the "Software"), |
| 7 | * to deal in the Software without restriction, including without limitation |
| 8 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 9 | * and/or sell copies of the Software, and to permit persons to whom the |
| 10 | * Software is furnished to do so, subject to the following conditions: |
| 11 | * |
| 12 | * The above copyright notice and this permission notice (including the next |
| 13 | * paragraph) shall be included in all copies or substantial portions of the |
| 14 | * Software. |
| 15 | * |
| 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 19 | * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR |
| 20 | * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, |
| 21 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
| 22 | * OTHER DEALINGS IN THE SOFTWARE. |
| 23 | */ |
| 24 | /* |
| 25 | * Authors: Dave Airlied <airlied@linux.ie> |
| 26 | * Ben Skeggs <darktama@iinet.net.au> |
| 27 | * Jeremy Kolb <jkolb@brandeis.edu> |
| 28 | */ |
| 29 | |
| 30 | #include "drmP.h" |
| 31 | |
| 32 | #include "nouveau_drm.h" |
| 33 | #include "nouveau_drv.h" |
| 34 | #include "nouveau_dma.h" |
Ben Skeggs | f869ef8 | 2010-11-15 11:53:16 +1000 | [diff] [blame] | 35 | #include "nouveau_mm.h" |
| 36 | #include "nouveau_vm.h" |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 37 | |
Maarten Maathuis | a510604 | 2009-12-26 21:46:36 +0100 | [diff] [blame] | 38 | #include <linux/log2.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 39 | #include <linux/slab.h> |
Maarten Maathuis | a510604 | 2009-12-26 21:46:36 +0100 | [diff] [blame] | 40 | |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 41 | static void |
| 42 | nouveau_bo_del_ttm(struct ttm_buffer_object *bo) |
| 43 | { |
| 44 | struct drm_nouveau_private *dev_priv = nouveau_bdev(bo->bdev); |
Francisco Jerez | a0af9ad | 2009-12-11 16:51:09 +0100 | [diff] [blame] | 45 | struct drm_device *dev = dev_priv->dev; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 46 | struct nouveau_bo *nvbo = nouveau_bo(bo); |
| 47 | |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 48 | if (unlikely(nvbo->gem)) |
| 49 | DRM_ERROR("bo %p still attached to GEM object\n", bo); |
| 50 | |
Francisco Jerez | a5cf68b | 2010-10-24 16:14:41 +0200 | [diff] [blame] | 51 | nv10_mem_put_tile_region(dev, nvbo->tile, NULL); |
Ben Skeggs | 4c13614 | 2010-11-15 11:54:21 +1000 | [diff] [blame] | 52 | nouveau_vm_put(&nvbo->vma); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 53 | kfree(nvbo); |
| 54 | } |
| 55 | |
Francisco Jerez | a0af9ad | 2009-12-11 16:51:09 +0100 | [diff] [blame] | 56 | static void |
Ben Skeggs | bfd83ac | 2010-11-12 15:12:51 +1000 | [diff] [blame^] | 57 | nouveau_bo_fixup_align(struct nouveau_bo *nvbo, int *align, int *size, |
| 58 | int *page_shift) |
Francisco Jerez | a0af9ad | 2009-12-11 16:51:09 +0100 | [diff] [blame] | 59 | { |
Ben Skeggs | bfd83ac | 2010-11-12 15:12:51 +1000 | [diff] [blame^] | 60 | struct drm_nouveau_private *dev_priv = nouveau_bdev(nvbo->bo.bdev); |
Francisco Jerez | a0af9ad | 2009-12-11 16:51:09 +0100 | [diff] [blame] | 61 | |
Ben Skeggs | 573a2a3 | 2010-08-25 15:26:04 +1000 | [diff] [blame] | 62 | if (dev_priv->card_type < NV_50) { |
Ben Skeggs | bfd83ac | 2010-11-12 15:12:51 +1000 | [diff] [blame^] | 63 | if (nvbo->tile_mode) { |
Francisco Jerez | a0af9ad | 2009-12-11 16:51:09 +0100 | [diff] [blame] | 64 | if (dev_priv->chipset >= 0x40) { |
| 65 | *align = 65536; |
Ben Skeggs | bfd83ac | 2010-11-12 15:12:51 +1000 | [diff] [blame^] | 66 | *size = roundup(*size, 64 * nvbo->tile_mode); |
Francisco Jerez | a0af9ad | 2009-12-11 16:51:09 +0100 | [diff] [blame] | 67 | |
| 68 | } else if (dev_priv->chipset >= 0x30) { |
| 69 | *align = 32768; |
Ben Skeggs | bfd83ac | 2010-11-12 15:12:51 +1000 | [diff] [blame^] | 70 | *size = roundup(*size, 64 * nvbo->tile_mode); |
Francisco Jerez | a0af9ad | 2009-12-11 16:51:09 +0100 | [diff] [blame] | 71 | |
| 72 | } else if (dev_priv->chipset >= 0x20) { |
| 73 | *align = 16384; |
Ben Skeggs | bfd83ac | 2010-11-12 15:12:51 +1000 | [diff] [blame^] | 74 | *size = roundup(*size, 64 * nvbo->tile_mode); |
Francisco Jerez | a0af9ad | 2009-12-11 16:51:09 +0100 | [diff] [blame] | 75 | |
| 76 | } else if (dev_priv->chipset >= 0x10) { |
| 77 | *align = 16384; |
Ben Skeggs | bfd83ac | 2010-11-12 15:12:51 +1000 | [diff] [blame^] | 78 | *size = roundup(*size, 32 * nvbo->tile_mode); |
Francisco Jerez | a0af9ad | 2009-12-11 16:51:09 +0100 | [diff] [blame] | 79 | } |
| 80 | } |
Ben Skeggs | bfd83ac | 2010-11-12 15:12:51 +1000 | [diff] [blame^] | 81 | } else { |
| 82 | if (likely(dev_priv->chan_vm)) { |
| 83 | if (*size > 256 * 1024) |
| 84 | *page_shift = dev_priv->chan_vm->lpg_shift; |
| 85 | else |
| 86 | *page_shift = dev_priv->chan_vm->spg_shift; |
| 87 | } else { |
| 88 | *page_shift = 12; |
| 89 | } |
| 90 | |
| 91 | *size = roundup(*size, (1 << *page_shift)); |
| 92 | *align = max((1 << *page_shift), *align); |
Francisco Jerez | a0af9ad | 2009-12-11 16:51:09 +0100 | [diff] [blame] | 93 | } |
| 94 | |
Maarten Maathuis | 1c7059e | 2009-12-25 18:51:17 +0100 | [diff] [blame] | 95 | *size = roundup(*size, PAGE_SIZE); |
Francisco Jerez | a0af9ad | 2009-12-11 16:51:09 +0100 | [diff] [blame] | 96 | } |
| 97 | |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 98 | int |
| 99 | nouveau_bo_new(struct drm_device *dev, struct nouveau_channel *chan, |
| 100 | int size, int align, uint32_t flags, uint32_t tile_mode, |
| 101 | uint32_t tile_flags, bool no_vm, bool mappable, |
| 102 | struct nouveau_bo **pnvbo) |
| 103 | { |
| 104 | struct drm_nouveau_private *dev_priv = dev->dev_private; |
| 105 | struct nouveau_bo *nvbo; |
Ben Skeggs | bfd83ac | 2010-11-12 15:12:51 +1000 | [diff] [blame^] | 106 | int ret = 0, page_shift = 0; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 107 | |
| 108 | nvbo = kzalloc(sizeof(struct nouveau_bo), GFP_KERNEL); |
| 109 | if (!nvbo) |
| 110 | return -ENOMEM; |
| 111 | INIT_LIST_HEAD(&nvbo->head); |
| 112 | INIT_LIST_HEAD(&nvbo->entry); |
| 113 | nvbo->mappable = mappable; |
| 114 | nvbo->no_vm = no_vm; |
| 115 | nvbo->tile_mode = tile_mode; |
| 116 | nvbo->tile_flags = tile_flags; |
Francisco Jerez | 699ddfd | 2010-10-10 06:07:32 +0200 | [diff] [blame] | 117 | nvbo->bo.bdev = &dev_priv->ttm.bdev; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 118 | |
Ben Skeggs | bfd83ac | 2010-11-12 15:12:51 +1000 | [diff] [blame^] | 119 | nouveau_bo_fixup_align(nvbo, &align, &size, &page_shift); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 120 | align >>= PAGE_SHIFT; |
| 121 | |
Ben Skeggs | 4c13614 | 2010-11-15 11:54:21 +1000 | [diff] [blame] | 122 | if (!nvbo->no_vm && dev_priv->chan_vm) { |
Ben Skeggs | bfd83ac | 2010-11-12 15:12:51 +1000 | [diff] [blame^] | 123 | ret = nouveau_vm_get(dev_priv->chan_vm, size, page_shift, |
Ben Skeggs | 4c13614 | 2010-11-15 11:54:21 +1000 | [diff] [blame] | 124 | NV_MEM_ACCESS_RW, &nvbo->vma); |
| 125 | if (ret) { |
| 126 | kfree(nvbo); |
| 127 | return ret; |
| 128 | } |
| 129 | } |
| 130 | |
Francisco Jerez | 78ad0f7 | 2010-03-18 13:07:47 +0100 | [diff] [blame] | 131 | nouveau_bo_placement_set(nvbo, flags, 0); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 132 | |
| 133 | nvbo->channel = chan; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 134 | ret = ttm_bo_init(&dev_priv->ttm.bdev, &nvbo->bo, size, |
| 135 | ttm_bo_type_device, &nvbo->placement, align, 0, |
| 136 | false, NULL, size, nouveau_bo_del_ttm); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 137 | if (ret) { |
| 138 | /* ttm will call nouveau_bo_del_ttm if it fails.. */ |
| 139 | return ret; |
| 140 | } |
Ben Skeggs | 90af89b | 2010-04-15 14:42:34 +1000 | [diff] [blame] | 141 | nvbo->channel = NULL; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 142 | |
Ben Skeggs | 4c13614 | 2010-11-15 11:54:21 +1000 | [diff] [blame] | 143 | if (nvbo->vma.node) { |
| 144 | if (nvbo->bo.mem.mem_type == TTM_PL_VRAM) |
| 145 | nvbo->bo.offset = nvbo->vma.offset; |
| 146 | } |
| 147 | |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 148 | *pnvbo = nvbo; |
| 149 | return 0; |
| 150 | } |
| 151 | |
Francisco Jerez | 78ad0f7 | 2010-03-18 13:07:47 +0100 | [diff] [blame] | 152 | static void |
| 153 | set_placement_list(uint32_t *pl, unsigned *n, uint32_t type, uint32_t flags) |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 154 | { |
Francisco Jerez | 78ad0f7 | 2010-03-18 13:07:47 +0100 | [diff] [blame] | 155 | *n = 0; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 156 | |
Francisco Jerez | 78ad0f7 | 2010-03-18 13:07:47 +0100 | [diff] [blame] | 157 | if (type & TTM_PL_FLAG_VRAM) |
| 158 | pl[(*n)++] = TTM_PL_FLAG_VRAM | flags; |
| 159 | if (type & TTM_PL_FLAG_TT) |
| 160 | pl[(*n)++] = TTM_PL_FLAG_TT | flags; |
| 161 | if (type & TTM_PL_FLAG_SYSTEM) |
| 162 | pl[(*n)++] = TTM_PL_FLAG_SYSTEM | flags; |
| 163 | } |
Ben Skeggs | 37cb3e08 | 2009-12-16 16:22:42 +1000 | [diff] [blame] | 164 | |
Francisco Jerez | 699ddfd | 2010-10-10 06:07:32 +0200 | [diff] [blame] | 165 | static void |
| 166 | set_placement_range(struct nouveau_bo *nvbo, uint32_t type) |
| 167 | { |
| 168 | struct drm_nouveau_private *dev_priv = nouveau_bdev(nvbo->bo.bdev); |
| 169 | |
| 170 | if (dev_priv->card_type == NV_10 && |
| 171 | nvbo->tile_mode && (type & TTM_PL_FLAG_VRAM)) { |
| 172 | /* |
| 173 | * Make sure that the color and depth buffers are handled |
| 174 | * by independent memory controller units. Up to a 9x |
| 175 | * speed up when alpha-blending and depth-test are enabled |
| 176 | * at the same time. |
| 177 | */ |
| 178 | int vram_pages = dev_priv->vram_size >> PAGE_SHIFT; |
| 179 | |
| 180 | if (nvbo->tile_flags & NOUVEAU_GEM_TILE_ZETA) { |
| 181 | nvbo->placement.fpfn = vram_pages / 2; |
| 182 | nvbo->placement.lpfn = ~0; |
| 183 | } else { |
| 184 | nvbo->placement.fpfn = 0; |
| 185 | nvbo->placement.lpfn = vram_pages / 2; |
| 186 | } |
| 187 | } |
| 188 | } |
| 189 | |
Francisco Jerez | 78ad0f7 | 2010-03-18 13:07:47 +0100 | [diff] [blame] | 190 | void |
| 191 | nouveau_bo_placement_set(struct nouveau_bo *nvbo, uint32_t type, uint32_t busy) |
| 192 | { |
| 193 | struct ttm_placement *pl = &nvbo->placement; |
| 194 | uint32_t flags = TTM_PL_MASK_CACHING | |
| 195 | (nvbo->pin_refcnt ? TTM_PL_FLAG_NO_EVICT : 0); |
| 196 | |
| 197 | pl->placement = nvbo->placements; |
| 198 | set_placement_list(nvbo->placements, &pl->num_placement, |
| 199 | type, flags); |
| 200 | |
| 201 | pl->busy_placement = nvbo->busy_placements; |
| 202 | set_placement_list(nvbo->busy_placements, &pl->num_busy_placement, |
| 203 | type | busy, flags); |
Francisco Jerez | 699ddfd | 2010-10-10 06:07:32 +0200 | [diff] [blame] | 204 | |
| 205 | set_placement_range(nvbo, type); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 206 | } |
| 207 | |
| 208 | int |
| 209 | nouveau_bo_pin(struct nouveau_bo *nvbo, uint32_t memtype) |
| 210 | { |
| 211 | struct drm_nouveau_private *dev_priv = nouveau_bdev(nvbo->bo.bdev); |
| 212 | struct ttm_buffer_object *bo = &nvbo->bo; |
Francisco Jerez | 78ad0f7 | 2010-03-18 13:07:47 +0100 | [diff] [blame] | 213 | int ret; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 214 | |
| 215 | if (nvbo->pin_refcnt && !(memtype & (1 << bo->mem.mem_type))) { |
| 216 | NV_ERROR(nouveau_bdev(bo->bdev)->dev, |
| 217 | "bo %p pinned elsewhere: 0x%08x vs 0x%08x\n", bo, |
| 218 | 1 << bo->mem.mem_type, memtype); |
| 219 | return -EINVAL; |
| 220 | } |
| 221 | |
| 222 | if (nvbo->pin_refcnt++) |
| 223 | return 0; |
| 224 | |
| 225 | ret = ttm_bo_reserve(bo, false, false, false, 0); |
| 226 | if (ret) |
| 227 | goto out; |
| 228 | |
Francisco Jerez | 78ad0f7 | 2010-03-18 13:07:47 +0100 | [diff] [blame] | 229 | nouveau_bo_placement_set(nvbo, memtype, 0); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 230 | |
Ben Skeggs | 7a45d76 | 2010-11-22 08:50:27 +1000 | [diff] [blame] | 231 | ret = nouveau_bo_validate(nvbo, false, false, false); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 232 | if (ret == 0) { |
| 233 | switch (bo->mem.mem_type) { |
| 234 | case TTM_PL_VRAM: |
| 235 | dev_priv->fb_aper_free -= bo->mem.size; |
| 236 | break; |
| 237 | case TTM_PL_TT: |
| 238 | dev_priv->gart_info.aper_free -= bo->mem.size; |
| 239 | break; |
| 240 | default: |
| 241 | break; |
| 242 | } |
| 243 | } |
| 244 | ttm_bo_unreserve(bo); |
| 245 | out: |
| 246 | if (unlikely(ret)) |
| 247 | nvbo->pin_refcnt--; |
| 248 | return ret; |
| 249 | } |
| 250 | |
| 251 | int |
| 252 | nouveau_bo_unpin(struct nouveau_bo *nvbo) |
| 253 | { |
| 254 | struct drm_nouveau_private *dev_priv = nouveau_bdev(nvbo->bo.bdev); |
| 255 | struct ttm_buffer_object *bo = &nvbo->bo; |
Francisco Jerez | 78ad0f7 | 2010-03-18 13:07:47 +0100 | [diff] [blame] | 256 | int ret; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 257 | |
| 258 | if (--nvbo->pin_refcnt) |
| 259 | return 0; |
| 260 | |
| 261 | ret = ttm_bo_reserve(bo, false, false, false, 0); |
| 262 | if (ret) |
| 263 | return ret; |
| 264 | |
Francisco Jerez | 78ad0f7 | 2010-03-18 13:07:47 +0100 | [diff] [blame] | 265 | nouveau_bo_placement_set(nvbo, bo->mem.placement, 0); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 266 | |
Ben Skeggs | 7a45d76 | 2010-11-22 08:50:27 +1000 | [diff] [blame] | 267 | ret = nouveau_bo_validate(nvbo, false, false, false); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 268 | if (ret == 0) { |
| 269 | switch (bo->mem.mem_type) { |
| 270 | case TTM_PL_VRAM: |
| 271 | dev_priv->fb_aper_free += bo->mem.size; |
| 272 | break; |
| 273 | case TTM_PL_TT: |
| 274 | dev_priv->gart_info.aper_free += bo->mem.size; |
| 275 | break; |
| 276 | default: |
| 277 | break; |
| 278 | } |
| 279 | } |
| 280 | |
| 281 | ttm_bo_unreserve(bo); |
| 282 | return ret; |
| 283 | } |
| 284 | |
| 285 | int |
| 286 | nouveau_bo_map(struct nouveau_bo *nvbo) |
| 287 | { |
| 288 | int ret; |
| 289 | |
| 290 | ret = ttm_bo_reserve(&nvbo->bo, false, false, false, 0); |
| 291 | if (ret) |
| 292 | return ret; |
| 293 | |
| 294 | ret = ttm_bo_kmap(&nvbo->bo, 0, nvbo->bo.mem.num_pages, &nvbo->kmap); |
| 295 | ttm_bo_unreserve(&nvbo->bo); |
| 296 | return ret; |
| 297 | } |
| 298 | |
| 299 | void |
| 300 | nouveau_bo_unmap(struct nouveau_bo *nvbo) |
| 301 | { |
Ben Skeggs | 9d59e8a | 2010-08-27 13:04:41 +1000 | [diff] [blame] | 302 | if (nvbo) |
| 303 | ttm_bo_kunmap(&nvbo->kmap); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 304 | } |
| 305 | |
Ben Skeggs | 7a45d76 | 2010-11-22 08:50:27 +1000 | [diff] [blame] | 306 | int |
| 307 | nouveau_bo_validate(struct nouveau_bo *nvbo, bool interruptible, |
| 308 | bool no_wait_reserve, bool no_wait_gpu) |
| 309 | { |
| 310 | int ret; |
| 311 | |
| 312 | ret = ttm_bo_validate(&nvbo->bo, &nvbo->placement, interruptible, |
| 313 | no_wait_reserve, no_wait_gpu); |
| 314 | if (ret) |
| 315 | return ret; |
| 316 | |
Ben Skeggs | 4c13614 | 2010-11-15 11:54:21 +1000 | [diff] [blame] | 317 | if (nvbo->vma.node) { |
| 318 | if (nvbo->bo.mem.mem_type == TTM_PL_VRAM) |
| 319 | nvbo->bo.offset = nvbo->vma.offset; |
| 320 | } |
| 321 | |
Ben Skeggs | 7a45d76 | 2010-11-22 08:50:27 +1000 | [diff] [blame] | 322 | return 0; |
| 323 | } |
| 324 | |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 325 | u16 |
| 326 | nouveau_bo_rd16(struct nouveau_bo *nvbo, unsigned index) |
| 327 | { |
| 328 | bool is_iomem; |
| 329 | u16 *mem = ttm_kmap_obj_virtual(&nvbo->kmap, &is_iomem); |
| 330 | mem = &mem[index]; |
| 331 | if (is_iomem) |
| 332 | return ioread16_native((void __force __iomem *)mem); |
| 333 | else |
| 334 | return *mem; |
| 335 | } |
| 336 | |
| 337 | void |
| 338 | nouveau_bo_wr16(struct nouveau_bo *nvbo, unsigned index, u16 val) |
| 339 | { |
| 340 | bool is_iomem; |
| 341 | u16 *mem = ttm_kmap_obj_virtual(&nvbo->kmap, &is_iomem); |
| 342 | mem = &mem[index]; |
| 343 | if (is_iomem) |
| 344 | iowrite16_native(val, (void __force __iomem *)mem); |
| 345 | else |
| 346 | *mem = val; |
| 347 | } |
| 348 | |
| 349 | u32 |
| 350 | nouveau_bo_rd32(struct nouveau_bo *nvbo, unsigned index) |
| 351 | { |
| 352 | bool is_iomem; |
| 353 | u32 *mem = ttm_kmap_obj_virtual(&nvbo->kmap, &is_iomem); |
| 354 | mem = &mem[index]; |
| 355 | if (is_iomem) |
| 356 | return ioread32_native((void __force __iomem *)mem); |
| 357 | else |
| 358 | return *mem; |
| 359 | } |
| 360 | |
| 361 | void |
| 362 | nouveau_bo_wr32(struct nouveau_bo *nvbo, unsigned index, u32 val) |
| 363 | { |
| 364 | bool is_iomem; |
| 365 | u32 *mem = ttm_kmap_obj_virtual(&nvbo->kmap, &is_iomem); |
| 366 | mem = &mem[index]; |
| 367 | if (is_iomem) |
| 368 | iowrite32_native(val, (void __force __iomem *)mem); |
| 369 | else |
| 370 | *mem = val; |
| 371 | } |
| 372 | |
| 373 | static struct ttm_backend * |
| 374 | nouveau_bo_create_ttm_backend_entry(struct ttm_bo_device *bdev) |
| 375 | { |
| 376 | struct drm_nouveau_private *dev_priv = nouveau_bdev(bdev); |
| 377 | struct drm_device *dev = dev_priv->dev; |
| 378 | |
| 379 | switch (dev_priv->gart_info.type) { |
Ben Skeggs | b694dfb | 2009-12-15 10:38:32 +1000 | [diff] [blame] | 380 | #if __OS_HAS_AGP |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 381 | case NOUVEAU_GART_AGP: |
| 382 | return ttm_agp_backend_init(bdev, dev->agp->bridge); |
Ben Skeggs | b694dfb | 2009-12-15 10:38:32 +1000 | [diff] [blame] | 383 | #endif |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 384 | case NOUVEAU_GART_SGDMA: |
| 385 | return nouveau_sgdma_init_ttm(dev); |
| 386 | default: |
| 387 | NV_ERROR(dev, "Unknown GART type %d\n", |
| 388 | dev_priv->gart_info.type); |
| 389 | break; |
| 390 | } |
| 391 | |
| 392 | return NULL; |
| 393 | } |
| 394 | |
| 395 | static int |
| 396 | nouveau_bo_invalidate_caches(struct ttm_bo_device *bdev, uint32_t flags) |
| 397 | { |
| 398 | /* We'll do this from user space. */ |
| 399 | return 0; |
| 400 | } |
| 401 | |
| 402 | static int |
| 403 | nouveau_bo_init_mem_type(struct ttm_bo_device *bdev, uint32_t type, |
| 404 | struct ttm_mem_type_manager *man) |
| 405 | { |
| 406 | struct drm_nouveau_private *dev_priv = nouveau_bdev(bdev); |
| 407 | struct drm_device *dev = dev_priv->dev; |
| 408 | |
| 409 | switch (type) { |
| 410 | case TTM_PL_SYSTEM: |
| 411 | man->flags = TTM_MEMTYPE_FLAG_MAPPABLE; |
| 412 | man->available_caching = TTM_PL_MASK_CACHING; |
| 413 | man->default_caching = TTM_PL_FLAG_CACHED; |
| 414 | break; |
| 415 | case TTM_PL_VRAM: |
Ben Skeggs | f869ef8 | 2010-11-15 11:53:16 +1000 | [diff] [blame] | 416 | if (dev_priv->card_type == NV_50) { |
Ben Skeggs | 573a2a3 | 2010-08-25 15:26:04 +1000 | [diff] [blame] | 417 | man->func = &nouveau_vram_manager; |
Ben Skeggs | f869ef8 | 2010-11-15 11:53:16 +1000 | [diff] [blame] | 418 | man->io_reserve_fastpath = false; |
| 419 | man->use_io_reserve_lru = true; |
| 420 | } else { |
Ben Skeggs | 573a2a3 | 2010-08-25 15:26:04 +1000 | [diff] [blame] | 421 | man->func = &ttm_bo_manager_func; |
Ben Skeggs | f869ef8 | 2010-11-15 11:53:16 +1000 | [diff] [blame] | 422 | } |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 423 | man->flags = TTM_MEMTYPE_FLAG_FIXED | |
Jerome Glisse | f32f02f | 2010-04-09 14:39:25 +0200 | [diff] [blame] | 424 | TTM_MEMTYPE_FLAG_MAPPABLE; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 425 | man->available_caching = TTM_PL_FLAG_UNCACHED | |
| 426 | TTM_PL_FLAG_WC; |
| 427 | man->default_caching = TTM_PL_FLAG_WC; |
Ben Skeggs | 4c13614 | 2010-11-15 11:54:21 +1000 | [diff] [blame] | 428 | man->gpu_offset = 0; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 429 | break; |
| 430 | case TTM_PL_TT: |
Ben Skeggs | d961db7 | 2010-08-05 10:48:18 +1000 | [diff] [blame] | 431 | man->func = &ttm_bo_manager_func; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 432 | switch (dev_priv->gart_info.type) { |
| 433 | case NOUVEAU_GART_AGP: |
Jerome Glisse | f32f02f | 2010-04-09 14:39:25 +0200 | [diff] [blame] | 434 | man->flags = TTM_MEMTYPE_FLAG_MAPPABLE; |
Francisco Jerez | a3d487e | 2010-11-20 22:11:22 +0100 | [diff] [blame] | 435 | man->available_caching = TTM_PL_FLAG_UNCACHED | |
| 436 | TTM_PL_FLAG_WC; |
| 437 | man->default_caching = TTM_PL_FLAG_WC; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 438 | break; |
| 439 | case NOUVEAU_GART_SGDMA: |
| 440 | man->flags = TTM_MEMTYPE_FLAG_MAPPABLE | |
| 441 | TTM_MEMTYPE_FLAG_CMA; |
| 442 | man->available_caching = TTM_PL_MASK_CACHING; |
| 443 | man->default_caching = TTM_PL_FLAG_CACHED; |
| 444 | break; |
| 445 | default: |
| 446 | NV_ERROR(dev, "Unknown GART type: %d\n", |
| 447 | dev_priv->gart_info.type); |
| 448 | return -EINVAL; |
| 449 | } |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 450 | man->gpu_offset = dev_priv->vm_gart_base; |
| 451 | break; |
| 452 | default: |
| 453 | NV_ERROR(dev, "Unsupported memory type %u\n", (unsigned)type); |
| 454 | return -EINVAL; |
| 455 | } |
| 456 | return 0; |
| 457 | } |
| 458 | |
| 459 | static void |
| 460 | nouveau_bo_evict_flags(struct ttm_buffer_object *bo, struct ttm_placement *pl) |
| 461 | { |
| 462 | struct nouveau_bo *nvbo = nouveau_bo(bo); |
| 463 | |
| 464 | switch (bo->mem.mem_type) { |
Francisco Jerez | 22fbd53 | 2009-12-11 18:40:17 +0100 | [diff] [blame] | 465 | case TTM_PL_VRAM: |
Francisco Jerez | 78ad0f7 | 2010-03-18 13:07:47 +0100 | [diff] [blame] | 466 | nouveau_bo_placement_set(nvbo, TTM_PL_FLAG_TT, |
| 467 | TTM_PL_FLAG_SYSTEM); |
Francisco Jerez | 22fbd53 | 2009-12-11 18:40:17 +0100 | [diff] [blame] | 468 | break; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 469 | default: |
Francisco Jerez | 78ad0f7 | 2010-03-18 13:07:47 +0100 | [diff] [blame] | 470 | nouveau_bo_placement_set(nvbo, TTM_PL_FLAG_SYSTEM, 0); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 471 | break; |
| 472 | } |
Francisco Jerez | 22fbd53 | 2009-12-11 18:40:17 +0100 | [diff] [blame] | 473 | |
| 474 | *pl = nvbo->placement; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 475 | } |
| 476 | |
| 477 | |
| 478 | /* GPU-assisted copy using NV_MEMORY_TO_MEMORY_FORMAT, can access |
| 479 | * TTM_PL_{VRAM,TT} directly. |
| 480 | */ |
Francisco Jerez | a0af9ad | 2009-12-11 16:51:09 +0100 | [diff] [blame] | 481 | |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 482 | static int |
| 483 | nouveau_bo_move_accel_cleanup(struct nouveau_channel *chan, |
Jerome Glisse | 9d87fa2 | 2010-04-07 10:21:19 +0000 | [diff] [blame] | 484 | struct nouveau_bo *nvbo, bool evict, |
| 485 | bool no_wait_reserve, bool no_wait_gpu, |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 486 | struct ttm_mem_reg *new_mem) |
| 487 | { |
| 488 | struct nouveau_fence *fence = NULL; |
| 489 | int ret; |
| 490 | |
| 491 | ret = nouveau_fence_new(chan, &fence, true); |
| 492 | if (ret) |
| 493 | return ret; |
| 494 | |
Francisco Jerez | 6479881 | 2010-09-21 19:02:01 +0200 | [diff] [blame] | 495 | ret = ttm_bo_move_accel_cleanup(&nvbo->bo, fence, NULL, evict, |
Francisco Jerez | 311ab69 | 2010-07-04 12:54:23 +0200 | [diff] [blame] | 496 | no_wait_reserve, no_wait_gpu, new_mem); |
Marcin Slusarz | 382d62e | 2010-10-20 21:50:24 +0200 | [diff] [blame] | 497 | nouveau_fence_unref(&fence); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 498 | return ret; |
| 499 | } |
| 500 | |
| 501 | static inline uint32_t |
Ben Skeggs | f1ab0cc | 2010-08-26 11:32:01 +1000 | [diff] [blame] | 502 | nouveau_bo_mem_ctxdma(struct ttm_buffer_object *bo, |
| 503 | struct nouveau_channel *chan, struct ttm_mem_reg *mem) |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 504 | { |
Ben Skeggs | f1ab0cc | 2010-08-26 11:32:01 +1000 | [diff] [blame] | 505 | struct nouveau_bo *nvbo = nouveau_bo(bo); |
| 506 | |
| 507 | if (nvbo->no_vm) { |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 508 | if (mem->mem_type == TTM_PL_TT) |
| 509 | return NvDmaGART; |
| 510 | return NvDmaVRAM; |
| 511 | } |
| 512 | |
| 513 | if (mem->mem_type == TTM_PL_TT) |
| 514 | return chan->gart_handle; |
| 515 | return chan->vram_handle; |
| 516 | } |
| 517 | |
| 518 | static int |
Ben Skeggs | f1ab0cc | 2010-08-26 11:32:01 +1000 | [diff] [blame] | 519 | nv50_bo_move_m2mf(struct nouveau_channel *chan, struct ttm_buffer_object *bo, |
| 520 | struct ttm_mem_reg *old_mem, struct ttm_mem_reg *new_mem) |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 521 | { |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 522 | struct drm_nouveau_private *dev_priv = nouveau_bdev(bo->bdev); |
Ben Skeggs | f1ab0cc | 2010-08-26 11:32:01 +1000 | [diff] [blame] | 523 | struct nouveau_bo *nvbo = nouveau_bo(bo); |
| 524 | u64 length = (new_mem->num_pages << PAGE_SHIFT); |
| 525 | u64 src_offset, dst_offset; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 526 | int ret; |
| 527 | |
Ben Skeggs | d961db7 | 2010-08-05 10:48:18 +1000 | [diff] [blame] | 528 | src_offset = old_mem->start << PAGE_SHIFT; |
| 529 | dst_offset = new_mem->start << PAGE_SHIFT; |
Ben Skeggs | f1ab0cc | 2010-08-26 11:32:01 +1000 | [diff] [blame] | 530 | if (!nvbo->no_vm) { |
| 531 | if (old_mem->mem_type == TTM_PL_VRAM) |
Ben Skeggs | 4c13614 | 2010-11-15 11:54:21 +1000 | [diff] [blame] | 532 | src_offset = nvbo->vma.offset; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 533 | else |
Ben Skeggs | f1ab0cc | 2010-08-26 11:32:01 +1000 | [diff] [blame] | 534 | src_offset += dev_priv->vm_gart_base; |
| 535 | |
| 536 | if (new_mem->mem_type == TTM_PL_VRAM) |
Ben Skeggs | 4c13614 | 2010-11-15 11:54:21 +1000 | [diff] [blame] | 537 | dst_offset = nvbo->vma.offset; |
Ben Skeggs | f1ab0cc | 2010-08-26 11:32:01 +1000 | [diff] [blame] | 538 | else |
| 539 | dst_offset += dev_priv->vm_gart_base; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 540 | } |
| 541 | |
| 542 | ret = RING_SPACE(chan, 3); |
| 543 | if (ret) |
| 544 | return ret; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 545 | |
Ben Skeggs | f1ab0cc | 2010-08-26 11:32:01 +1000 | [diff] [blame] | 546 | BEGIN_RING(chan, NvSubM2MF, 0x0184, 2); |
| 547 | OUT_RING (chan, nouveau_bo_mem_ctxdma(bo, chan, old_mem)); |
| 548 | OUT_RING (chan, nouveau_bo_mem_ctxdma(bo, chan, new_mem)); |
| 549 | |
| 550 | while (length) { |
| 551 | u32 amount, stride, height; |
| 552 | |
Ben Skeggs | 5220b3c | 2010-09-23 15:21:17 +1000 | [diff] [blame] | 553 | amount = min(length, (u64)(4 * 1024 * 1024)); |
| 554 | stride = 16 * 4; |
Ben Skeggs | f1ab0cc | 2010-08-26 11:32:01 +1000 | [diff] [blame] | 555 | height = amount / stride; |
| 556 | |
Francisco Jerez | f13b326 | 2010-10-10 06:01:08 +0200 | [diff] [blame] | 557 | if (new_mem->mem_type == TTM_PL_VRAM && |
| 558 | nouveau_bo_tile_layout(nvbo)) { |
Ben Skeggs | f1ab0cc | 2010-08-26 11:32:01 +1000 | [diff] [blame] | 559 | ret = RING_SPACE(chan, 8); |
| 560 | if (ret) |
| 561 | return ret; |
| 562 | |
| 563 | BEGIN_RING(chan, NvSubM2MF, 0x0200, 7); |
| 564 | OUT_RING (chan, 0); |
Ben Skeggs | 5220b3c | 2010-09-23 15:21:17 +1000 | [diff] [blame] | 565 | OUT_RING (chan, 0); |
Ben Skeggs | f1ab0cc | 2010-08-26 11:32:01 +1000 | [diff] [blame] | 566 | OUT_RING (chan, stride); |
| 567 | OUT_RING (chan, height); |
| 568 | OUT_RING (chan, 1); |
| 569 | OUT_RING (chan, 0); |
| 570 | OUT_RING (chan, 0); |
| 571 | } else { |
| 572 | ret = RING_SPACE(chan, 2); |
| 573 | if (ret) |
| 574 | return ret; |
| 575 | |
| 576 | BEGIN_RING(chan, NvSubM2MF, 0x0200, 1); |
| 577 | OUT_RING (chan, 1); |
| 578 | } |
Francisco Jerez | f13b326 | 2010-10-10 06:01:08 +0200 | [diff] [blame] | 579 | if (old_mem->mem_type == TTM_PL_VRAM && |
| 580 | nouveau_bo_tile_layout(nvbo)) { |
Ben Skeggs | f1ab0cc | 2010-08-26 11:32:01 +1000 | [diff] [blame] | 581 | ret = RING_SPACE(chan, 8); |
| 582 | if (ret) |
| 583 | return ret; |
| 584 | |
| 585 | BEGIN_RING(chan, NvSubM2MF, 0x021c, 7); |
| 586 | OUT_RING (chan, 0); |
Ben Skeggs | 5220b3c | 2010-09-23 15:21:17 +1000 | [diff] [blame] | 587 | OUT_RING (chan, 0); |
Ben Skeggs | f1ab0cc | 2010-08-26 11:32:01 +1000 | [diff] [blame] | 588 | OUT_RING (chan, stride); |
| 589 | OUT_RING (chan, height); |
| 590 | OUT_RING (chan, 1); |
| 591 | OUT_RING (chan, 0); |
| 592 | OUT_RING (chan, 0); |
| 593 | } else { |
| 594 | ret = RING_SPACE(chan, 2); |
| 595 | if (ret) |
| 596 | return ret; |
| 597 | |
| 598 | BEGIN_RING(chan, NvSubM2MF, 0x021c, 1); |
| 599 | OUT_RING (chan, 1); |
| 600 | } |
| 601 | |
| 602 | ret = RING_SPACE(chan, 14); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 603 | if (ret) |
| 604 | return ret; |
Ben Skeggs | f1ab0cc | 2010-08-26 11:32:01 +1000 | [diff] [blame] | 605 | |
| 606 | BEGIN_RING(chan, NvSubM2MF, 0x0238, 2); |
| 607 | OUT_RING (chan, upper_32_bits(src_offset)); |
| 608 | OUT_RING (chan, upper_32_bits(dst_offset)); |
| 609 | BEGIN_RING(chan, NvSubM2MF, 0x030c, 8); |
| 610 | OUT_RING (chan, lower_32_bits(src_offset)); |
| 611 | OUT_RING (chan, lower_32_bits(dst_offset)); |
| 612 | OUT_RING (chan, stride); |
| 613 | OUT_RING (chan, stride); |
| 614 | OUT_RING (chan, stride); |
| 615 | OUT_RING (chan, height); |
| 616 | OUT_RING (chan, 0x00000101); |
| 617 | OUT_RING (chan, 0x00000000); |
| 618 | BEGIN_RING(chan, NvSubM2MF, NV_MEMORY_TO_MEMORY_FORMAT_NOP, 1); |
| 619 | OUT_RING (chan, 0); |
| 620 | |
| 621 | length -= amount; |
| 622 | src_offset += amount; |
| 623 | dst_offset += amount; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 624 | } |
| 625 | |
Ben Skeggs | f1ab0cc | 2010-08-26 11:32:01 +1000 | [diff] [blame] | 626 | return 0; |
| 627 | } |
| 628 | |
| 629 | static int |
| 630 | nv04_bo_move_m2mf(struct nouveau_channel *chan, struct ttm_buffer_object *bo, |
| 631 | struct ttm_mem_reg *old_mem, struct ttm_mem_reg *new_mem) |
| 632 | { |
Ben Skeggs | d961db7 | 2010-08-05 10:48:18 +1000 | [diff] [blame] | 633 | u32 src_offset = old_mem->start << PAGE_SHIFT; |
| 634 | u32 dst_offset = new_mem->start << PAGE_SHIFT; |
Ben Skeggs | f1ab0cc | 2010-08-26 11:32:01 +1000 | [diff] [blame] | 635 | u32 page_count = new_mem->num_pages; |
| 636 | int ret; |
| 637 | |
| 638 | ret = RING_SPACE(chan, 3); |
| 639 | if (ret) |
| 640 | return ret; |
| 641 | |
| 642 | BEGIN_RING(chan, NvSubM2MF, NV_MEMORY_TO_MEMORY_FORMAT_DMA_SOURCE, 2); |
| 643 | OUT_RING (chan, nouveau_bo_mem_ctxdma(bo, chan, old_mem)); |
| 644 | OUT_RING (chan, nouveau_bo_mem_ctxdma(bo, chan, new_mem)); |
| 645 | |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 646 | page_count = new_mem->num_pages; |
| 647 | while (page_count) { |
| 648 | int line_count = (page_count > 2047) ? 2047 : page_count; |
| 649 | |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 650 | ret = RING_SPACE(chan, 11); |
| 651 | if (ret) |
| 652 | return ret; |
Ben Skeggs | f1ab0cc | 2010-08-26 11:32:01 +1000 | [diff] [blame] | 653 | |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 654 | BEGIN_RING(chan, NvSubM2MF, |
| 655 | NV_MEMORY_TO_MEMORY_FORMAT_OFFSET_IN, 8); |
Ben Skeggs | f1ab0cc | 2010-08-26 11:32:01 +1000 | [diff] [blame] | 656 | OUT_RING (chan, src_offset); |
| 657 | OUT_RING (chan, dst_offset); |
| 658 | OUT_RING (chan, PAGE_SIZE); /* src_pitch */ |
| 659 | OUT_RING (chan, PAGE_SIZE); /* dst_pitch */ |
| 660 | OUT_RING (chan, PAGE_SIZE); /* line_length */ |
| 661 | OUT_RING (chan, line_count); |
| 662 | OUT_RING (chan, 0x00000101); |
| 663 | OUT_RING (chan, 0x00000000); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 664 | BEGIN_RING(chan, NvSubM2MF, NV_MEMORY_TO_MEMORY_FORMAT_NOP, 1); |
Ben Skeggs | f1ab0cc | 2010-08-26 11:32:01 +1000 | [diff] [blame] | 665 | OUT_RING (chan, 0); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 666 | |
| 667 | page_count -= line_count; |
| 668 | src_offset += (PAGE_SIZE * line_count); |
| 669 | dst_offset += (PAGE_SIZE * line_count); |
| 670 | } |
| 671 | |
Ben Skeggs | f1ab0cc | 2010-08-26 11:32:01 +1000 | [diff] [blame] | 672 | return 0; |
| 673 | } |
| 674 | |
| 675 | static int |
| 676 | nouveau_bo_move_m2mf(struct ttm_buffer_object *bo, int evict, bool intr, |
| 677 | bool no_wait_reserve, bool no_wait_gpu, |
| 678 | struct ttm_mem_reg *new_mem) |
| 679 | { |
| 680 | struct drm_nouveau_private *dev_priv = nouveau_bdev(bo->bdev); |
| 681 | struct nouveau_bo *nvbo = nouveau_bo(bo); |
| 682 | struct nouveau_channel *chan; |
| 683 | int ret; |
| 684 | |
| 685 | chan = nvbo->channel; |
Ben Skeggs | 6a6b73f | 2010-10-05 16:53:48 +1000 | [diff] [blame] | 686 | if (!chan || nvbo->no_vm) { |
Ben Skeggs | f1ab0cc | 2010-08-26 11:32:01 +1000 | [diff] [blame] | 687 | chan = dev_priv->channel; |
Francisco Jerez | e419cf0 | 2010-10-25 23:38:59 +0200 | [diff] [blame] | 688 | mutex_lock_nested(&chan->mutex, NOUVEAU_KCHANNEL_MUTEX); |
Ben Skeggs | 6a6b73f | 2010-10-05 16:53:48 +1000 | [diff] [blame] | 689 | } |
Ben Skeggs | f1ab0cc | 2010-08-26 11:32:01 +1000 | [diff] [blame] | 690 | |
| 691 | if (dev_priv->card_type < NV_50) |
| 692 | ret = nv04_bo_move_m2mf(chan, bo, &bo->mem, new_mem); |
| 693 | else |
| 694 | ret = nv50_bo_move_m2mf(chan, bo, &bo->mem, new_mem); |
Ben Skeggs | 6a6b73f | 2010-10-05 16:53:48 +1000 | [diff] [blame] | 695 | if (ret == 0) { |
| 696 | ret = nouveau_bo_move_accel_cleanup(chan, nvbo, evict, |
| 697 | no_wait_reserve, |
| 698 | no_wait_gpu, new_mem); |
| 699 | } |
Ben Skeggs | f1ab0cc | 2010-08-26 11:32:01 +1000 | [diff] [blame] | 700 | |
Ben Skeggs | 6a6b73f | 2010-10-05 16:53:48 +1000 | [diff] [blame] | 701 | if (chan == dev_priv->channel) |
| 702 | mutex_unlock(&chan->mutex); |
| 703 | return ret; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 704 | } |
| 705 | |
| 706 | static int |
| 707 | nouveau_bo_move_flipd(struct ttm_buffer_object *bo, bool evict, bool intr, |
Jerome Glisse | 9d87fa2 | 2010-04-07 10:21:19 +0000 | [diff] [blame] | 708 | bool no_wait_reserve, bool no_wait_gpu, |
| 709 | struct ttm_mem_reg *new_mem) |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 710 | { |
| 711 | u32 placement_memtype = TTM_PL_FLAG_TT | TTM_PL_MASK_CACHING; |
| 712 | struct ttm_placement placement; |
| 713 | struct ttm_mem_reg tmp_mem; |
| 714 | int ret; |
| 715 | |
| 716 | placement.fpfn = placement.lpfn = 0; |
| 717 | placement.num_placement = placement.num_busy_placement = 1; |
Francisco Jerez | 77e2b5e | 2009-12-16 19:05:00 +0100 | [diff] [blame] | 718 | placement.placement = placement.busy_placement = &placement_memtype; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 719 | |
| 720 | tmp_mem = *new_mem; |
| 721 | tmp_mem.mm_node = NULL; |
Jerome Glisse | 9d87fa2 | 2010-04-07 10:21:19 +0000 | [diff] [blame] | 722 | ret = ttm_bo_mem_space(bo, &placement, &tmp_mem, intr, no_wait_reserve, no_wait_gpu); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 723 | if (ret) |
| 724 | return ret; |
| 725 | |
| 726 | ret = ttm_tt_bind(bo->ttm, &tmp_mem); |
| 727 | if (ret) |
| 728 | goto out; |
| 729 | |
Jerome Glisse | 9d87fa2 | 2010-04-07 10:21:19 +0000 | [diff] [blame] | 730 | ret = nouveau_bo_move_m2mf(bo, true, intr, no_wait_reserve, no_wait_gpu, &tmp_mem); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 731 | if (ret) |
| 732 | goto out; |
| 733 | |
Jerome Glisse | 9d87fa2 | 2010-04-07 10:21:19 +0000 | [diff] [blame] | 734 | ret = ttm_bo_move_ttm(bo, evict, no_wait_reserve, no_wait_gpu, new_mem); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 735 | out: |
Ben Skeggs | 42311ff | 2010-08-04 12:07:08 +1000 | [diff] [blame] | 736 | ttm_bo_mem_put(bo, &tmp_mem); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 737 | return ret; |
| 738 | } |
| 739 | |
| 740 | static int |
| 741 | nouveau_bo_move_flips(struct ttm_buffer_object *bo, bool evict, bool intr, |
Jerome Glisse | 9d87fa2 | 2010-04-07 10:21:19 +0000 | [diff] [blame] | 742 | bool no_wait_reserve, bool no_wait_gpu, |
| 743 | struct ttm_mem_reg *new_mem) |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 744 | { |
| 745 | u32 placement_memtype = TTM_PL_FLAG_TT | TTM_PL_MASK_CACHING; |
| 746 | struct ttm_placement placement; |
| 747 | struct ttm_mem_reg tmp_mem; |
| 748 | int ret; |
| 749 | |
| 750 | placement.fpfn = placement.lpfn = 0; |
| 751 | placement.num_placement = placement.num_busy_placement = 1; |
Francisco Jerez | 77e2b5e | 2009-12-16 19:05:00 +0100 | [diff] [blame] | 752 | placement.placement = placement.busy_placement = &placement_memtype; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 753 | |
| 754 | tmp_mem = *new_mem; |
| 755 | tmp_mem.mm_node = NULL; |
Jerome Glisse | 9d87fa2 | 2010-04-07 10:21:19 +0000 | [diff] [blame] | 756 | ret = ttm_bo_mem_space(bo, &placement, &tmp_mem, intr, no_wait_reserve, no_wait_gpu); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 757 | if (ret) |
| 758 | return ret; |
| 759 | |
Jerome Glisse | 9d87fa2 | 2010-04-07 10:21:19 +0000 | [diff] [blame] | 760 | ret = ttm_bo_move_ttm(bo, evict, no_wait_reserve, no_wait_gpu, &tmp_mem); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 761 | if (ret) |
| 762 | goto out; |
| 763 | |
Jerome Glisse | 9d87fa2 | 2010-04-07 10:21:19 +0000 | [diff] [blame] | 764 | ret = nouveau_bo_move_m2mf(bo, evict, intr, no_wait_reserve, no_wait_gpu, new_mem); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 765 | if (ret) |
| 766 | goto out; |
| 767 | |
| 768 | out: |
Ben Skeggs | 42311ff | 2010-08-04 12:07:08 +1000 | [diff] [blame] | 769 | ttm_bo_mem_put(bo, &tmp_mem); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 770 | return ret; |
| 771 | } |
| 772 | |
| 773 | static int |
Francisco Jerez | a0af9ad | 2009-12-11 16:51:09 +0100 | [diff] [blame] | 774 | nouveau_bo_vm_bind(struct ttm_buffer_object *bo, struct ttm_mem_reg *new_mem, |
| 775 | struct nouveau_tile_reg **new_tile) |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 776 | { |
| 777 | struct drm_nouveau_private *dev_priv = nouveau_bdev(bo->bdev); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 778 | struct drm_device *dev = dev_priv->dev; |
Francisco Jerez | a0af9ad | 2009-12-11 16:51:09 +0100 | [diff] [blame] | 779 | struct nouveau_bo *nvbo = nouveau_bo(bo); |
| 780 | uint64_t offset; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 781 | |
Francisco Jerez | a0af9ad | 2009-12-11 16:51:09 +0100 | [diff] [blame] | 782 | if (nvbo->no_vm || new_mem->mem_type != TTM_PL_VRAM) { |
| 783 | /* Nothing to do. */ |
| 784 | *new_tile = NULL; |
| 785 | return 0; |
| 786 | } |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 787 | |
Ben Skeggs | d961db7 | 2010-08-05 10:48:18 +1000 | [diff] [blame] | 788 | offset = new_mem->start << PAGE_SHIFT; |
Francisco Jerez | a0af9ad | 2009-12-11 16:51:09 +0100 | [diff] [blame] | 789 | |
Ben Skeggs | 4c13614 | 2010-11-15 11:54:21 +1000 | [diff] [blame] | 790 | if (dev_priv->chan_vm) { |
| 791 | nouveau_vm_map(&nvbo->vma, new_mem->mm_node); |
Francisco Jerez | a0af9ad | 2009-12-11 16:51:09 +0100 | [diff] [blame] | 792 | } else if (dev_priv->card_type >= NV_10) { |
| 793 | *new_tile = nv10_mem_set_tiling(dev, offset, new_mem->size, |
Francisco Jerez | a5cf68b | 2010-10-24 16:14:41 +0200 | [diff] [blame] | 794 | nvbo->tile_mode, |
| 795 | nvbo->tile_flags); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 796 | } |
| 797 | |
Francisco Jerez | a0af9ad | 2009-12-11 16:51:09 +0100 | [diff] [blame] | 798 | return 0; |
| 799 | } |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 800 | |
Francisco Jerez | a0af9ad | 2009-12-11 16:51:09 +0100 | [diff] [blame] | 801 | static void |
| 802 | nouveau_bo_vm_cleanup(struct ttm_buffer_object *bo, |
| 803 | struct nouveau_tile_reg *new_tile, |
| 804 | struct nouveau_tile_reg **old_tile) |
| 805 | { |
| 806 | struct drm_nouveau_private *dev_priv = nouveau_bdev(bo->bdev); |
| 807 | struct drm_device *dev = dev_priv->dev; |
| 808 | |
| 809 | if (dev_priv->card_type >= NV_10 && |
| 810 | dev_priv->card_type < NV_50) { |
Francisco Jerez | a5cf68b | 2010-10-24 16:14:41 +0200 | [diff] [blame] | 811 | nv10_mem_put_tile_region(dev, *old_tile, bo->sync_obj); |
Francisco Jerez | a0af9ad | 2009-12-11 16:51:09 +0100 | [diff] [blame] | 812 | *old_tile = new_tile; |
| 813 | } |
| 814 | } |
| 815 | |
| 816 | static int |
| 817 | nouveau_bo_move(struct ttm_buffer_object *bo, bool evict, bool intr, |
Jerome Glisse | 9d87fa2 | 2010-04-07 10:21:19 +0000 | [diff] [blame] | 818 | bool no_wait_reserve, bool no_wait_gpu, |
| 819 | struct ttm_mem_reg *new_mem) |
Francisco Jerez | a0af9ad | 2009-12-11 16:51:09 +0100 | [diff] [blame] | 820 | { |
| 821 | struct drm_nouveau_private *dev_priv = nouveau_bdev(bo->bdev); |
| 822 | struct nouveau_bo *nvbo = nouveau_bo(bo); |
| 823 | struct ttm_mem_reg *old_mem = &bo->mem; |
| 824 | struct nouveau_tile_reg *new_tile = NULL; |
| 825 | int ret = 0; |
| 826 | |
| 827 | ret = nouveau_bo_vm_bind(bo, new_mem, &new_tile); |
| 828 | if (ret) |
| 829 | return ret; |
| 830 | |
Francisco Jerez | a0af9ad | 2009-12-11 16:51:09 +0100 | [diff] [blame] | 831 | /* Fake bo copy. */ |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 832 | if (old_mem->mem_type == TTM_PL_SYSTEM && !bo->ttm) { |
| 833 | BUG_ON(bo->mem.mm_node != NULL); |
| 834 | bo->mem = *new_mem; |
| 835 | new_mem->mm_node = NULL; |
Francisco Jerez | a0af9ad | 2009-12-11 16:51:09 +0100 | [diff] [blame] | 836 | goto out; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 837 | } |
| 838 | |
Ben Skeggs | b8a6a80 | 2010-08-27 11:55:43 +1000 | [diff] [blame] | 839 | /* Software copy if the card isn't up and running yet. */ |
| 840 | if (!dev_priv->channel) { |
| 841 | ret = ttm_bo_move_memcpy(bo, evict, no_wait_reserve, no_wait_gpu, new_mem); |
| 842 | goto out; |
| 843 | } |
| 844 | |
Francisco Jerez | a0af9ad | 2009-12-11 16:51:09 +0100 | [diff] [blame] | 845 | /* Hardware assisted copy. */ |
| 846 | if (new_mem->mem_type == TTM_PL_SYSTEM) |
Jerome Glisse | 9d87fa2 | 2010-04-07 10:21:19 +0000 | [diff] [blame] | 847 | ret = nouveau_bo_move_flipd(bo, evict, intr, no_wait_reserve, no_wait_gpu, new_mem); |
Francisco Jerez | a0af9ad | 2009-12-11 16:51:09 +0100 | [diff] [blame] | 848 | else if (old_mem->mem_type == TTM_PL_SYSTEM) |
Jerome Glisse | 9d87fa2 | 2010-04-07 10:21:19 +0000 | [diff] [blame] | 849 | ret = nouveau_bo_move_flips(bo, evict, intr, no_wait_reserve, no_wait_gpu, new_mem); |
Francisco Jerez | a0af9ad | 2009-12-11 16:51:09 +0100 | [diff] [blame] | 850 | else |
Jerome Glisse | 9d87fa2 | 2010-04-07 10:21:19 +0000 | [diff] [blame] | 851 | ret = nouveau_bo_move_m2mf(bo, evict, intr, no_wait_reserve, no_wait_gpu, new_mem); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 852 | |
Francisco Jerez | a0af9ad | 2009-12-11 16:51:09 +0100 | [diff] [blame] | 853 | if (!ret) |
| 854 | goto out; |
| 855 | |
| 856 | /* Fallback to software copy. */ |
Jerome Glisse | 9d87fa2 | 2010-04-07 10:21:19 +0000 | [diff] [blame] | 857 | ret = ttm_bo_move_memcpy(bo, evict, no_wait_reserve, no_wait_gpu, new_mem); |
Francisco Jerez | a0af9ad | 2009-12-11 16:51:09 +0100 | [diff] [blame] | 858 | |
| 859 | out: |
| 860 | if (ret) |
| 861 | nouveau_bo_vm_cleanup(bo, NULL, &new_tile); |
| 862 | else |
| 863 | nouveau_bo_vm_cleanup(bo, new_tile, &nvbo->tile); |
| 864 | |
| 865 | return ret; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 866 | } |
| 867 | |
| 868 | static int |
| 869 | nouveau_bo_verify_access(struct ttm_buffer_object *bo, struct file *filp) |
| 870 | { |
| 871 | return 0; |
| 872 | } |
| 873 | |
Jerome Glisse | f32f02f | 2010-04-09 14:39:25 +0200 | [diff] [blame] | 874 | static int |
| 875 | nouveau_ttm_io_mem_reserve(struct ttm_bo_device *bdev, struct ttm_mem_reg *mem) |
| 876 | { |
| 877 | struct ttm_mem_type_manager *man = &bdev->man[mem->mem_type]; |
| 878 | struct drm_nouveau_private *dev_priv = nouveau_bdev(bdev); |
| 879 | struct drm_device *dev = dev_priv->dev; |
Ben Skeggs | f869ef8 | 2010-11-15 11:53:16 +1000 | [diff] [blame] | 880 | int ret; |
Jerome Glisse | f32f02f | 2010-04-09 14:39:25 +0200 | [diff] [blame] | 881 | |
| 882 | mem->bus.addr = NULL; |
| 883 | mem->bus.offset = 0; |
| 884 | mem->bus.size = mem->num_pages << PAGE_SHIFT; |
| 885 | mem->bus.base = 0; |
| 886 | mem->bus.is_iomem = false; |
| 887 | if (!(man->flags & TTM_MEMTYPE_FLAG_MAPPABLE)) |
| 888 | return -EINVAL; |
| 889 | switch (mem->mem_type) { |
| 890 | case TTM_PL_SYSTEM: |
| 891 | /* System memory */ |
| 892 | return 0; |
| 893 | case TTM_PL_TT: |
| 894 | #if __OS_HAS_AGP |
| 895 | if (dev_priv->gart_info.type == NOUVEAU_GART_AGP) { |
Ben Skeggs | d961db7 | 2010-08-05 10:48:18 +1000 | [diff] [blame] | 896 | mem->bus.offset = mem->start << PAGE_SHIFT; |
Jerome Glisse | f32f02f | 2010-04-09 14:39:25 +0200 | [diff] [blame] | 897 | mem->bus.base = dev_priv->gart_info.aper_base; |
| 898 | mem->bus.is_iomem = true; |
| 899 | } |
| 900 | #endif |
| 901 | break; |
| 902 | case TTM_PL_VRAM: |
Ben Skeggs | f869ef8 | 2010-11-15 11:53:16 +1000 | [diff] [blame] | 903 | { |
| 904 | struct nouveau_vram *vram = mem->mm_node; |
| 905 | |
| 906 | if (!dev_priv->bar1_vm) { |
| 907 | mem->bus.offset = mem->start << PAGE_SHIFT; |
| 908 | mem->bus.base = pci_resource_start(dev->pdev, 1); |
| 909 | mem->bus.is_iomem = true; |
| 910 | break; |
| 911 | } |
| 912 | |
| 913 | ret = nouveau_vm_get(dev_priv->bar1_vm, mem->bus.size, 12, |
| 914 | NV_MEM_ACCESS_RW, &vram->bar_vma); |
| 915 | if (ret) |
| 916 | return ret; |
| 917 | |
| 918 | nouveau_vm_map(&vram->bar_vma, vram); |
| 919 | if (ret) { |
| 920 | nouveau_vm_put(&vram->bar_vma); |
| 921 | return ret; |
| 922 | } |
| 923 | |
| 924 | mem->bus.offset = vram->bar_vma.offset; |
| 925 | mem->bus.offset -= 0x0020000000ULL; |
Jordan Crouse | 01d73a6 | 2010-05-27 13:40:24 -0600 | [diff] [blame] | 926 | mem->bus.base = pci_resource_start(dev->pdev, 1); |
Jerome Glisse | f32f02f | 2010-04-09 14:39:25 +0200 | [diff] [blame] | 927 | mem->bus.is_iomem = true; |
Ben Skeggs | f869ef8 | 2010-11-15 11:53:16 +1000 | [diff] [blame] | 928 | } |
Jerome Glisse | f32f02f | 2010-04-09 14:39:25 +0200 | [diff] [blame] | 929 | break; |
| 930 | default: |
| 931 | return -EINVAL; |
| 932 | } |
| 933 | return 0; |
| 934 | } |
| 935 | |
| 936 | static void |
| 937 | nouveau_ttm_io_mem_free(struct ttm_bo_device *bdev, struct ttm_mem_reg *mem) |
| 938 | { |
Ben Skeggs | f869ef8 | 2010-11-15 11:53:16 +1000 | [diff] [blame] | 939 | struct drm_nouveau_private *dev_priv = nouveau_bdev(bdev); |
| 940 | struct nouveau_vram *vram = mem->mm_node; |
| 941 | |
| 942 | if (!dev_priv->bar1_vm || mem->mem_type != TTM_PL_VRAM) |
| 943 | return; |
| 944 | |
| 945 | if (!vram->bar_vma.node) |
| 946 | return; |
| 947 | |
| 948 | nouveau_vm_unmap(&vram->bar_vma); |
| 949 | nouveau_vm_put(&vram->bar_vma); |
Jerome Glisse | f32f02f | 2010-04-09 14:39:25 +0200 | [diff] [blame] | 950 | } |
| 951 | |
| 952 | static int |
| 953 | nouveau_ttm_fault_reserve_notify(struct ttm_buffer_object *bo) |
| 954 | { |
Ben Skeggs | e1429b4 | 2010-09-10 11:12:25 +1000 | [diff] [blame] | 955 | struct drm_nouveau_private *dev_priv = nouveau_bdev(bo->bdev); |
| 956 | struct nouveau_bo *nvbo = nouveau_bo(bo); |
| 957 | |
| 958 | /* as long as the bo isn't in vram, and isn't tiled, we've got |
| 959 | * nothing to do here. |
| 960 | */ |
| 961 | if (bo->mem.mem_type != TTM_PL_VRAM) { |
Francisco Jerez | f13b326 | 2010-10-10 06:01:08 +0200 | [diff] [blame] | 962 | if (dev_priv->card_type < NV_50 || |
| 963 | !nouveau_bo_tile_layout(nvbo)) |
Ben Skeggs | e1429b4 | 2010-09-10 11:12:25 +1000 | [diff] [blame] | 964 | return 0; |
| 965 | } |
| 966 | |
| 967 | /* make sure bo is in mappable vram */ |
Ben Skeggs | d961db7 | 2010-08-05 10:48:18 +1000 | [diff] [blame] | 968 | if (bo->mem.start + bo->mem.num_pages < dev_priv->fb_mappable_pages) |
Ben Skeggs | e1429b4 | 2010-09-10 11:12:25 +1000 | [diff] [blame] | 969 | return 0; |
| 970 | |
| 971 | |
| 972 | nvbo->placement.fpfn = 0; |
| 973 | nvbo->placement.lpfn = dev_priv->fb_mappable_pages; |
| 974 | nouveau_bo_placement_set(nvbo, TTM_PL_VRAM, 0); |
Ben Skeggs | 7a45d76 | 2010-11-22 08:50:27 +1000 | [diff] [blame] | 975 | return nouveau_bo_validate(nvbo, false, true, false); |
Jerome Glisse | f32f02f | 2010-04-09 14:39:25 +0200 | [diff] [blame] | 976 | } |
| 977 | |
Francisco Jerez | 332b242 | 2010-10-20 23:35:40 +0200 | [diff] [blame] | 978 | void |
| 979 | nouveau_bo_fence(struct nouveau_bo *nvbo, struct nouveau_fence *fence) |
| 980 | { |
Francisco Jerez | 23c45e8 | 2010-10-28 23:10:29 +0200 | [diff] [blame] | 981 | struct nouveau_fence *old_fence; |
Francisco Jerez | 332b242 | 2010-10-20 23:35:40 +0200 | [diff] [blame] | 982 | |
| 983 | if (likely(fence)) |
Francisco Jerez | 23c45e8 | 2010-10-28 23:10:29 +0200 | [diff] [blame] | 984 | nouveau_fence_ref(fence); |
Francisco Jerez | 332b242 | 2010-10-20 23:35:40 +0200 | [diff] [blame] | 985 | |
Francisco Jerez | 23c45e8 | 2010-10-28 23:10:29 +0200 | [diff] [blame] | 986 | spin_lock(&nvbo->bo.bdev->fence_lock); |
| 987 | old_fence = nvbo->bo.sync_obj; |
| 988 | nvbo->bo.sync_obj = fence; |
Francisco Jerez | 332b242 | 2010-10-20 23:35:40 +0200 | [diff] [blame] | 989 | spin_unlock(&nvbo->bo.bdev->fence_lock); |
Francisco Jerez | 23c45e8 | 2010-10-28 23:10:29 +0200 | [diff] [blame] | 990 | |
| 991 | nouveau_fence_unref(&old_fence); |
Francisco Jerez | 332b242 | 2010-10-20 23:35:40 +0200 | [diff] [blame] | 992 | } |
| 993 | |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 994 | struct ttm_bo_driver nouveau_bo_driver = { |
| 995 | .create_ttm_backend_entry = nouveau_bo_create_ttm_backend_entry, |
| 996 | .invalidate_caches = nouveau_bo_invalidate_caches, |
| 997 | .init_mem_type = nouveau_bo_init_mem_type, |
| 998 | .evict_flags = nouveau_bo_evict_flags, |
| 999 | .move = nouveau_bo_move, |
| 1000 | .verify_access = nouveau_bo_verify_access, |
Marcin Slusarz | 382d62e | 2010-10-20 21:50:24 +0200 | [diff] [blame] | 1001 | .sync_obj_signaled = __nouveau_fence_signalled, |
| 1002 | .sync_obj_wait = __nouveau_fence_wait, |
| 1003 | .sync_obj_flush = __nouveau_fence_flush, |
| 1004 | .sync_obj_unref = __nouveau_fence_unref, |
| 1005 | .sync_obj_ref = __nouveau_fence_ref, |
Jerome Glisse | f32f02f | 2010-04-09 14:39:25 +0200 | [diff] [blame] | 1006 | .fault_reserve_notify = &nouveau_ttm_fault_reserve_notify, |
| 1007 | .io_mem_reserve = &nouveau_ttm_io_mem_reserve, |
| 1008 | .io_mem_free = &nouveau_ttm_io_mem_free, |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 1009 | }; |
| 1010 | |