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" |
Jerome Glisse | b1e5f17 | 2011-11-02 23:59:28 -0400 | [diff] [blame] | 31 | #include "ttm/ttm_page_alloc.h" |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 32 | |
| 33 | #include "nouveau_drm.h" |
| 34 | #include "nouveau_drv.h" |
| 35 | #include "nouveau_dma.h" |
Ben Skeggs | f869ef8 | 2010-11-15 11:53:16 +1000 | [diff] [blame] | 36 | #include "nouveau_mm.h" |
| 37 | #include "nouveau_vm.h" |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 38 | |
Maarten Maathuis | a510604 | 2009-12-26 21:46:36 +0100 | [diff] [blame] | 39 | #include <linux/log2.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 40 | #include <linux/slab.h> |
Maarten Maathuis | a510604 | 2009-12-26 21:46:36 +0100 | [diff] [blame] | 41 | |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 42 | static void |
| 43 | nouveau_bo_del_ttm(struct ttm_buffer_object *bo) |
| 44 | { |
| 45 | struct drm_nouveau_private *dev_priv = nouveau_bdev(bo->bdev); |
Francisco Jerez | a0af9ad | 2009-12-11 16:51:09 +0100 | [diff] [blame] | 46 | struct drm_device *dev = dev_priv->dev; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 47 | struct nouveau_bo *nvbo = nouveau_bo(bo); |
| 48 | |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 49 | if (unlikely(nvbo->gem)) |
| 50 | DRM_ERROR("bo %p still attached to GEM object\n", bo); |
| 51 | |
Francisco Jerez | a5cf68b | 2010-10-24 16:14:41 +0200 | [diff] [blame] | 52 | nv10_mem_put_tile_region(dev, nvbo->tile, NULL); |
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 | db5c8e2 | 2011-02-10 13:41:01 +1000 | [diff] [blame] | 57 | nouveau_bo_fixup_align(struct nouveau_bo *nvbo, u32 flags, |
Ben Skeggs | f91bac5 | 2011-06-06 14:15:46 +1000 | [diff] [blame] | 58 | int *align, int *size) |
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 { |
Ben Skeggs | f91bac5 | 2011-06-06 14:15:46 +1000 | [diff] [blame] | 82 | *size = roundup(*size, (1 << nvbo->page_shift)); |
| 83 | *align = max((1 << nvbo->page_shift), *align); |
Francisco Jerez | a0af9ad | 2009-12-11 16:51:09 +0100 | [diff] [blame] | 84 | } |
| 85 | |
Maarten Maathuis | 1c7059e | 2009-12-25 18:51:17 +0100 | [diff] [blame] | 86 | *size = roundup(*size, PAGE_SIZE); |
Francisco Jerez | a0af9ad | 2009-12-11 16:51:09 +0100 | [diff] [blame] | 87 | } |
| 88 | |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 89 | int |
Ben Skeggs | 7375c95 | 2011-06-07 14:21:29 +1000 | [diff] [blame] | 90 | nouveau_bo_new(struct drm_device *dev, int size, int align, |
| 91 | uint32_t flags, uint32_t tile_mode, uint32_t tile_flags, |
Dave Airlie | 22b33e8 | 2012-04-02 11:53:06 +0100 | [diff] [blame] | 92 | struct sg_table *sg, |
Ben Skeggs | 7375c95 | 2011-06-07 14:21:29 +1000 | [diff] [blame] | 93 | struct nouveau_bo **pnvbo) |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 94 | { |
| 95 | struct drm_nouveau_private *dev_priv = dev->dev_private; |
| 96 | struct nouveau_bo *nvbo; |
Jerome Glisse | 57de4ba | 2011-11-11 15:42:57 -0500 | [diff] [blame] | 97 | size_t acc_size; |
Ben Skeggs | f91bac5 | 2011-06-06 14:15:46 +1000 | [diff] [blame] | 98 | int ret; |
Dave Airlie | 22b33e8 | 2012-04-02 11:53:06 +0100 | [diff] [blame] | 99 | int type = ttm_bo_type_device; |
| 100 | |
| 101 | if (sg) |
| 102 | type = ttm_bo_type_sg; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 103 | |
| 104 | nvbo = kzalloc(sizeof(struct nouveau_bo), GFP_KERNEL); |
| 105 | if (!nvbo) |
| 106 | return -ENOMEM; |
| 107 | INIT_LIST_HEAD(&nvbo->head); |
| 108 | INIT_LIST_HEAD(&nvbo->entry); |
Ben Skeggs | fd2871a | 2011-06-06 14:07:04 +1000 | [diff] [blame] | 109 | INIT_LIST_HEAD(&nvbo->vma_list); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 110 | nvbo->tile_mode = tile_mode; |
| 111 | nvbo->tile_flags = tile_flags; |
Francisco Jerez | 699ddfd | 2010-10-10 06:07:32 +0200 | [diff] [blame] | 112 | nvbo->bo.bdev = &dev_priv->ttm.bdev; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 113 | |
Ben Skeggs | f91bac5 | 2011-06-06 14:15:46 +1000 | [diff] [blame] | 114 | nvbo->page_shift = 12; |
| 115 | if (dev_priv->bar1_vm) { |
| 116 | if (!(flags & TTM_PL_FLAG_TT) && size > 256 * 1024) |
| 117 | nvbo->page_shift = dev_priv->bar1_vm->lpg_shift; |
| 118 | } |
| 119 | |
| 120 | nouveau_bo_fixup_align(nvbo, flags, &align, &size); |
Ben Skeggs | fd2871a | 2011-06-06 14:07:04 +1000 | [diff] [blame] | 121 | nvbo->bo.mem.num_pages = size >> PAGE_SHIFT; |
| 122 | nouveau_bo_placement_set(nvbo, flags, 0); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 123 | |
Jerome Glisse | 57de4ba | 2011-11-11 15:42:57 -0500 | [diff] [blame] | 124 | acc_size = ttm_bo_dma_acc_size(&dev_priv->ttm.bdev, size, |
| 125 | sizeof(struct nouveau_bo)); |
| 126 | |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 127 | ret = ttm_bo_init(&dev_priv->ttm.bdev, &nvbo->bo, size, |
Dave Airlie | 22b33e8 | 2012-04-02 11:53:06 +0100 | [diff] [blame] | 128 | type, &nvbo->placement, |
| 129 | align >> PAGE_SHIFT, 0, false, NULL, acc_size, sg, |
Ben Skeggs | fd2871a | 2011-06-06 14:07:04 +1000 | [diff] [blame] | 130 | nouveau_bo_del_ttm); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 131 | if (ret) { |
| 132 | /* ttm will call nouveau_bo_del_ttm if it fails.. */ |
| 133 | return ret; |
| 134 | } |
| 135 | |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 136 | *pnvbo = nvbo; |
| 137 | return 0; |
| 138 | } |
| 139 | |
Francisco Jerez | 78ad0f7 | 2010-03-18 13:07:47 +0100 | [diff] [blame] | 140 | static void |
| 141 | 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] | 142 | { |
Francisco Jerez | 78ad0f7 | 2010-03-18 13:07:47 +0100 | [diff] [blame] | 143 | *n = 0; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 144 | |
Francisco Jerez | 78ad0f7 | 2010-03-18 13:07:47 +0100 | [diff] [blame] | 145 | if (type & TTM_PL_FLAG_VRAM) |
| 146 | pl[(*n)++] = TTM_PL_FLAG_VRAM | flags; |
| 147 | if (type & TTM_PL_FLAG_TT) |
| 148 | pl[(*n)++] = TTM_PL_FLAG_TT | flags; |
| 149 | if (type & TTM_PL_FLAG_SYSTEM) |
| 150 | pl[(*n)++] = TTM_PL_FLAG_SYSTEM | flags; |
| 151 | } |
Ben Skeggs | 37cb3e08 | 2009-12-16 16:22:42 +1000 | [diff] [blame] | 152 | |
Francisco Jerez | 699ddfd | 2010-10-10 06:07:32 +0200 | [diff] [blame] | 153 | static void |
| 154 | set_placement_range(struct nouveau_bo *nvbo, uint32_t type) |
| 155 | { |
| 156 | struct drm_nouveau_private *dev_priv = nouveau_bdev(nvbo->bo.bdev); |
Francisco Jerez | 812f219 | 2011-02-03 01:49:33 +0100 | [diff] [blame] | 157 | int vram_pages = dev_priv->vram_size >> PAGE_SHIFT; |
Francisco Jerez | 699ddfd | 2010-10-10 06:07:32 +0200 | [diff] [blame] | 158 | |
| 159 | if (dev_priv->card_type == NV_10 && |
Francisco Jerez | 812f219 | 2011-02-03 01:49:33 +0100 | [diff] [blame] | 160 | nvbo->tile_mode && (type & TTM_PL_FLAG_VRAM) && |
Francisco Jerez | 4beb116 | 2011-11-06 21:21:28 +0100 | [diff] [blame] | 161 | nvbo->bo.mem.num_pages < vram_pages / 4) { |
Francisco Jerez | 699ddfd | 2010-10-10 06:07:32 +0200 | [diff] [blame] | 162 | /* |
| 163 | * Make sure that the color and depth buffers are handled |
| 164 | * by independent memory controller units. Up to a 9x |
| 165 | * speed up when alpha-blending and depth-test are enabled |
| 166 | * at the same time. |
| 167 | */ |
Francisco Jerez | 699ddfd | 2010-10-10 06:07:32 +0200 | [diff] [blame] | 168 | if (nvbo->tile_flags & NOUVEAU_GEM_TILE_ZETA) { |
| 169 | nvbo->placement.fpfn = vram_pages / 2; |
| 170 | nvbo->placement.lpfn = ~0; |
| 171 | } else { |
| 172 | nvbo->placement.fpfn = 0; |
| 173 | nvbo->placement.lpfn = vram_pages / 2; |
| 174 | } |
| 175 | } |
| 176 | } |
| 177 | |
Francisco Jerez | 78ad0f7 | 2010-03-18 13:07:47 +0100 | [diff] [blame] | 178 | void |
| 179 | nouveau_bo_placement_set(struct nouveau_bo *nvbo, uint32_t type, uint32_t busy) |
| 180 | { |
| 181 | struct ttm_placement *pl = &nvbo->placement; |
| 182 | uint32_t flags = TTM_PL_MASK_CACHING | |
| 183 | (nvbo->pin_refcnt ? TTM_PL_FLAG_NO_EVICT : 0); |
| 184 | |
| 185 | pl->placement = nvbo->placements; |
| 186 | set_placement_list(nvbo->placements, &pl->num_placement, |
| 187 | type, flags); |
| 188 | |
| 189 | pl->busy_placement = nvbo->busy_placements; |
| 190 | set_placement_list(nvbo->busy_placements, &pl->num_busy_placement, |
| 191 | type | busy, flags); |
Francisco Jerez | 699ddfd | 2010-10-10 06:07:32 +0200 | [diff] [blame] | 192 | |
| 193 | set_placement_range(nvbo, type); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 194 | } |
| 195 | |
| 196 | int |
| 197 | nouveau_bo_pin(struct nouveau_bo *nvbo, uint32_t memtype) |
| 198 | { |
| 199 | struct drm_nouveau_private *dev_priv = nouveau_bdev(nvbo->bo.bdev); |
| 200 | struct ttm_buffer_object *bo = &nvbo->bo; |
Francisco Jerez | 78ad0f7 | 2010-03-18 13:07:47 +0100 | [diff] [blame] | 201 | int ret; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 202 | |
| 203 | if (nvbo->pin_refcnt && !(memtype & (1 << bo->mem.mem_type))) { |
| 204 | NV_ERROR(nouveau_bdev(bo->bdev)->dev, |
| 205 | "bo %p pinned elsewhere: 0x%08x vs 0x%08x\n", bo, |
| 206 | 1 << bo->mem.mem_type, memtype); |
| 207 | return -EINVAL; |
| 208 | } |
| 209 | |
| 210 | if (nvbo->pin_refcnt++) |
| 211 | return 0; |
| 212 | |
| 213 | ret = ttm_bo_reserve(bo, false, false, false, 0); |
| 214 | if (ret) |
| 215 | goto out; |
| 216 | |
Francisco Jerez | 78ad0f7 | 2010-03-18 13:07:47 +0100 | [diff] [blame] | 217 | nouveau_bo_placement_set(nvbo, memtype, 0); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 218 | |
Ben Skeggs | 7a45d76 | 2010-11-22 08:50:27 +1000 | [diff] [blame] | 219 | ret = nouveau_bo_validate(nvbo, false, false, false); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 220 | if (ret == 0) { |
| 221 | switch (bo->mem.mem_type) { |
| 222 | case TTM_PL_VRAM: |
| 223 | dev_priv->fb_aper_free -= bo->mem.size; |
| 224 | break; |
| 225 | case TTM_PL_TT: |
| 226 | dev_priv->gart_info.aper_free -= bo->mem.size; |
| 227 | break; |
| 228 | default: |
| 229 | break; |
| 230 | } |
| 231 | } |
| 232 | ttm_bo_unreserve(bo); |
| 233 | out: |
| 234 | if (unlikely(ret)) |
| 235 | nvbo->pin_refcnt--; |
| 236 | return ret; |
| 237 | } |
| 238 | |
| 239 | int |
| 240 | nouveau_bo_unpin(struct nouveau_bo *nvbo) |
| 241 | { |
| 242 | struct drm_nouveau_private *dev_priv = nouveau_bdev(nvbo->bo.bdev); |
| 243 | struct ttm_buffer_object *bo = &nvbo->bo; |
Francisco Jerez | 78ad0f7 | 2010-03-18 13:07:47 +0100 | [diff] [blame] | 244 | int ret; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 245 | |
| 246 | if (--nvbo->pin_refcnt) |
| 247 | return 0; |
| 248 | |
| 249 | ret = ttm_bo_reserve(bo, false, false, false, 0); |
| 250 | if (ret) |
| 251 | return ret; |
| 252 | |
Francisco Jerez | 78ad0f7 | 2010-03-18 13:07:47 +0100 | [diff] [blame] | 253 | nouveau_bo_placement_set(nvbo, bo->mem.placement, 0); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 254 | |
Ben Skeggs | 7a45d76 | 2010-11-22 08:50:27 +1000 | [diff] [blame] | 255 | ret = nouveau_bo_validate(nvbo, false, false, false); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 256 | if (ret == 0) { |
| 257 | switch (bo->mem.mem_type) { |
| 258 | case TTM_PL_VRAM: |
| 259 | dev_priv->fb_aper_free += bo->mem.size; |
| 260 | break; |
| 261 | case TTM_PL_TT: |
| 262 | dev_priv->gart_info.aper_free += bo->mem.size; |
| 263 | break; |
| 264 | default: |
| 265 | break; |
| 266 | } |
| 267 | } |
| 268 | |
| 269 | ttm_bo_unreserve(bo); |
| 270 | return ret; |
| 271 | } |
| 272 | |
| 273 | int |
| 274 | nouveau_bo_map(struct nouveau_bo *nvbo) |
| 275 | { |
| 276 | int ret; |
| 277 | |
| 278 | ret = ttm_bo_reserve(&nvbo->bo, false, false, false, 0); |
| 279 | if (ret) |
| 280 | return ret; |
| 281 | |
| 282 | ret = ttm_bo_kmap(&nvbo->bo, 0, nvbo->bo.mem.num_pages, &nvbo->kmap); |
| 283 | ttm_bo_unreserve(&nvbo->bo); |
| 284 | return ret; |
| 285 | } |
| 286 | |
| 287 | void |
| 288 | nouveau_bo_unmap(struct nouveau_bo *nvbo) |
| 289 | { |
Ben Skeggs | 9d59e8a | 2010-08-27 13:04:41 +1000 | [diff] [blame] | 290 | if (nvbo) |
| 291 | ttm_bo_kunmap(&nvbo->kmap); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 292 | } |
| 293 | |
Ben Skeggs | 7a45d76 | 2010-11-22 08:50:27 +1000 | [diff] [blame] | 294 | int |
| 295 | nouveau_bo_validate(struct nouveau_bo *nvbo, bool interruptible, |
| 296 | bool no_wait_reserve, bool no_wait_gpu) |
| 297 | { |
| 298 | int ret; |
| 299 | |
| 300 | ret = ttm_bo_validate(&nvbo->bo, &nvbo->placement, interruptible, |
| 301 | no_wait_reserve, no_wait_gpu); |
| 302 | if (ret) |
| 303 | return ret; |
| 304 | |
| 305 | return 0; |
| 306 | } |
| 307 | |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 308 | u16 |
| 309 | nouveau_bo_rd16(struct nouveau_bo *nvbo, unsigned index) |
| 310 | { |
| 311 | bool is_iomem; |
| 312 | u16 *mem = ttm_kmap_obj_virtual(&nvbo->kmap, &is_iomem); |
| 313 | mem = &mem[index]; |
| 314 | if (is_iomem) |
| 315 | return ioread16_native((void __force __iomem *)mem); |
| 316 | else |
| 317 | return *mem; |
| 318 | } |
| 319 | |
| 320 | void |
| 321 | nouveau_bo_wr16(struct nouveau_bo *nvbo, unsigned index, u16 val) |
| 322 | { |
| 323 | bool is_iomem; |
| 324 | u16 *mem = ttm_kmap_obj_virtual(&nvbo->kmap, &is_iomem); |
| 325 | mem = &mem[index]; |
| 326 | if (is_iomem) |
| 327 | iowrite16_native(val, (void __force __iomem *)mem); |
| 328 | else |
| 329 | *mem = val; |
| 330 | } |
| 331 | |
| 332 | u32 |
| 333 | nouveau_bo_rd32(struct nouveau_bo *nvbo, unsigned index) |
| 334 | { |
| 335 | bool is_iomem; |
| 336 | u32 *mem = ttm_kmap_obj_virtual(&nvbo->kmap, &is_iomem); |
| 337 | mem = &mem[index]; |
| 338 | if (is_iomem) |
| 339 | return ioread32_native((void __force __iomem *)mem); |
| 340 | else |
| 341 | return *mem; |
| 342 | } |
| 343 | |
| 344 | void |
| 345 | nouveau_bo_wr32(struct nouveau_bo *nvbo, unsigned index, u32 val) |
| 346 | { |
| 347 | bool is_iomem; |
| 348 | u32 *mem = ttm_kmap_obj_virtual(&nvbo->kmap, &is_iomem); |
| 349 | mem = &mem[index]; |
| 350 | if (is_iomem) |
| 351 | iowrite32_native(val, (void __force __iomem *)mem); |
| 352 | else |
| 353 | *mem = val; |
| 354 | } |
| 355 | |
Jerome Glisse | 649bf3c | 2011-11-01 20:46:13 -0400 | [diff] [blame] | 356 | static struct ttm_tt * |
| 357 | nouveau_ttm_tt_create(struct ttm_bo_device *bdev, |
| 358 | unsigned long size, uint32_t page_flags, |
| 359 | struct page *dummy_read_page) |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 360 | { |
| 361 | struct drm_nouveau_private *dev_priv = nouveau_bdev(bdev); |
| 362 | struct drm_device *dev = dev_priv->dev; |
| 363 | |
| 364 | switch (dev_priv->gart_info.type) { |
Ben Skeggs | b694dfb | 2009-12-15 10:38:32 +1000 | [diff] [blame] | 365 | #if __OS_HAS_AGP |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 366 | case NOUVEAU_GART_AGP: |
Jerome Glisse | 649bf3c | 2011-11-01 20:46:13 -0400 | [diff] [blame] | 367 | return ttm_agp_tt_create(bdev, dev->agp->bridge, |
| 368 | size, page_flags, dummy_read_page); |
Ben Skeggs | b694dfb | 2009-12-15 10:38:32 +1000 | [diff] [blame] | 369 | #endif |
Ben Skeggs | 58e6c7a | 2011-01-11 14:10:09 +1000 | [diff] [blame] | 370 | case NOUVEAU_GART_PDMA: |
| 371 | case NOUVEAU_GART_HW: |
Jerome Glisse | 649bf3c | 2011-11-01 20:46:13 -0400 | [diff] [blame] | 372 | return nouveau_sgdma_create_ttm(bdev, size, page_flags, |
| 373 | dummy_read_page); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 374 | default: |
| 375 | NV_ERROR(dev, "Unknown GART type %d\n", |
| 376 | dev_priv->gart_info.type); |
| 377 | break; |
| 378 | } |
| 379 | |
| 380 | return NULL; |
| 381 | } |
| 382 | |
| 383 | static int |
| 384 | nouveau_bo_invalidate_caches(struct ttm_bo_device *bdev, uint32_t flags) |
| 385 | { |
| 386 | /* We'll do this from user space. */ |
| 387 | return 0; |
| 388 | } |
| 389 | |
| 390 | static int |
| 391 | nouveau_bo_init_mem_type(struct ttm_bo_device *bdev, uint32_t type, |
| 392 | struct ttm_mem_type_manager *man) |
| 393 | { |
| 394 | struct drm_nouveau_private *dev_priv = nouveau_bdev(bdev); |
| 395 | struct drm_device *dev = dev_priv->dev; |
| 396 | |
| 397 | switch (type) { |
| 398 | case TTM_PL_SYSTEM: |
| 399 | man->flags = TTM_MEMTYPE_FLAG_MAPPABLE; |
| 400 | man->available_caching = TTM_PL_MASK_CACHING; |
| 401 | man->default_caching = TTM_PL_FLAG_CACHED; |
| 402 | break; |
| 403 | case TTM_PL_VRAM: |
Ben Skeggs | 8984e04 | 2010-11-15 11:48:33 +1000 | [diff] [blame] | 404 | if (dev_priv->card_type >= NV_50) { |
Ben Skeggs | 573a2a3 | 2010-08-25 15:26:04 +1000 | [diff] [blame] | 405 | man->func = &nouveau_vram_manager; |
Ben Skeggs | f869ef8 | 2010-11-15 11:53:16 +1000 | [diff] [blame] | 406 | man->io_reserve_fastpath = false; |
| 407 | man->use_io_reserve_lru = true; |
| 408 | } else { |
Ben Skeggs | 573a2a3 | 2010-08-25 15:26:04 +1000 | [diff] [blame] | 409 | man->func = &ttm_bo_manager_func; |
Ben Skeggs | f869ef8 | 2010-11-15 11:53:16 +1000 | [diff] [blame] | 410 | } |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 411 | man->flags = TTM_MEMTYPE_FLAG_FIXED | |
Jerome Glisse | f32f02f | 2010-04-09 14:39:25 +0200 | [diff] [blame] | 412 | TTM_MEMTYPE_FLAG_MAPPABLE; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 413 | man->available_caching = TTM_PL_FLAG_UNCACHED | |
| 414 | TTM_PL_FLAG_WC; |
| 415 | man->default_caching = TTM_PL_FLAG_WC; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 416 | break; |
| 417 | case TTM_PL_TT: |
Ben Skeggs | 26c0c9e | 2011-02-10 12:59:51 +1000 | [diff] [blame] | 418 | if (dev_priv->card_type >= NV_50) |
| 419 | man->func = &nouveau_gart_manager; |
| 420 | else |
| 421 | man->func = &ttm_bo_manager_func; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 422 | switch (dev_priv->gart_info.type) { |
| 423 | case NOUVEAU_GART_AGP: |
Jerome Glisse | f32f02f | 2010-04-09 14:39:25 +0200 | [diff] [blame] | 424 | man->flags = TTM_MEMTYPE_FLAG_MAPPABLE; |
Francisco Jerez | a3d487e | 2010-11-20 22:11:22 +0100 | [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 | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 428 | break; |
Ben Skeggs | 58e6c7a | 2011-01-11 14:10:09 +1000 | [diff] [blame] | 429 | case NOUVEAU_GART_PDMA: |
| 430 | case NOUVEAU_GART_HW: |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 431 | man->flags = TTM_MEMTYPE_FLAG_MAPPABLE | |
| 432 | TTM_MEMTYPE_FLAG_CMA; |
| 433 | man->available_caching = TTM_PL_MASK_CACHING; |
| 434 | man->default_caching = TTM_PL_FLAG_CACHED; |
| 435 | break; |
| 436 | default: |
| 437 | NV_ERROR(dev, "Unknown GART type: %d\n", |
| 438 | dev_priv->gart_info.type); |
| 439 | return -EINVAL; |
| 440 | } |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 441 | break; |
| 442 | default: |
| 443 | NV_ERROR(dev, "Unsupported memory type %u\n", (unsigned)type); |
| 444 | return -EINVAL; |
| 445 | } |
| 446 | return 0; |
| 447 | } |
| 448 | |
| 449 | static void |
| 450 | nouveau_bo_evict_flags(struct ttm_buffer_object *bo, struct ttm_placement *pl) |
| 451 | { |
| 452 | struct nouveau_bo *nvbo = nouveau_bo(bo); |
| 453 | |
| 454 | switch (bo->mem.mem_type) { |
Francisco Jerez | 22fbd53 | 2009-12-11 18:40:17 +0100 | [diff] [blame] | 455 | case TTM_PL_VRAM: |
Francisco Jerez | 78ad0f7 | 2010-03-18 13:07:47 +0100 | [diff] [blame] | 456 | nouveau_bo_placement_set(nvbo, TTM_PL_FLAG_TT, |
| 457 | TTM_PL_FLAG_SYSTEM); |
Francisco Jerez | 22fbd53 | 2009-12-11 18:40:17 +0100 | [diff] [blame] | 458 | break; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 459 | default: |
Francisco Jerez | 78ad0f7 | 2010-03-18 13:07:47 +0100 | [diff] [blame] | 460 | nouveau_bo_placement_set(nvbo, TTM_PL_FLAG_SYSTEM, 0); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 461 | break; |
| 462 | } |
Francisco Jerez | 22fbd53 | 2009-12-11 18:40:17 +0100 | [diff] [blame] | 463 | |
| 464 | *pl = nvbo->placement; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 465 | } |
| 466 | |
| 467 | |
| 468 | /* GPU-assisted copy using NV_MEMORY_TO_MEMORY_FORMAT, can access |
| 469 | * TTM_PL_{VRAM,TT} directly. |
| 470 | */ |
Francisco Jerez | a0af9ad | 2009-12-11 16:51:09 +0100 | [diff] [blame] | 471 | |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 472 | static int |
| 473 | nouveau_bo_move_accel_cleanup(struct nouveau_channel *chan, |
Jerome Glisse | 9d87fa2 | 2010-04-07 10:21:19 +0000 | [diff] [blame] | 474 | struct nouveau_bo *nvbo, bool evict, |
| 475 | bool no_wait_reserve, bool no_wait_gpu, |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 476 | struct ttm_mem_reg *new_mem) |
| 477 | { |
| 478 | struct nouveau_fence *fence = NULL; |
| 479 | int ret; |
| 480 | |
| 481 | ret = nouveau_fence_new(chan, &fence, true); |
| 482 | if (ret) |
| 483 | return ret; |
| 484 | |
Francisco Jerez | 6479881 | 2010-09-21 19:02:01 +0200 | [diff] [blame] | 485 | ret = ttm_bo_move_accel_cleanup(&nvbo->bo, fence, NULL, evict, |
Francisco Jerez | 311ab69 | 2010-07-04 12:54:23 +0200 | [diff] [blame] | 486 | no_wait_reserve, no_wait_gpu, new_mem); |
Marcin Slusarz | 382d62e | 2010-10-20 21:50:24 +0200 | [diff] [blame] | 487 | nouveau_fence_unref(&fence); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 488 | return ret; |
| 489 | } |
| 490 | |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 491 | static int |
Ben Skeggs | c6b7e89 | 2012-03-20 14:36:04 +1000 | [diff] [blame] | 492 | nve0_bo_move_copy(struct nouveau_channel *chan, struct ttm_buffer_object *bo, |
| 493 | struct ttm_mem_reg *old_mem, struct ttm_mem_reg *new_mem) |
| 494 | { |
| 495 | struct nouveau_mem *node = old_mem->mm_node; |
| 496 | int ret = RING_SPACE(chan, 10); |
| 497 | if (ret == 0) { |
Ben Skeggs | 6d59702 | 2012-04-01 21:09:13 +1000 | [diff] [blame] | 498 | BEGIN_NVC0(chan, NvSubCopy, 0x0400, 8); |
Ben Skeggs | c6b7e89 | 2012-03-20 14:36:04 +1000 | [diff] [blame] | 499 | OUT_RING (chan, upper_32_bits(node->vma[0].offset)); |
| 500 | OUT_RING (chan, lower_32_bits(node->vma[0].offset)); |
| 501 | OUT_RING (chan, upper_32_bits(node->vma[1].offset)); |
| 502 | OUT_RING (chan, lower_32_bits(node->vma[1].offset)); |
| 503 | OUT_RING (chan, PAGE_SIZE); |
| 504 | OUT_RING (chan, PAGE_SIZE); |
| 505 | OUT_RING (chan, PAGE_SIZE); |
| 506 | OUT_RING (chan, new_mem->num_pages); |
Ben Skeggs | 6d59702 | 2012-04-01 21:09:13 +1000 | [diff] [blame] | 507 | BEGIN_IMC0(chan, NvSubCopy, 0x0300, 0x0386); |
Ben Skeggs | c6b7e89 | 2012-03-20 14:36:04 +1000 | [diff] [blame] | 508 | } |
| 509 | return ret; |
| 510 | } |
| 511 | |
| 512 | static int |
Ben Skeggs | 183720b | 2010-12-09 15:17:10 +1000 | [diff] [blame] | 513 | nvc0_bo_move_m2mf(struct nouveau_channel *chan, struct ttm_buffer_object *bo, |
| 514 | struct ttm_mem_reg *old_mem, struct ttm_mem_reg *new_mem) |
| 515 | { |
Ben Skeggs | d2f96666 | 2011-06-06 20:54:42 +1000 | [diff] [blame] | 516 | struct nouveau_mem *node = old_mem->mm_node; |
| 517 | u64 src_offset = node->vma[0].offset; |
| 518 | u64 dst_offset = node->vma[1].offset; |
Ben Skeggs | 183720b | 2010-12-09 15:17:10 +1000 | [diff] [blame] | 519 | u32 page_count = new_mem->num_pages; |
| 520 | int ret; |
| 521 | |
Ben Skeggs | 183720b | 2010-12-09 15:17:10 +1000 | [diff] [blame] | 522 | page_count = new_mem->num_pages; |
| 523 | while (page_count) { |
| 524 | int line_count = (page_count > 2047) ? 2047 : page_count; |
| 525 | |
| 526 | ret = RING_SPACE(chan, 12); |
| 527 | if (ret) |
| 528 | return ret; |
| 529 | |
Ben Skeggs | 6d59702 | 2012-04-01 21:09:13 +1000 | [diff] [blame] | 530 | BEGIN_NVC0(chan, NvSubM2MF, 0x0238, 2); |
Ben Skeggs | 183720b | 2010-12-09 15:17:10 +1000 | [diff] [blame] | 531 | OUT_RING (chan, upper_32_bits(dst_offset)); |
| 532 | OUT_RING (chan, lower_32_bits(dst_offset)); |
Ben Skeggs | 6d59702 | 2012-04-01 21:09:13 +1000 | [diff] [blame] | 533 | BEGIN_NVC0(chan, NvSubM2MF, 0x030c, 6); |
Ben Skeggs | 183720b | 2010-12-09 15:17:10 +1000 | [diff] [blame] | 534 | OUT_RING (chan, upper_32_bits(src_offset)); |
| 535 | OUT_RING (chan, lower_32_bits(src_offset)); |
| 536 | OUT_RING (chan, PAGE_SIZE); /* src_pitch */ |
| 537 | OUT_RING (chan, PAGE_SIZE); /* dst_pitch */ |
| 538 | OUT_RING (chan, PAGE_SIZE); /* line_length */ |
| 539 | OUT_RING (chan, line_count); |
Ben Skeggs | 6d59702 | 2012-04-01 21:09:13 +1000 | [diff] [blame] | 540 | BEGIN_NVC0(chan, NvSubM2MF, 0x0300, 1); |
Ben Skeggs | 183720b | 2010-12-09 15:17:10 +1000 | [diff] [blame] | 541 | OUT_RING (chan, 0x00100110); |
| 542 | |
| 543 | page_count -= line_count; |
| 544 | src_offset += (PAGE_SIZE * line_count); |
| 545 | dst_offset += (PAGE_SIZE * line_count); |
| 546 | } |
| 547 | |
| 548 | return 0; |
| 549 | } |
| 550 | |
| 551 | static int |
Ben Skeggs | f1ab0cc | 2010-08-26 11:32:01 +1000 | [diff] [blame] | 552 | nv50_bo_move_m2mf(struct nouveau_channel *chan, struct ttm_buffer_object *bo, |
| 553 | struct ttm_mem_reg *old_mem, struct ttm_mem_reg *new_mem) |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 554 | { |
Ben Skeggs | d2f96666 | 2011-06-06 20:54:42 +1000 | [diff] [blame] | 555 | struct nouveau_mem *node = old_mem->mm_node; |
Ben Skeggs | f1ab0cc | 2010-08-26 11:32:01 +1000 | [diff] [blame] | 556 | struct nouveau_bo *nvbo = nouveau_bo(bo); |
| 557 | u64 length = (new_mem->num_pages << PAGE_SHIFT); |
Ben Skeggs | d2f96666 | 2011-06-06 20:54:42 +1000 | [diff] [blame] | 558 | u64 src_offset = node->vma[0].offset; |
| 559 | u64 dst_offset = node->vma[1].offset; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 560 | int ret; |
| 561 | |
Ben Skeggs | f1ab0cc | 2010-08-26 11:32:01 +1000 | [diff] [blame] | 562 | while (length) { |
| 563 | u32 amount, stride, height; |
| 564 | |
Ben Skeggs | 5220b3c | 2010-09-23 15:21:17 +1000 | [diff] [blame] | 565 | amount = min(length, (u64)(4 * 1024 * 1024)); |
| 566 | stride = 16 * 4; |
Ben Skeggs | f1ab0cc | 2010-08-26 11:32:01 +1000 | [diff] [blame] | 567 | height = amount / stride; |
| 568 | |
Francisco Jerez | f13b326 | 2010-10-10 06:01:08 +0200 | [diff] [blame] | 569 | if (new_mem->mem_type == TTM_PL_VRAM && |
| 570 | nouveau_bo_tile_layout(nvbo)) { |
Ben Skeggs | f1ab0cc | 2010-08-26 11:32:01 +1000 | [diff] [blame] | 571 | ret = RING_SPACE(chan, 8); |
| 572 | if (ret) |
| 573 | return ret; |
| 574 | |
Ben Skeggs | 6d59702 | 2012-04-01 21:09:13 +1000 | [diff] [blame] | 575 | BEGIN_NV04(chan, NvSubM2MF, 0x0200, 7); |
Ben Skeggs | f1ab0cc | 2010-08-26 11:32:01 +1000 | [diff] [blame] | 576 | OUT_RING (chan, 0); |
Ben Skeggs | 5220b3c | 2010-09-23 15:21:17 +1000 | [diff] [blame] | 577 | OUT_RING (chan, 0); |
Ben Skeggs | f1ab0cc | 2010-08-26 11:32:01 +1000 | [diff] [blame] | 578 | OUT_RING (chan, stride); |
| 579 | OUT_RING (chan, height); |
| 580 | OUT_RING (chan, 1); |
| 581 | OUT_RING (chan, 0); |
| 582 | OUT_RING (chan, 0); |
| 583 | } else { |
| 584 | ret = RING_SPACE(chan, 2); |
| 585 | if (ret) |
| 586 | return ret; |
| 587 | |
Ben Skeggs | 6d59702 | 2012-04-01 21:09:13 +1000 | [diff] [blame] | 588 | BEGIN_NV04(chan, NvSubM2MF, 0x0200, 1); |
Ben Skeggs | f1ab0cc | 2010-08-26 11:32:01 +1000 | [diff] [blame] | 589 | OUT_RING (chan, 1); |
| 590 | } |
Francisco Jerez | f13b326 | 2010-10-10 06:01:08 +0200 | [diff] [blame] | 591 | if (old_mem->mem_type == TTM_PL_VRAM && |
| 592 | nouveau_bo_tile_layout(nvbo)) { |
Ben Skeggs | f1ab0cc | 2010-08-26 11:32:01 +1000 | [diff] [blame] | 593 | ret = RING_SPACE(chan, 8); |
| 594 | if (ret) |
| 595 | return ret; |
| 596 | |
Ben Skeggs | 6d59702 | 2012-04-01 21:09:13 +1000 | [diff] [blame] | 597 | BEGIN_NV04(chan, NvSubM2MF, 0x021c, 7); |
Ben Skeggs | f1ab0cc | 2010-08-26 11:32:01 +1000 | [diff] [blame] | 598 | OUT_RING (chan, 0); |
Ben Skeggs | 5220b3c | 2010-09-23 15:21:17 +1000 | [diff] [blame] | 599 | OUT_RING (chan, 0); |
Ben Skeggs | f1ab0cc | 2010-08-26 11:32:01 +1000 | [diff] [blame] | 600 | OUT_RING (chan, stride); |
| 601 | OUT_RING (chan, height); |
| 602 | OUT_RING (chan, 1); |
| 603 | OUT_RING (chan, 0); |
| 604 | OUT_RING (chan, 0); |
| 605 | } else { |
| 606 | ret = RING_SPACE(chan, 2); |
| 607 | if (ret) |
| 608 | return ret; |
| 609 | |
Ben Skeggs | 6d59702 | 2012-04-01 21:09:13 +1000 | [diff] [blame] | 610 | BEGIN_NV04(chan, NvSubM2MF, 0x021c, 1); |
Ben Skeggs | f1ab0cc | 2010-08-26 11:32:01 +1000 | [diff] [blame] | 611 | OUT_RING (chan, 1); |
| 612 | } |
| 613 | |
| 614 | ret = RING_SPACE(chan, 14); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 615 | if (ret) |
| 616 | return ret; |
Ben Skeggs | f1ab0cc | 2010-08-26 11:32:01 +1000 | [diff] [blame] | 617 | |
Ben Skeggs | 6d59702 | 2012-04-01 21:09:13 +1000 | [diff] [blame] | 618 | BEGIN_NV04(chan, NvSubM2MF, 0x0238, 2); |
Ben Skeggs | f1ab0cc | 2010-08-26 11:32:01 +1000 | [diff] [blame] | 619 | OUT_RING (chan, upper_32_bits(src_offset)); |
| 620 | OUT_RING (chan, upper_32_bits(dst_offset)); |
Ben Skeggs | 6d59702 | 2012-04-01 21:09:13 +1000 | [diff] [blame] | 621 | BEGIN_NV04(chan, NvSubM2MF, 0x030c, 8); |
Ben Skeggs | f1ab0cc | 2010-08-26 11:32:01 +1000 | [diff] [blame] | 622 | OUT_RING (chan, lower_32_bits(src_offset)); |
| 623 | OUT_RING (chan, lower_32_bits(dst_offset)); |
| 624 | OUT_RING (chan, stride); |
| 625 | OUT_RING (chan, stride); |
| 626 | OUT_RING (chan, stride); |
| 627 | OUT_RING (chan, height); |
| 628 | OUT_RING (chan, 0x00000101); |
| 629 | OUT_RING (chan, 0x00000000); |
Ben Skeggs | 6d59702 | 2012-04-01 21:09:13 +1000 | [diff] [blame] | 630 | BEGIN_NV04(chan, NvSubM2MF, NV_MEMORY_TO_MEMORY_FORMAT_NOP, 1); |
Ben Skeggs | f1ab0cc | 2010-08-26 11:32:01 +1000 | [diff] [blame] | 631 | OUT_RING (chan, 0); |
| 632 | |
| 633 | length -= amount; |
| 634 | src_offset += amount; |
| 635 | dst_offset += amount; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 636 | } |
| 637 | |
Ben Skeggs | f1ab0cc | 2010-08-26 11:32:01 +1000 | [diff] [blame] | 638 | return 0; |
| 639 | } |
| 640 | |
Ben Skeggs | a670478 | 2011-02-16 09:10:20 +1000 | [diff] [blame] | 641 | static inline uint32_t |
| 642 | nouveau_bo_mem_ctxdma(struct ttm_buffer_object *bo, |
| 643 | struct nouveau_channel *chan, struct ttm_mem_reg *mem) |
| 644 | { |
| 645 | if (mem->mem_type == TTM_PL_TT) |
| 646 | return chan->gart_handle; |
| 647 | return chan->vram_handle; |
| 648 | } |
| 649 | |
Ben Skeggs | f1ab0cc | 2010-08-26 11:32:01 +1000 | [diff] [blame] | 650 | static int |
| 651 | nv04_bo_move_m2mf(struct nouveau_channel *chan, struct ttm_buffer_object *bo, |
| 652 | struct ttm_mem_reg *old_mem, struct ttm_mem_reg *new_mem) |
| 653 | { |
Ben Skeggs | d961db7 | 2010-08-05 10:48:18 +1000 | [diff] [blame] | 654 | u32 src_offset = old_mem->start << PAGE_SHIFT; |
| 655 | u32 dst_offset = new_mem->start << PAGE_SHIFT; |
Ben Skeggs | f1ab0cc | 2010-08-26 11:32:01 +1000 | [diff] [blame] | 656 | u32 page_count = new_mem->num_pages; |
| 657 | int ret; |
| 658 | |
| 659 | ret = RING_SPACE(chan, 3); |
| 660 | if (ret) |
| 661 | return ret; |
| 662 | |
Ben Skeggs | 6d59702 | 2012-04-01 21:09:13 +1000 | [diff] [blame] | 663 | BEGIN_NV04(chan, NvSubM2MF, NV_MEMORY_TO_MEMORY_FORMAT_DMA_SOURCE, 2); |
Ben Skeggs | f1ab0cc | 2010-08-26 11:32:01 +1000 | [diff] [blame] | 664 | OUT_RING (chan, nouveau_bo_mem_ctxdma(bo, chan, old_mem)); |
| 665 | OUT_RING (chan, nouveau_bo_mem_ctxdma(bo, chan, new_mem)); |
| 666 | |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 667 | page_count = new_mem->num_pages; |
| 668 | while (page_count) { |
| 669 | int line_count = (page_count > 2047) ? 2047 : page_count; |
| 670 | |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 671 | ret = RING_SPACE(chan, 11); |
| 672 | if (ret) |
| 673 | return ret; |
Ben Skeggs | f1ab0cc | 2010-08-26 11:32:01 +1000 | [diff] [blame] | 674 | |
Ben Skeggs | 6d59702 | 2012-04-01 21:09:13 +1000 | [diff] [blame] | 675 | BEGIN_NV04(chan, NvSubM2MF, |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 676 | NV_MEMORY_TO_MEMORY_FORMAT_OFFSET_IN, 8); |
Ben Skeggs | f1ab0cc | 2010-08-26 11:32:01 +1000 | [diff] [blame] | 677 | OUT_RING (chan, src_offset); |
| 678 | OUT_RING (chan, dst_offset); |
| 679 | OUT_RING (chan, PAGE_SIZE); /* src_pitch */ |
| 680 | OUT_RING (chan, PAGE_SIZE); /* dst_pitch */ |
| 681 | OUT_RING (chan, PAGE_SIZE); /* line_length */ |
| 682 | OUT_RING (chan, line_count); |
| 683 | OUT_RING (chan, 0x00000101); |
| 684 | OUT_RING (chan, 0x00000000); |
Ben Skeggs | 6d59702 | 2012-04-01 21:09:13 +1000 | [diff] [blame] | 685 | BEGIN_NV04(chan, NvSubM2MF, NV_MEMORY_TO_MEMORY_FORMAT_NOP, 1); |
Ben Skeggs | f1ab0cc | 2010-08-26 11:32:01 +1000 | [diff] [blame] | 686 | OUT_RING (chan, 0); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 687 | |
| 688 | page_count -= line_count; |
| 689 | src_offset += (PAGE_SIZE * line_count); |
| 690 | dst_offset += (PAGE_SIZE * line_count); |
| 691 | } |
| 692 | |
Ben Skeggs | f1ab0cc | 2010-08-26 11:32:01 +1000 | [diff] [blame] | 693 | return 0; |
| 694 | } |
| 695 | |
| 696 | static int |
Ben Skeggs | d2f96666 | 2011-06-06 20:54:42 +1000 | [diff] [blame] | 697 | nouveau_vma_getmap(struct nouveau_channel *chan, struct nouveau_bo *nvbo, |
| 698 | struct ttm_mem_reg *mem, struct nouveau_vma *vma) |
| 699 | { |
| 700 | struct nouveau_mem *node = mem->mm_node; |
| 701 | int ret; |
| 702 | |
| 703 | ret = nouveau_vm_get(chan->vm, mem->num_pages << PAGE_SHIFT, |
| 704 | node->page_shift, NV_MEM_ACCESS_RO, vma); |
| 705 | if (ret) |
| 706 | return ret; |
| 707 | |
| 708 | if (mem->mem_type == TTM_PL_VRAM) |
| 709 | nouveau_vm_map(vma, node); |
| 710 | else |
Ben Skeggs | f7b24c4 | 2011-12-22 15:20:21 +1000 | [diff] [blame] | 711 | nouveau_vm_map_sg(vma, 0, mem->num_pages << PAGE_SHIFT, node); |
Ben Skeggs | d2f96666 | 2011-06-06 20:54:42 +1000 | [diff] [blame] | 712 | |
| 713 | return 0; |
| 714 | } |
| 715 | |
| 716 | static int |
Ben Skeggs | f1ab0cc | 2010-08-26 11:32:01 +1000 | [diff] [blame] | 717 | nouveau_bo_move_m2mf(struct ttm_buffer_object *bo, int evict, bool intr, |
| 718 | bool no_wait_reserve, bool no_wait_gpu, |
| 719 | struct ttm_mem_reg *new_mem) |
| 720 | { |
| 721 | struct drm_nouveau_private *dev_priv = nouveau_bdev(bo->bdev); |
Ben Skeggs | accf949 | 2012-03-16 12:40:17 +1000 | [diff] [blame] | 722 | struct nouveau_channel *chan = chan = dev_priv->channel; |
Ben Skeggs | f1ab0cc | 2010-08-26 11:32:01 +1000 | [diff] [blame] | 723 | struct nouveau_bo *nvbo = nouveau_bo(bo); |
Ben Skeggs | 3425df4 | 2011-02-10 11:22:12 +1000 | [diff] [blame] | 724 | struct ttm_mem_reg *old_mem = &bo->mem; |
Ben Skeggs | f1ab0cc | 2010-08-26 11:32:01 +1000 | [diff] [blame] | 725 | int ret; |
| 726 | |
Ben Skeggs | accf949 | 2012-03-16 12:40:17 +1000 | [diff] [blame] | 727 | mutex_lock_nested(&chan->mutex, NOUVEAU_KCHANNEL_MUTEX); |
Ben Skeggs | f1ab0cc | 2010-08-26 11:32:01 +1000 | [diff] [blame] | 728 | |
Ben Skeggs | d2f96666 | 2011-06-06 20:54:42 +1000 | [diff] [blame] | 729 | /* create temporary vmas for the transfer and attach them to the |
| 730 | * old nouveau_mem node, these will get cleaned up after ttm has |
| 731 | * destroyed the ttm_mem_reg |
Ben Skeggs | 3425df4 | 2011-02-10 11:22:12 +1000 | [diff] [blame] | 732 | */ |
Ben Skeggs | 26c0c9e | 2011-02-10 12:59:51 +1000 | [diff] [blame] | 733 | if (dev_priv->card_type >= NV_50) { |
Ben Skeggs | d5f4239 | 2011-02-10 12:22:52 +1000 | [diff] [blame] | 734 | struct nouveau_mem *node = old_mem->mm_node; |
Ben Skeggs | 3425df4 | 2011-02-10 11:22:12 +1000 | [diff] [blame] | 735 | |
Ben Skeggs | d2f96666 | 2011-06-06 20:54:42 +1000 | [diff] [blame] | 736 | ret = nouveau_vma_getmap(chan, nvbo, old_mem, &node->vma[0]); |
| 737 | if (ret) |
| 738 | goto out; |
Ben Skeggs | 3425df4 | 2011-02-10 11:22:12 +1000 | [diff] [blame] | 739 | |
Ben Skeggs | d2f96666 | 2011-06-06 20:54:42 +1000 | [diff] [blame] | 740 | ret = nouveau_vma_getmap(chan, nvbo, new_mem, &node->vma[1]); |
| 741 | if (ret) |
| 742 | goto out; |
Ben Skeggs | 3425df4 | 2011-02-10 11:22:12 +1000 | [diff] [blame] | 743 | } |
| 744 | |
Ben Skeggs | f1ab0cc | 2010-08-26 11:32:01 +1000 | [diff] [blame] | 745 | if (dev_priv->card_type < NV_50) |
| 746 | ret = nv04_bo_move_m2mf(chan, bo, &bo->mem, new_mem); |
| 747 | else |
Ben Skeggs | 183720b | 2010-12-09 15:17:10 +1000 | [diff] [blame] | 748 | if (dev_priv->card_type < NV_C0) |
Ben Skeggs | f1ab0cc | 2010-08-26 11:32:01 +1000 | [diff] [blame] | 749 | ret = nv50_bo_move_m2mf(chan, bo, &bo->mem, new_mem); |
Ben Skeggs | 183720b | 2010-12-09 15:17:10 +1000 | [diff] [blame] | 750 | else |
Ben Skeggs | c6b7e89 | 2012-03-20 14:36:04 +1000 | [diff] [blame] | 751 | if (dev_priv->card_type < NV_E0) |
Ben Skeggs | 183720b | 2010-12-09 15:17:10 +1000 | [diff] [blame] | 752 | ret = nvc0_bo_move_m2mf(chan, bo, &bo->mem, new_mem); |
Ben Skeggs | c6b7e89 | 2012-03-20 14:36:04 +1000 | [diff] [blame] | 753 | else |
| 754 | ret = nve0_bo_move_copy(chan, bo, &bo->mem, new_mem); |
Ben Skeggs | 6a6b73f | 2010-10-05 16:53:48 +1000 | [diff] [blame] | 755 | if (ret == 0) { |
| 756 | ret = nouveau_bo_move_accel_cleanup(chan, nvbo, evict, |
| 757 | no_wait_reserve, |
| 758 | no_wait_gpu, new_mem); |
| 759 | } |
Ben Skeggs | f1ab0cc | 2010-08-26 11:32:01 +1000 | [diff] [blame] | 760 | |
Ben Skeggs | 3425df4 | 2011-02-10 11:22:12 +1000 | [diff] [blame] | 761 | out: |
Ben Skeggs | accf949 | 2012-03-16 12:40:17 +1000 | [diff] [blame] | 762 | mutex_unlock(&chan->mutex); |
Ben Skeggs | 6a6b73f | 2010-10-05 16:53:48 +1000 | [diff] [blame] | 763 | return ret; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 764 | } |
| 765 | |
| 766 | static int |
| 767 | 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] | 768 | bool no_wait_reserve, bool no_wait_gpu, |
| 769 | struct ttm_mem_reg *new_mem) |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 770 | { |
| 771 | u32 placement_memtype = TTM_PL_FLAG_TT | TTM_PL_MASK_CACHING; |
| 772 | struct ttm_placement placement; |
| 773 | struct ttm_mem_reg tmp_mem; |
| 774 | int ret; |
| 775 | |
| 776 | placement.fpfn = placement.lpfn = 0; |
| 777 | placement.num_placement = placement.num_busy_placement = 1; |
Francisco Jerez | 77e2b5e | 2009-12-16 19:05:00 +0100 | [diff] [blame] | 778 | placement.placement = placement.busy_placement = &placement_memtype; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 779 | |
| 780 | tmp_mem = *new_mem; |
| 781 | tmp_mem.mm_node = NULL; |
Jerome Glisse | 9d87fa2 | 2010-04-07 10:21:19 +0000 | [diff] [blame] | 782 | 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] | 783 | if (ret) |
| 784 | return ret; |
| 785 | |
| 786 | ret = ttm_tt_bind(bo->ttm, &tmp_mem); |
| 787 | if (ret) |
| 788 | goto out; |
| 789 | |
Jerome Glisse | 9d87fa2 | 2010-04-07 10:21:19 +0000 | [diff] [blame] | 790 | 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] | 791 | if (ret) |
| 792 | goto out; |
| 793 | |
Ben Skeggs | b8884da | 2011-02-14 13:51:28 +1000 | [diff] [blame] | 794 | ret = ttm_bo_move_ttm(bo, true, no_wait_reserve, no_wait_gpu, new_mem); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 795 | out: |
Ben Skeggs | 42311ff | 2010-08-04 12:07:08 +1000 | [diff] [blame] | 796 | ttm_bo_mem_put(bo, &tmp_mem); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 797 | return ret; |
| 798 | } |
| 799 | |
| 800 | static int |
| 801 | 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] | 802 | bool no_wait_reserve, bool no_wait_gpu, |
| 803 | struct ttm_mem_reg *new_mem) |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 804 | { |
| 805 | u32 placement_memtype = TTM_PL_FLAG_TT | TTM_PL_MASK_CACHING; |
| 806 | struct ttm_placement placement; |
| 807 | struct ttm_mem_reg tmp_mem; |
| 808 | int ret; |
| 809 | |
| 810 | placement.fpfn = placement.lpfn = 0; |
| 811 | placement.num_placement = placement.num_busy_placement = 1; |
Francisco Jerez | 77e2b5e | 2009-12-16 19:05:00 +0100 | [diff] [blame] | 812 | placement.placement = placement.busy_placement = &placement_memtype; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 813 | |
| 814 | tmp_mem = *new_mem; |
| 815 | tmp_mem.mm_node = NULL; |
Jerome Glisse | 9d87fa2 | 2010-04-07 10:21:19 +0000 | [diff] [blame] | 816 | 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] | 817 | if (ret) |
| 818 | return ret; |
| 819 | |
Ben Skeggs | b8884da | 2011-02-14 13:51:28 +1000 | [diff] [blame] | 820 | ret = ttm_bo_move_ttm(bo, true, no_wait_reserve, no_wait_gpu, &tmp_mem); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 821 | if (ret) |
| 822 | goto out; |
| 823 | |
Ben Skeggs | b8884da | 2011-02-14 13:51:28 +1000 | [diff] [blame] | 824 | ret = nouveau_bo_move_m2mf(bo, true, intr, no_wait_reserve, no_wait_gpu, new_mem); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 825 | if (ret) |
| 826 | goto out; |
| 827 | |
| 828 | out: |
Ben Skeggs | 42311ff | 2010-08-04 12:07:08 +1000 | [diff] [blame] | 829 | ttm_bo_mem_put(bo, &tmp_mem); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 830 | return ret; |
| 831 | } |
| 832 | |
Ben Skeggs | a4154bb | 2011-02-10 10:35:16 +1000 | [diff] [blame] | 833 | static void |
| 834 | nouveau_bo_move_ntfy(struct ttm_buffer_object *bo, struct ttm_mem_reg *new_mem) |
| 835 | { |
Ben Skeggs | a4154bb | 2011-02-10 10:35:16 +1000 | [diff] [blame] | 836 | struct nouveau_bo *nvbo = nouveau_bo(bo); |
Ben Skeggs | fd2871a | 2011-06-06 14:07:04 +1000 | [diff] [blame] | 837 | struct nouveau_vma *vma; |
Ben Skeggs | a4154bb | 2011-02-10 10:35:16 +1000 | [diff] [blame] | 838 | |
Ben Skeggs | 9f1feed | 2012-01-25 15:34:22 +1000 | [diff] [blame] | 839 | /* ttm can now (stupidly) pass the driver bos it didn't create... */ |
| 840 | if (bo->destroy != nouveau_bo_del_ttm) |
| 841 | return; |
| 842 | |
Ben Skeggs | fd2871a | 2011-06-06 14:07:04 +1000 | [diff] [blame] | 843 | list_for_each_entry(vma, &nvbo->vma_list, head) { |
Jerome Glisse | dc97b34 | 2011-11-18 11:47:03 -0500 | [diff] [blame] | 844 | if (new_mem && new_mem->mem_type == TTM_PL_VRAM) { |
Ben Skeggs | fd2871a | 2011-06-06 14:07:04 +1000 | [diff] [blame] | 845 | nouveau_vm_map(vma, new_mem->mm_node); |
| 846 | } else |
Jerome Glisse | dc97b34 | 2011-11-18 11:47:03 -0500 | [diff] [blame] | 847 | if (new_mem && new_mem->mem_type == TTM_PL_TT && |
Ben Skeggs | fd2871a | 2011-06-06 14:07:04 +1000 | [diff] [blame] | 848 | nvbo->page_shift == vma->vm->spg_shift) { |
Dave Airlie | 22b33e8 | 2012-04-02 11:53:06 +0100 | [diff] [blame] | 849 | if (((struct nouveau_mem *)new_mem->mm_node)->sg) |
| 850 | nouveau_vm_map_sg_table(vma, 0, new_mem-> |
| 851 | num_pages << PAGE_SHIFT, |
| 852 | new_mem->mm_node); |
| 853 | else |
| 854 | nouveau_vm_map_sg(vma, 0, new_mem-> |
| 855 | num_pages << PAGE_SHIFT, |
| 856 | new_mem->mm_node); |
Ben Skeggs | fd2871a | 2011-06-06 14:07:04 +1000 | [diff] [blame] | 857 | } else { |
| 858 | nouveau_vm_unmap(vma); |
| 859 | } |
Ben Skeggs | a4154bb | 2011-02-10 10:35:16 +1000 | [diff] [blame] | 860 | } |
| 861 | } |
| 862 | |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 863 | static int |
Francisco Jerez | a0af9ad | 2009-12-11 16:51:09 +0100 | [diff] [blame] | 864 | nouveau_bo_vm_bind(struct ttm_buffer_object *bo, struct ttm_mem_reg *new_mem, |
| 865 | struct nouveau_tile_reg **new_tile) |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 866 | { |
| 867 | struct drm_nouveau_private *dev_priv = nouveau_bdev(bo->bdev); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 868 | struct drm_device *dev = dev_priv->dev; |
Francisco Jerez | a0af9ad | 2009-12-11 16:51:09 +0100 | [diff] [blame] | 869 | struct nouveau_bo *nvbo = nouveau_bo(bo); |
Ben Skeggs | a4154bb | 2011-02-10 10:35:16 +1000 | [diff] [blame] | 870 | u64 offset = new_mem->start << PAGE_SHIFT; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 871 | |
Ben Skeggs | a4154bb | 2011-02-10 10:35:16 +1000 | [diff] [blame] | 872 | *new_tile = NULL; |
| 873 | if (new_mem->mem_type != TTM_PL_VRAM) |
Francisco Jerez | a0af9ad | 2009-12-11 16:51:09 +0100 | [diff] [blame] | 874 | return 0; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 875 | |
Ben Skeggs | a4154bb | 2011-02-10 10:35:16 +1000 | [diff] [blame] | 876 | if (dev_priv->card_type >= NV_10) { |
Francisco Jerez | a0af9ad | 2009-12-11 16:51:09 +0100 | [diff] [blame] | 877 | *new_tile = nv10_mem_set_tiling(dev, offset, new_mem->size, |
Francisco Jerez | a5cf68b | 2010-10-24 16:14:41 +0200 | [diff] [blame] | 878 | nvbo->tile_mode, |
| 879 | nvbo->tile_flags); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 880 | } |
| 881 | |
Francisco Jerez | a0af9ad | 2009-12-11 16:51:09 +0100 | [diff] [blame] | 882 | return 0; |
| 883 | } |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 884 | |
Francisco Jerez | a0af9ad | 2009-12-11 16:51:09 +0100 | [diff] [blame] | 885 | static void |
| 886 | nouveau_bo_vm_cleanup(struct ttm_buffer_object *bo, |
| 887 | struct nouveau_tile_reg *new_tile, |
| 888 | struct nouveau_tile_reg **old_tile) |
| 889 | { |
| 890 | struct drm_nouveau_private *dev_priv = nouveau_bdev(bo->bdev); |
| 891 | struct drm_device *dev = dev_priv->dev; |
| 892 | |
Ben Skeggs | a4154bb | 2011-02-10 10:35:16 +1000 | [diff] [blame] | 893 | nv10_mem_put_tile_region(dev, *old_tile, bo->sync_obj); |
| 894 | *old_tile = new_tile; |
Francisco Jerez | a0af9ad | 2009-12-11 16:51:09 +0100 | [diff] [blame] | 895 | } |
| 896 | |
| 897 | static int |
| 898 | nouveau_bo_move(struct ttm_buffer_object *bo, bool evict, bool intr, |
Jerome Glisse | 9d87fa2 | 2010-04-07 10:21:19 +0000 | [diff] [blame] | 899 | bool no_wait_reserve, bool no_wait_gpu, |
| 900 | struct ttm_mem_reg *new_mem) |
Francisco Jerez | a0af9ad | 2009-12-11 16:51:09 +0100 | [diff] [blame] | 901 | { |
| 902 | struct drm_nouveau_private *dev_priv = nouveau_bdev(bo->bdev); |
| 903 | struct nouveau_bo *nvbo = nouveau_bo(bo); |
| 904 | struct ttm_mem_reg *old_mem = &bo->mem; |
| 905 | struct nouveau_tile_reg *new_tile = NULL; |
| 906 | int ret = 0; |
| 907 | |
Ben Skeggs | a4154bb | 2011-02-10 10:35:16 +1000 | [diff] [blame] | 908 | if (dev_priv->card_type < NV_50) { |
| 909 | ret = nouveau_bo_vm_bind(bo, new_mem, &new_tile); |
| 910 | if (ret) |
| 911 | return ret; |
| 912 | } |
Francisco Jerez | a0af9ad | 2009-12-11 16:51:09 +0100 | [diff] [blame] | 913 | |
Francisco Jerez | a0af9ad | 2009-12-11 16:51:09 +0100 | [diff] [blame] | 914 | /* Fake bo copy. */ |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 915 | if (old_mem->mem_type == TTM_PL_SYSTEM && !bo->ttm) { |
| 916 | BUG_ON(bo->mem.mm_node != NULL); |
| 917 | bo->mem = *new_mem; |
| 918 | new_mem->mm_node = NULL; |
Francisco Jerez | a0af9ad | 2009-12-11 16:51:09 +0100 | [diff] [blame] | 919 | goto out; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 920 | } |
| 921 | |
Ben Skeggs | b8a6a80 | 2010-08-27 11:55:43 +1000 | [diff] [blame] | 922 | /* Software copy if the card isn't up and running yet. */ |
Ben Skeggs | 183720b | 2010-12-09 15:17:10 +1000 | [diff] [blame] | 923 | if (!dev_priv->channel) { |
Ben Skeggs | b8a6a80 | 2010-08-27 11:55:43 +1000 | [diff] [blame] | 924 | ret = ttm_bo_move_memcpy(bo, evict, no_wait_reserve, no_wait_gpu, new_mem); |
| 925 | goto out; |
| 926 | } |
| 927 | |
Francisco Jerez | a0af9ad | 2009-12-11 16:51:09 +0100 | [diff] [blame] | 928 | /* Hardware assisted copy. */ |
| 929 | if (new_mem->mem_type == TTM_PL_SYSTEM) |
Jerome Glisse | 9d87fa2 | 2010-04-07 10:21:19 +0000 | [diff] [blame] | 930 | 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] | 931 | else if (old_mem->mem_type == TTM_PL_SYSTEM) |
Jerome Glisse | 9d87fa2 | 2010-04-07 10:21:19 +0000 | [diff] [blame] | 932 | 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] | 933 | else |
Jerome Glisse | 9d87fa2 | 2010-04-07 10:21:19 +0000 | [diff] [blame] | 934 | 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] | 935 | |
Francisco Jerez | a0af9ad | 2009-12-11 16:51:09 +0100 | [diff] [blame] | 936 | if (!ret) |
| 937 | goto out; |
| 938 | |
| 939 | /* Fallback to software copy. */ |
Jerome Glisse | 9d87fa2 | 2010-04-07 10:21:19 +0000 | [diff] [blame] | 940 | 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] | 941 | |
| 942 | out: |
Ben Skeggs | a4154bb | 2011-02-10 10:35:16 +1000 | [diff] [blame] | 943 | if (dev_priv->card_type < NV_50) { |
| 944 | if (ret) |
| 945 | nouveau_bo_vm_cleanup(bo, NULL, &new_tile); |
| 946 | else |
| 947 | nouveau_bo_vm_cleanup(bo, new_tile, &nvbo->tile); |
| 948 | } |
Francisco Jerez | a0af9ad | 2009-12-11 16:51:09 +0100 | [diff] [blame] | 949 | |
| 950 | return ret; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 951 | } |
| 952 | |
| 953 | static int |
| 954 | nouveau_bo_verify_access(struct ttm_buffer_object *bo, struct file *filp) |
| 955 | { |
| 956 | return 0; |
| 957 | } |
| 958 | |
Jerome Glisse | f32f02f | 2010-04-09 14:39:25 +0200 | [diff] [blame] | 959 | static int |
| 960 | nouveau_ttm_io_mem_reserve(struct ttm_bo_device *bdev, struct ttm_mem_reg *mem) |
| 961 | { |
| 962 | struct ttm_mem_type_manager *man = &bdev->man[mem->mem_type]; |
| 963 | struct drm_nouveau_private *dev_priv = nouveau_bdev(bdev); |
| 964 | struct drm_device *dev = dev_priv->dev; |
Ben Skeggs | f869ef8 | 2010-11-15 11:53:16 +1000 | [diff] [blame] | 965 | int ret; |
Jerome Glisse | f32f02f | 2010-04-09 14:39:25 +0200 | [diff] [blame] | 966 | |
| 967 | mem->bus.addr = NULL; |
| 968 | mem->bus.offset = 0; |
| 969 | mem->bus.size = mem->num_pages << PAGE_SHIFT; |
| 970 | mem->bus.base = 0; |
| 971 | mem->bus.is_iomem = false; |
| 972 | if (!(man->flags & TTM_MEMTYPE_FLAG_MAPPABLE)) |
| 973 | return -EINVAL; |
| 974 | switch (mem->mem_type) { |
| 975 | case TTM_PL_SYSTEM: |
| 976 | /* System memory */ |
| 977 | return 0; |
| 978 | case TTM_PL_TT: |
| 979 | #if __OS_HAS_AGP |
| 980 | if (dev_priv->gart_info.type == NOUVEAU_GART_AGP) { |
Ben Skeggs | d961db7 | 2010-08-05 10:48:18 +1000 | [diff] [blame] | 981 | mem->bus.offset = mem->start << PAGE_SHIFT; |
Jerome Glisse | f32f02f | 2010-04-09 14:39:25 +0200 | [diff] [blame] | 982 | mem->bus.base = dev_priv->gart_info.aper_base; |
| 983 | mem->bus.is_iomem = true; |
| 984 | } |
| 985 | #endif |
| 986 | break; |
| 987 | case TTM_PL_VRAM: |
Ben Skeggs | f869ef8 | 2010-11-15 11:53:16 +1000 | [diff] [blame] | 988 | { |
Ben Skeggs | d5f4239 | 2011-02-10 12:22:52 +1000 | [diff] [blame] | 989 | struct nouveau_mem *node = mem->mm_node; |
Ben Skeggs | 8984e04 | 2010-11-15 11:48:33 +1000 | [diff] [blame] | 990 | u8 page_shift; |
Ben Skeggs | f869ef8 | 2010-11-15 11:53:16 +1000 | [diff] [blame] | 991 | |
| 992 | if (!dev_priv->bar1_vm) { |
| 993 | mem->bus.offset = mem->start << PAGE_SHIFT; |
| 994 | mem->bus.base = pci_resource_start(dev->pdev, 1); |
| 995 | mem->bus.is_iomem = true; |
| 996 | break; |
| 997 | } |
| 998 | |
Ben Skeggs | 2e9733f | 2011-07-02 20:28:49 +1000 | [diff] [blame] | 999 | if (dev_priv->card_type >= NV_C0) |
Ben Skeggs | d5f4239 | 2011-02-10 12:22:52 +1000 | [diff] [blame] | 1000 | page_shift = node->page_shift; |
Ben Skeggs | 8984e04 | 2010-11-15 11:48:33 +1000 | [diff] [blame] | 1001 | else |
| 1002 | page_shift = 12; |
| 1003 | |
Ben Skeggs | 4c74eb7 | 2010-11-10 14:10:04 +1000 | [diff] [blame] | 1004 | ret = nouveau_vm_get(dev_priv->bar1_vm, mem->bus.size, |
Ben Skeggs | 8984e04 | 2010-11-15 11:48:33 +1000 | [diff] [blame] | 1005 | page_shift, NV_MEM_ACCESS_RW, |
Ben Skeggs | d5f4239 | 2011-02-10 12:22:52 +1000 | [diff] [blame] | 1006 | &node->bar_vma); |
Ben Skeggs | f869ef8 | 2010-11-15 11:53:16 +1000 | [diff] [blame] | 1007 | if (ret) |
| 1008 | return ret; |
| 1009 | |
Ben Skeggs | d5f4239 | 2011-02-10 12:22:52 +1000 | [diff] [blame] | 1010 | nouveau_vm_map(&node->bar_vma, node); |
Ben Skeggs | f869ef8 | 2010-11-15 11:53:16 +1000 | [diff] [blame] | 1011 | if (ret) { |
Ben Skeggs | d5f4239 | 2011-02-10 12:22:52 +1000 | [diff] [blame] | 1012 | nouveau_vm_put(&node->bar_vma); |
Ben Skeggs | f869ef8 | 2010-11-15 11:53:16 +1000 | [diff] [blame] | 1013 | return ret; |
| 1014 | } |
| 1015 | |
Ben Skeggs | d5f4239 | 2011-02-10 12:22:52 +1000 | [diff] [blame] | 1016 | mem->bus.offset = node->bar_vma.offset; |
Ben Skeggs | 8984e04 | 2010-11-15 11:48:33 +1000 | [diff] [blame] | 1017 | if (dev_priv->card_type == NV_50) /*XXX*/ |
| 1018 | mem->bus.offset -= 0x0020000000ULL; |
Jordan Crouse | 01d73a6 | 2010-05-27 13:40:24 -0600 | [diff] [blame] | 1019 | mem->bus.base = pci_resource_start(dev->pdev, 1); |
Jerome Glisse | f32f02f | 2010-04-09 14:39:25 +0200 | [diff] [blame] | 1020 | mem->bus.is_iomem = true; |
Ben Skeggs | f869ef8 | 2010-11-15 11:53:16 +1000 | [diff] [blame] | 1021 | } |
Jerome Glisse | f32f02f | 2010-04-09 14:39:25 +0200 | [diff] [blame] | 1022 | break; |
| 1023 | default: |
| 1024 | return -EINVAL; |
| 1025 | } |
| 1026 | return 0; |
| 1027 | } |
| 1028 | |
| 1029 | static void |
| 1030 | nouveau_ttm_io_mem_free(struct ttm_bo_device *bdev, struct ttm_mem_reg *mem) |
| 1031 | { |
Ben Skeggs | f869ef8 | 2010-11-15 11:53:16 +1000 | [diff] [blame] | 1032 | struct drm_nouveau_private *dev_priv = nouveau_bdev(bdev); |
Ben Skeggs | d5f4239 | 2011-02-10 12:22:52 +1000 | [diff] [blame] | 1033 | struct nouveau_mem *node = mem->mm_node; |
Ben Skeggs | f869ef8 | 2010-11-15 11:53:16 +1000 | [diff] [blame] | 1034 | |
| 1035 | if (!dev_priv->bar1_vm || mem->mem_type != TTM_PL_VRAM) |
| 1036 | return; |
| 1037 | |
Ben Skeggs | d5f4239 | 2011-02-10 12:22:52 +1000 | [diff] [blame] | 1038 | if (!node->bar_vma.node) |
Ben Skeggs | f869ef8 | 2010-11-15 11:53:16 +1000 | [diff] [blame] | 1039 | return; |
| 1040 | |
Ben Skeggs | d5f4239 | 2011-02-10 12:22:52 +1000 | [diff] [blame] | 1041 | nouveau_vm_unmap(&node->bar_vma); |
| 1042 | nouveau_vm_put(&node->bar_vma); |
Jerome Glisse | f32f02f | 2010-04-09 14:39:25 +0200 | [diff] [blame] | 1043 | } |
| 1044 | |
| 1045 | static int |
| 1046 | nouveau_ttm_fault_reserve_notify(struct ttm_buffer_object *bo) |
| 1047 | { |
Ben Skeggs | e1429b4 | 2010-09-10 11:12:25 +1000 | [diff] [blame] | 1048 | struct drm_nouveau_private *dev_priv = nouveau_bdev(bo->bdev); |
| 1049 | struct nouveau_bo *nvbo = nouveau_bo(bo); |
| 1050 | |
| 1051 | /* as long as the bo isn't in vram, and isn't tiled, we've got |
| 1052 | * nothing to do here. |
| 1053 | */ |
| 1054 | if (bo->mem.mem_type != TTM_PL_VRAM) { |
Francisco Jerez | f13b326 | 2010-10-10 06:01:08 +0200 | [diff] [blame] | 1055 | if (dev_priv->card_type < NV_50 || |
| 1056 | !nouveau_bo_tile_layout(nvbo)) |
Ben Skeggs | e1429b4 | 2010-09-10 11:12:25 +1000 | [diff] [blame] | 1057 | return 0; |
| 1058 | } |
| 1059 | |
| 1060 | /* make sure bo is in mappable vram */ |
Ben Skeggs | d961db7 | 2010-08-05 10:48:18 +1000 | [diff] [blame] | 1061 | 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] | 1062 | return 0; |
| 1063 | |
| 1064 | |
| 1065 | nvbo->placement.fpfn = 0; |
| 1066 | nvbo->placement.lpfn = dev_priv->fb_mappable_pages; |
Dave Airlie | c284815 | 2012-05-18 15:31:12 +0100 | [diff] [blame] | 1067 | nouveau_bo_placement_set(nvbo, TTM_PL_FLAG_VRAM, 0); |
Ben Skeggs | 7a45d76 | 2010-11-22 08:50:27 +1000 | [diff] [blame] | 1068 | return nouveau_bo_validate(nvbo, false, true, false); |
Jerome Glisse | f32f02f | 2010-04-09 14:39:25 +0200 | [diff] [blame] | 1069 | } |
| 1070 | |
Francisco Jerez | 332b242 | 2010-10-20 23:35:40 +0200 | [diff] [blame] | 1071 | void |
| 1072 | nouveau_bo_fence(struct nouveau_bo *nvbo, struct nouveau_fence *fence) |
| 1073 | { |
Francisco Jerez | 23c45e8 | 2010-10-28 23:10:29 +0200 | [diff] [blame] | 1074 | struct nouveau_fence *old_fence; |
Francisco Jerez | 332b242 | 2010-10-20 23:35:40 +0200 | [diff] [blame] | 1075 | |
| 1076 | if (likely(fence)) |
Francisco Jerez | 23c45e8 | 2010-10-28 23:10:29 +0200 | [diff] [blame] | 1077 | nouveau_fence_ref(fence); |
Francisco Jerez | 332b242 | 2010-10-20 23:35:40 +0200 | [diff] [blame] | 1078 | |
Francisco Jerez | 23c45e8 | 2010-10-28 23:10:29 +0200 | [diff] [blame] | 1079 | spin_lock(&nvbo->bo.bdev->fence_lock); |
| 1080 | old_fence = nvbo->bo.sync_obj; |
| 1081 | nvbo->bo.sync_obj = fence; |
Francisco Jerez | 332b242 | 2010-10-20 23:35:40 +0200 | [diff] [blame] | 1082 | spin_unlock(&nvbo->bo.bdev->fence_lock); |
Francisco Jerez | 23c45e8 | 2010-10-28 23:10:29 +0200 | [diff] [blame] | 1083 | |
| 1084 | nouveau_fence_unref(&old_fence); |
Francisco Jerez | 332b242 | 2010-10-20 23:35:40 +0200 | [diff] [blame] | 1085 | } |
| 1086 | |
Konrad Rzeszutek Wilk | 3230cfc | 2011-10-17 17:14:26 -0400 | [diff] [blame] | 1087 | static int |
| 1088 | nouveau_ttm_tt_populate(struct ttm_tt *ttm) |
| 1089 | { |
Jerome Glisse | 8e7e705 | 2011-11-09 17:15:26 -0500 | [diff] [blame] | 1090 | struct ttm_dma_tt *ttm_dma = (void *)ttm; |
Konrad Rzeszutek Wilk | 3230cfc | 2011-10-17 17:14:26 -0400 | [diff] [blame] | 1091 | struct drm_nouveau_private *dev_priv; |
| 1092 | struct drm_device *dev; |
| 1093 | unsigned i; |
| 1094 | int r; |
Dave Airlie | 22b33e8 | 2012-04-02 11:53:06 +0100 | [diff] [blame] | 1095 | bool slave = !!(ttm->page_flags & TTM_PAGE_FLAG_SG); |
Konrad Rzeszutek Wilk | 3230cfc | 2011-10-17 17:14:26 -0400 | [diff] [blame] | 1096 | |
| 1097 | if (ttm->state != tt_unpopulated) |
| 1098 | return 0; |
| 1099 | |
Dave Airlie | 22b33e8 | 2012-04-02 11:53:06 +0100 | [diff] [blame] | 1100 | if (slave && ttm->sg) { |
| 1101 | /* make userspace faulting work */ |
| 1102 | drm_prime_sg_to_page_addr_arrays(ttm->sg, ttm->pages, |
| 1103 | ttm_dma->dma_address, ttm->num_pages); |
| 1104 | ttm->state = tt_unbound; |
| 1105 | return 0; |
| 1106 | } |
| 1107 | |
Konrad Rzeszutek Wilk | 3230cfc | 2011-10-17 17:14:26 -0400 | [diff] [blame] | 1108 | dev_priv = nouveau_bdev(ttm->bdev); |
| 1109 | dev = dev_priv->dev; |
| 1110 | |
Jerome Glisse | dea7e0a | 2012-01-03 17:37:37 -0500 | [diff] [blame] | 1111 | #if __OS_HAS_AGP |
| 1112 | if (dev_priv->gart_info.type == NOUVEAU_GART_AGP) { |
| 1113 | return ttm_agp_tt_populate(ttm); |
| 1114 | } |
| 1115 | #endif |
| 1116 | |
Konrad Rzeszutek Wilk | 3230cfc | 2011-10-17 17:14:26 -0400 | [diff] [blame] | 1117 | #ifdef CONFIG_SWIOTLB |
| 1118 | if (swiotlb_nr_tbl()) { |
Jerome Glisse | 8e7e705 | 2011-11-09 17:15:26 -0500 | [diff] [blame] | 1119 | return ttm_dma_populate((void *)ttm, dev->dev); |
Konrad Rzeszutek Wilk | 3230cfc | 2011-10-17 17:14:26 -0400 | [diff] [blame] | 1120 | } |
| 1121 | #endif |
| 1122 | |
| 1123 | r = ttm_pool_populate(ttm); |
| 1124 | if (r) { |
| 1125 | return r; |
| 1126 | } |
| 1127 | |
| 1128 | for (i = 0; i < ttm->num_pages; i++) { |
Jerome Glisse | 8e7e705 | 2011-11-09 17:15:26 -0500 | [diff] [blame] | 1129 | ttm_dma->dma_address[i] = pci_map_page(dev->pdev, ttm->pages[i], |
Konrad Rzeszutek Wilk | 3230cfc | 2011-10-17 17:14:26 -0400 | [diff] [blame] | 1130 | 0, PAGE_SIZE, |
| 1131 | PCI_DMA_BIDIRECTIONAL); |
Jerome Glisse | 8e7e705 | 2011-11-09 17:15:26 -0500 | [diff] [blame] | 1132 | if (pci_dma_mapping_error(dev->pdev, ttm_dma->dma_address[i])) { |
Konrad Rzeszutek Wilk | 3230cfc | 2011-10-17 17:14:26 -0400 | [diff] [blame] | 1133 | while (--i) { |
Jerome Glisse | 8e7e705 | 2011-11-09 17:15:26 -0500 | [diff] [blame] | 1134 | pci_unmap_page(dev->pdev, ttm_dma->dma_address[i], |
Konrad Rzeszutek Wilk | 3230cfc | 2011-10-17 17:14:26 -0400 | [diff] [blame] | 1135 | PAGE_SIZE, PCI_DMA_BIDIRECTIONAL); |
Jerome Glisse | 8e7e705 | 2011-11-09 17:15:26 -0500 | [diff] [blame] | 1136 | ttm_dma->dma_address[i] = 0; |
Konrad Rzeszutek Wilk | 3230cfc | 2011-10-17 17:14:26 -0400 | [diff] [blame] | 1137 | } |
| 1138 | ttm_pool_unpopulate(ttm); |
| 1139 | return -EFAULT; |
| 1140 | } |
| 1141 | } |
| 1142 | return 0; |
| 1143 | } |
| 1144 | |
| 1145 | static void |
| 1146 | nouveau_ttm_tt_unpopulate(struct ttm_tt *ttm) |
| 1147 | { |
Jerome Glisse | 8e7e705 | 2011-11-09 17:15:26 -0500 | [diff] [blame] | 1148 | struct ttm_dma_tt *ttm_dma = (void *)ttm; |
Konrad Rzeszutek Wilk | 3230cfc | 2011-10-17 17:14:26 -0400 | [diff] [blame] | 1149 | struct drm_nouveau_private *dev_priv; |
| 1150 | struct drm_device *dev; |
| 1151 | unsigned i; |
Dave Airlie | 22b33e8 | 2012-04-02 11:53:06 +0100 | [diff] [blame] | 1152 | bool slave = !!(ttm->page_flags & TTM_PAGE_FLAG_SG); |
| 1153 | |
| 1154 | if (slave) |
| 1155 | return; |
Konrad Rzeszutek Wilk | 3230cfc | 2011-10-17 17:14:26 -0400 | [diff] [blame] | 1156 | |
| 1157 | dev_priv = nouveau_bdev(ttm->bdev); |
| 1158 | dev = dev_priv->dev; |
| 1159 | |
Jerome Glisse | dea7e0a | 2012-01-03 17:37:37 -0500 | [diff] [blame] | 1160 | #if __OS_HAS_AGP |
| 1161 | if (dev_priv->gart_info.type == NOUVEAU_GART_AGP) { |
| 1162 | ttm_agp_tt_unpopulate(ttm); |
| 1163 | return; |
| 1164 | } |
| 1165 | #endif |
| 1166 | |
Konrad Rzeszutek Wilk | 3230cfc | 2011-10-17 17:14:26 -0400 | [diff] [blame] | 1167 | #ifdef CONFIG_SWIOTLB |
| 1168 | if (swiotlb_nr_tbl()) { |
Jerome Glisse | 8e7e705 | 2011-11-09 17:15:26 -0500 | [diff] [blame] | 1169 | ttm_dma_unpopulate((void *)ttm, dev->dev); |
Konrad Rzeszutek Wilk | 3230cfc | 2011-10-17 17:14:26 -0400 | [diff] [blame] | 1170 | return; |
| 1171 | } |
| 1172 | #endif |
| 1173 | |
| 1174 | for (i = 0; i < ttm->num_pages; i++) { |
Jerome Glisse | 8e7e705 | 2011-11-09 17:15:26 -0500 | [diff] [blame] | 1175 | if (ttm_dma->dma_address[i]) { |
| 1176 | pci_unmap_page(dev->pdev, ttm_dma->dma_address[i], |
Konrad Rzeszutek Wilk | 3230cfc | 2011-10-17 17:14:26 -0400 | [diff] [blame] | 1177 | PAGE_SIZE, PCI_DMA_BIDIRECTIONAL); |
| 1178 | } |
| 1179 | } |
| 1180 | |
| 1181 | ttm_pool_unpopulate(ttm); |
| 1182 | } |
| 1183 | |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 1184 | struct ttm_bo_driver nouveau_bo_driver = { |
Jerome Glisse | 649bf3c | 2011-11-01 20:46:13 -0400 | [diff] [blame] | 1185 | .ttm_tt_create = &nouveau_ttm_tt_create, |
Konrad Rzeszutek Wilk | 3230cfc | 2011-10-17 17:14:26 -0400 | [diff] [blame] | 1186 | .ttm_tt_populate = &nouveau_ttm_tt_populate, |
| 1187 | .ttm_tt_unpopulate = &nouveau_ttm_tt_unpopulate, |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 1188 | .invalidate_caches = nouveau_bo_invalidate_caches, |
| 1189 | .init_mem_type = nouveau_bo_init_mem_type, |
| 1190 | .evict_flags = nouveau_bo_evict_flags, |
Ben Skeggs | a4154bb | 2011-02-10 10:35:16 +1000 | [diff] [blame] | 1191 | .move_notify = nouveau_bo_move_ntfy, |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 1192 | .move = nouveau_bo_move, |
| 1193 | .verify_access = nouveau_bo_verify_access, |
Marcin Slusarz | 382d62e | 2010-10-20 21:50:24 +0200 | [diff] [blame] | 1194 | .sync_obj_signaled = __nouveau_fence_signalled, |
| 1195 | .sync_obj_wait = __nouveau_fence_wait, |
| 1196 | .sync_obj_flush = __nouveau_fence_flush, |
| 1197 | .sync_obj_unref = __nouveau_fence_unref, |
| 1198 | .sync_obj_ref = __nouveau_fence_ref, |
Jerome Glisse | f32f02f | 2010-04-09 14:39:25 +0200 | [diff] [blame] | 1199 | .fault_reserve_notify = &nouveau_ttm_fault_reserve_notify, |
| 1200 | .io_mem_reserve = &nouveau_ttm_io_mem_reserve, |
| 1201 | .io_mem_free = &nouveau_ttm_io_mem_free, |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 1202 | }; |
| 1203 | |
Ben Skeggs | fd2871a | 2011-06-06 14:07:04 +1000 | [diff] [blame] | 1204 | struct nouveau_vma * |
| 1205 | nouveau_bo_vma_find(struct nouveau_bo *nvbo, struct nouveau_vm *vm) |
| 1206 | { |
| 1207 | struct nouveau_vma *vma; |
| 1208 | list_for_each_entry(vma, &nvbo->vma_list, head) { |
| 1209 | if (vma->vm == vm) |
| 1210 | return vma; |
| 1211 | } |
| 1212 | |
| 1213 | return NULL; |
| 1214 | } |
| 1215 | |
| 1216 | int |
| 1217 | nouveau_bo_vma_add(struct nouveau_bo *nvbo, struct nouveau_vm *vm, |
| 1218 | struct nouveau_vma *vma) |
| 1219 | { |
| 1220 | const u32 size = nvbo->bo.mem.num_pages << PAGE_SHIFT; |
| 1221 | struct nouveau_mem *node = nvbo->bo.mem.mm_node; |
| 1222 | int ret; |
| 1223 | |
| 1224 | ret = nouveau_vm_get(vm, size, nvbo->page_shift, |
| 1225 | NV_MEM_ACCESS_RW, vma); |
| 1226 | if (ret) |
| 1227 | return ret; |
| 1228 | |
| 1229 | if (nvbo->bo.mem.mem_type == TTM_PL_VRAM) |
| 1230 | nouveau_vm_map(vma, nvbo->bo.mem.mm_node); |
Dave Airlie | 22b33e8 | 2012-04-02 11:53:06 +0100 | [diff] [blame] | 1231 | else if (nvbo->bo.mem.mem_type == TTM_PL_TT) { |
| 1232 | if (node->sg) |
| 1233 | nouveau_vm_map_sg_table(vma, 0, size, node); |
| 1234 | else |
| 1235 | nouveau_vm_map_sg(vma, 0, size, node); |
| 1236 | } |
Ben Skeggs | fd2871a | 2011-06-06 14:07:04 +1000 | [diff] [blame] | 1237 | |
| 1238 | list_add_tail(&vma->head, &nvbo->vma_list); |
Ben Skeggs | 2fd3db6 | 2011-06-07 15:25:12 +1000 | [diff] [blame] | 1239 | vma->refcount = 1; |
Ben Skeggs | fd2871a | 2011-06-06 14:07:04 +1000 | [diff] [blame] | 1240 | return 0; |
| 1241 | } |
| 1242 | |
| 1243 | void |
| 1244 | nouveau_bo_vma_del(struct nouveau_bo *nvbo, struct nouveau_vma *vma) |
| 1245 | { |
| 1246 | if (vma->node) { |
| 1247 | if (nvbo->bo.mem.mem_type != TTM_PL_SYSTEM) { |
| 1248 | spin_lock(&nvbo->bo.bdev->fence_lock); |
Dave Airlie | 1717c0e | 2011-10-27 18:28:37 +0200 | [diff] [blame] | 1249 | ttm_bo_wait(&nvbo->bo, false, false, false); |
Ben Skeggs | fd2871a | 2011-06-06 14:07:04 +1000 | [diff] [blame] | 1250 | spin_unlock(&nvbo->bo.bdev->fence_lock); |
| 1251 | nouveau_vm_unmap(vma); |
| 1252 | } |
| 1253 | |
| 1254 | nouveau_vm_put(vma); |
| 1255 | list_del(&vma->head); |
| 1256 | } |
| 1257 | } |