Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2008 Ben Skeggs. |
| 3 | * All Rights Reserved. |
| 4 | * |
| 5 | * Permission is hereby granted, free of charge, to any person obtaining |
| 6 | * a copy of this software and associated documentation files (the |
| 7 | * "Software"), to deal in the Software without restriction, including |
| 8 | * without limitation the rights to use, copy, modify, merge, publish, |
| 9 | * distribute, sublicense, and/or sell copies of the Software, and to |
| 10 | * permit persons to whom the Software is furnished to do so, subject to |
| 11 | * the following conditions: |
| 12 | * |
| 13 | * The above copyright notice and this permission notice (including the |
| 14 | * next paragraph) shall be included in all copies or substantial |
| 15 | * portions of the Software. |
| 16 | * |
| 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
| 18 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
| 20 | * IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE |
| 21 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION |
| 22 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION |
| 23 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 24 | * |
| 25 | */ |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 26 | |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 27 | #include <linux/dma-buf.h> |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 28 | |
| 29 | #include <subdev/fb.h> |
| 30 | |
| 31 | #include "nouveau_drm.h" |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 32 | #include "nouveau_dma.h" |
Ben Skeggs | d375e7d5 | 2012-04-30 13:30:00 +1000 | [diff] [blame] | 33 | #include "nouveau_fence.h" |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 34 | #include "nouveau_abi16.h" |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 35 | |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 36 | #include "nouveau_ttm.h" |
| 37 | #include "nouveau_gem.h" |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 38 | |
| 39 | int |
| 40 | nouveau_gem_object_new(struct drm_gem_object *gem) |
| 41 | { |
| 42 | return 0; |
| 43 | } |
| 44 | |
| 45 | void |
| 46 | nouveau_gem_object_del(struct drm_gem_object *gem) |
| 47 | { |
| 48 | struct nouveau_bo *nvbo = gem->driver_private; |
| 49 | struct ttm_buffer_object *bo = &nvbo->bo; |
| 50 | |
| 51 | if (!nvbo) |
| 52 | return; |
| 53 | nvbo->gem = NULL; |
| 54 | |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 55 | if (unlikely(nvbo->pin_refcnt)) { |
| 56 | nvbo->pin_refcnt = 1; |
| 57 | nouveau_bo_unpin(nvbo); |
| 58 | } |
| 59 | |
Dave Airlie | 22b33e8 | 2012-04-02 11:53:06 +0100 | [diff] [blame] | 60 | if (gem->import_attach) |
| 61 | drm_prime_gem_destroy(gem, nvbo->bo.sg); |
| 62 | |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 63 | ttm_bo_unref(&bo); |
Daniel Vetter | fd632aa | 2010-04-09 19:05:05 +0000 | [diff] [blame] | 64 | |
| 65 | drm_gem_object_release(gem); |
| 66 | kfree(gem); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 67 | } |
| 68 | |
| 69 | int |
Ben Skeggs | 639212d | 2011-06-03 16:18:26 +1000 | [diff] [blame] | 70 | nouveau_gem_object_open(struct drm_gem_object *gem, struct drm_file *file_priv) |
| 71 | { |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 72 | struct nouveau_cli *cli = nouveau_cli(file_priv); |
Ben Skeggs | 2fd3db6 | 2011-06-07 15:25:12 +1000 | [diff] [blame] | 73 | struct nouveau_bo *nvbo = nouveau_gem_object(gem); |
| 74 | struct nouveau_vma *vma; |
| 75 | int ret; |
Ben Skeggs | 639212d | 2011-06-03 16:18:26 +1000 | [diff] [blame] | 76 | |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 77 | if (!cli->base.vm) |
Ben Skeggs | 639212d | 2011-06-03 16:18:26 +1000 | [diff] [blame] | 78 | return 0; |
| 79 | |
Ben Skeggs | 2fd3db6 | 2011-06-07 15:25:12 +1000 | [diff] [blame] | 80 | ret = ttm_bo_reserve(&nvbo->bo, false, false, false, 0); |
| 81 | if (ret) |
| 82 | return ret; |
| 83 | |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 84 | vma = nouveau_bo_vma_find(nvbo, cli->base.vm); |
Ben Skeggs | 2fd3db6 | 2011-06-07 15:25:12 +1000 | [diff] [blame] | 85 | if (!vma) { |
| 86 | vma = kzalloc(sizeof(*vma), GFP_KERNEL); |
| 87 | if (!vma) { |
| 88 | ret = -ENOMEM; |
| 89 | goto out; |
| 90 | } |
| 91 | |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 92 | ret = nouveau_bo_vma_add(nvbo, cli->base.vm, vma); |
Ben Skeggs | 2fd3db6 | 2011-06-07 15:25:12 +1000 | [diff] [blame] | 93 | if (ret) { |
| 94 | kfree(vma); |
| 95 | goto out; |
| 96 | } |
| 97 | } else { |
| 98 | vma->refcount++; |
| 99 | } |
| 100 | |
| 101 | out: |
| 102 | ttm_bo_unreserve(&nvbo->bo); |
| 103 | return ret; |
Ben Skeggs | 639212d | 2011-06-03 16:18:26 +1000 | [diff] [blame] | 104 | } |
| 105 | |
| 106 | void |
| 107 | nouveau_gem_object_close(struct drm_gem_object *gem, struct drm_file *file_priv) |
| 108 | { |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 109 | struct nouveau_cli *cli = nouveau_cli(file_priv); |
Ben Skeggs | 2fd3db6 | 2011-06-07 15:25:12 +1000 | [diff] [blame] | 110 | struct nouveau_bo *nvbo = nouveau_gem_object(gem); |
| 111 | struct nouveau_vma *vma; |
| 112 | int ret; |
Ben Skeggs | 639212d | 2011-06-03 16:18:26 +1000 | [diff] [blame] | 113 | |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 114 | if (!cli->base.vm) |
Ben Skeggs | 639212d | 2011-06-03 16:18:26 +1000 | [diff] [blame] | 115 | return; |
Ben Skeggs | 2fd3db6 | 2011-06-07 15:25:12 +1000 | [diff] [blame] | 116 | |
| 117 | ret = ttm_bo_reserve(&nvbo->bo, false, false, false, 0); |
| 118 | if (ret) |
| 119 | return; |
| 120 | |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 121 | vma = nouveau_bo_vma_find(nvbo, cli->base.vm); |
Ben Skeggs | 2fd3db6 | 2011-06-07 15:25:12 +1000 | [diff] [blame] | 122 | if (vma) { |
Marcin Slusarz | 8fe198b | 2011-06-23 16:34:30 +0200 | [diff] [blame] | 123 | if (--vma->refcount == 0) { |
Ben Skeggs | 2fd3db6 | 2011-06-07 15:25:12 +1000 | [diff] [blame] | 124 | nouveau_bo_vma_del(nvbo, vma); |
Marcin Slusarz | 8fe198b | 2011-06-23 16:34:30 +0200 | [diff] [blame] | 125 | kfree(vma); |
| 126 | } |
Ben Skeggs | 2fd3db6 | 2011-06-07 15:25:12 +1000 | [diff] [blame] | 127 | } |
| 128 | ttm_bo_unreserve(&nvbo->bo); |
Ben Skeggs | 639212d | 2011-06-03 16:18:26 +1000 | [diff] [blame] | 129 | } |
| 130 | |
| 131 | int |
Ben Skeggs | f6d4e62 | 2011-06-07 12:25:36 +1000 | [diff] [blame] | 132 | nouveau_gem_new(struct drm_device *dev, int size, int align, uint32_t domain, |
| 133 | uint32_t tile_mode, uint32_t tile_flags, |
| 134 | struct nouveau_bo **pnvbo) |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 135 | { |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 136 | struct nouveau_drm *drm = nouveau_drm(dev); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 137 | struct nouveau_bo *nvbo; |
Ben Skeggs | 6ba9a68 | 2011-02-10 14:42:08 +1000 | [diff] [blame] | 138 | u32 flags = 0; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 139 | int ret; |
| 140 | |
Ben Skeggs | 6ba9a68 | 2011-02-10 14:42:08 +1000 | [diff] [blame] | 141 | if (domain & NOUVEAU_GEM_DOMAIN_VRAM) |
| 142 | flags |= TTM_PL_FLAG_VRAM; |
| 143 | if (domain & NOUVEAU_GEM_DOMAIN_GART) |
| 144 | flags |= TTM_PL_FLAG_TT; |
| 145 | if (!flags || domain & NOUVEAU_GEM_DOMAIN_CPU) |
| 146 | flags |= TTM_PL_FLAG_SYSTEM; |
| 147 | |
Ben Skeggs | 7375c95 | 2011-06-07 14:21:29 +1000 | [diff] [blame] | 148 | ret = nouveau_bo_new(dev, size, align, flags, tile_mode, |
Dave Airlie | 22b33e8 | 2012-04-02 11:53:06 +0100 | [diff] [blame] | 149 | tile_flags, NULL, pnvbo); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 150 | if (ret) |
| 151 | return ret; |
| 152 | nvbo = *pnvbo; |
| 153 | |
Ben Skeggs | db5c8e2 | 2011-02-10 13:41:01 +1000 | [diff] [blame] | 154 | /* we restrict allowed domains on nv50+ to only the types |
| 155 | * that were requested at creation time. not possibly on |
| 156 | * earlier chips without busting the ABI. |
| 157 | */ |
| 158 | nvbo->valid_domains = NOUVEAU_GEM_DOMAIN_VRAM | |
| 159 | NOUVEAU_GEM_DOMAIN_GART; |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 160 | if (nv_device(drm->device)->card_type >= NV_50) |
Ben Skeggs | db5c8e2 | 2011-02-10 13:41:01 +1000 | [diff] [blame] | 161 | nvbo->valid_domains &= domain; |
| 162 | |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 163 | nvbo->gem = drm_gem_object_alloc(dev, nvbo->bo.mem.size); |
| 164 | if (!nvbo->gem) { |
| 165 | nouveau_bo_ref(NULL, pnvbo); |
| 166 | return -ENOMEM; |
| 167 | } |
| 168 | |
Jan Engelhardt | 5df2397 | 2011-04-04 01:25:18 +0200 | [diff] [blame] | 169 | nvbo->bo.persistent_swap_storage = nvbo->gem->filp; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 170 | nvbo->gem->driver_private = nvbo; |
| 171 | return 0; |
| 172 | } |
| 173 | |
| 174 | static int |
Ben Skeggs | e758a31 | 2011-06-07 13:28:11 +1000 | [diff] [blame] | 175 | nouveau_gem_info(struct drm_file *file_priv, struct drm_gem_object *gem, |
| 176 | struct drm_nouveau_gem_info *rep) |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 177 | { |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 178 | struct nouveau_cli *cli = nouveau_cli(file_priv); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 179 | struct nouveau_bo *nvbo = nouveau_gem_object(gem); |
Ben Skeggs | e758a31 | 2011-06-07 13:28:11 +1000 | [diff] [blame] | 180 | struct nouveau_vma *vma; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 181 | |
| 182 | if (nvbo->bo.mem.mem_type == TTM_PL_TT) |
| 183 | rep->domain = NOUVEAU_GEM_DOMAIN_GART; |
| 184 | else |
| 185 | rep->domain = NOUVEAU_GEM_DOMAIN_VRAM; |
| 186 | |
Ben Skeggs | e758a31 | 2011-06-07 13:28:11 +1000 | [diff] [blame] | 187 | rep->offset = nvbo->bo.offset; |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 188 | if (cli->base.vm) { |
| 189 | vma = nouveau_bo_vma_find(nvbo, cli->base.vm); |
Ben Skeggs | e758a31 | 2011-06-07 13:28:11 +1000 | [diff] [blame] | 190 | if (!vma) |
| 191 | return -EINVAL; |
| 192 | |
| 193 | rep->offset = vma->offset; |
| 194 | } |
| 195 | |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 196 | rep->size = nvbo->bo.mem.num_pages << PAGE_SHIFT; |
Ben Skeggs | d550c41 | 2011-02-16 08:41:56 +1000 | [diff] [blame] | 197 | rep->map_handle = nvbo->bo.addr_space_offset; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 198 | rep->tile_mode = nvbo->tile_mode; |
| 199 | rep->tile_flags = nvbo->tile_flags; |
| 200 | return 0; |
| 201 | } |
| 202 | |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 203 | int |
| 204 | nouveau_gem_ioctl_new(struct drm_device *dev, void *data, |
| 205 | struct drm_file *file_priv) |
| 206 | { |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 207 | struct nouveau_drm *drm = nouveau_drm(dev); |
| 208 | struct nouveau_fb *pfb = nouveau_fb(drm->device); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 209 | struct drm_nouveau_gem_new *req = data; |
| 210 | struct nouveau_bo *nvbo = NULL; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 211 | int ret = 0; |
| 212 | |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 213 | drm->ttm.bdev.dev_mapping = drm->dev->dev_mapping; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 214 | |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 215 | if (!pfb->memtype_valid(pfb, req->info.tile_flags)) { |
| 216 | NV_ERROR(drm, "bad page flags: 0x%08x\n", req->info.tile_flags); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 217 | return -EINVAL; |
Ben Skeggs | 60d2a88 | 2010-12-06 15:28:54 +1000 | [diff] [blame] | 218 | } |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 219 | |
Ben Skeggs | f6d4e62 | 2011-06-07 12:25:36 +1000 | [diff] [blame] | 220 | ret = nouveau_gem_new(dev, req->info.size, req->align, |
Ben Skeggs | 6ba9a68 | 2011-02-10 14:42:08 +1000 | [diff] [blame] | 221 | req->info.domain, req->info.tile_mode, |
| 222 | req->info.tile_flags, &nvbo); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 223 | if (ret) |
| 224 | return ret; |
| 225 | |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 226 | ret = drm_gem_handle_create(file_priv, nvbo->gem, &req->info.handle); |
Ben Skeggs | e758a31 | 2011-06-07 13:28:11 +1000 | [diff] [blame] | 227 | if (ret == 0) { |
| 228 | ret = nouveau_gem_info(file_priv, nvbo->gem, &req->info); |
| 229 | if (ret) |
| 230 | drm_gem_handle_delete(file_priv, req->info.handle); |
| 231 | } |
| 232 | |
Dave Airlie | 29d08b3 | 2010-09-27 16:17:17 +1000 | [diff] [blame] | 233 | /* drop reference from allocate - handle holds it now */ |
| 234 | drm_gem_object_unreference_unlocked(nvbo->gem); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 235 | return ret; |
| 236 | } |
| 237 | |
| 238 | static int |
| 239 | nouveau_gem_set_domain(struct drm_gem_object *gem, uint32_t read_domains, |
| 240 | uint32_t write_domains, uint32_t valid_domains) |
| 241 | { |
| 242 | struct nouveau_bo *nvbo = gem->driver_private; |
| 243 | struct ttm_buffer_object *bo = &nvbo->bo; |
Ben Skeggs | db5c8e2 | 2011-02-10 13:41:01 +1000 | [diff] [blame] | 244 | uint32_t domains = valid_domains & nvbo->valid_domains & |
Francisco Jerez | 78ad0f7 | 2010-03-18 13:07:47 +0100 | [diff] [blame] | 245 | (write_domains ? write_domains : read_domains); |
| 246 | uint32_t pref_flags = 0, valid_flags = 0; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 247 | |
Francisco Jerez | 78ad0f7 | 2010-03-18 13:07:47 +0100 | [diff] [blame] | 248 | if (!domains) |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 249 | return -EINVAL; |
| 250 | |
Francisco Jerez | 78ad0f7 | 2010-03-18 13:07:47 +0100 | [diff] [blame] | 251 | if (valid_domains & NOUVEAU_GEM_DOMAIN_VRAM) |
| 252 | valid_flags |= TTM_PL_FLAG_VRAM; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 253 | |
Francisco Jerez | 78ad0f7 | 2010-03-18 13:07:47 +0100 | [diff] [blame] | 254 | if (valid_domains & NOUVEAU_GEM_DOMAIN_GART) |
| 255 | valid_flags |= TTM_PL_FLAG_TT; |
| 256 | |
| 257 | if ((domains & NOUVEAU_GEM_DOMAIN_VRAM) && |
| 258 | bo->mem.mem_type == TTM_PL_VRAM) |
| 259 | pref_flags |= TTM_PL_FLAG_VRAM; |
| 260 | |
| 261 | else if ((domains & NOUVEAU_GEM_DOMAIN_GART) && |
| 262 | bo->mem.mem_type == TTM_PL_TT) |
| 263 | pref_flags |= TTM_PL_FLAG_TT; |
| 264 | |
| 265 | else if (domains & NOUVEAU_GEM_DOMAIN_VRAM) |
| 266 | pref_flags |= TTM_PL_FLAG_VRAM; |
| 267 | |
| 268 | else |
| 269 | pref_flags |= TTM_PL_FLAG_TT; |
| 270 | |
| 271 | nouveau_bo_placement_set(nvbo, pref_flags, valid_flags); |
| 272 | |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 273 | return 0; |
| 274 | } |
| 275 | |
| 276 | struct validate_op { |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 277 | struct list_head vram_list; |
| 278 | struct list_head gart_list; |
| 279 | struct list_head both_list; |
| 280 | }; |
| 281 | |
| 282 | static void |
| 283 | validate_fini_list(struct list_head *list, struct nouveau_fence *fence) |
| 284 | { |
| 285 | struct list_head *entry, *tmp; |
| 286 | struct nouveau_bo *nvbo; |
| 287 | |
| 288 | list_for_each_safe(entry, tmp, list) { |
| 289 | nvbo = list_entry(entry, struct nouveau_bo, entry); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 290 | |
Francisco Jerez | 332b242 | 2010-10-20 23:35:40 +0200 | [diff] [blame] | 291 | nouveau_bo_fence(nvbo, fence); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 292 | |
Ben Skeggs | a1606a9 | 2010-02-12 10:27:35 +1000 | [diff] [blame] | 293 | if (unlikely(nvbo->validate_mapped)) { |
| 294 | ttm_bo_kunmap(&nvbo->kmap); |
| 295 | nvbo->validate_mapped = false; |
| 296 | } |
| 297 | |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 298 | list_del(&nvbo->entry); |
| 299 | nvbo->reserved_by = NULL; |
| 300 | ttm_bo_unreserve(&nvbo->bo); |
Francisco Jerez | 374c3af | 2010-08-29 12:21:16 +0200 | [diff] [blame] | 301 | drm_gem_object_unreference_unlocked(nvbo->gem); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 302 | } |
| 303 | } |
| 304 | |
| 305 | static void |
Luca Barbieri | 234896a | 2010-01-06 04:02:45 +0100 | [diff] [blame] | 306 | validate_fini(struct validate_op *op, struct nouveau_fence* fence) |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 307 | { |
Luca Barbieri | 234896a | 2010-01-06 04:02:45 +0100 | [diff] [blame] | 308 | validate_fini_list(&op->vram_list, fence); |
| 309 | validate_fini_list(&op->gart_list, fence); |
| 310 | validate_fini_list(&op->both_list, fence); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 311 | } |
| 312 | |
| 313 | static int |
| 314 | validate_init(struct nouveau_channel *chan, struct drm_file *file_priv, |
| 315 | struct drm_nouveau_gem_pushbuf_bo *pbbo, |
| 316 | int nr_buffers, struct validate_op *op) |
| 317 | { |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 318 | struct drm_device *dev = chan->drm->dev; |
| 319 | struct nouveau_drm *drm = nouveau_drm(dev); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 320 | uint32_t sequence; |
| 321 | int trycnt = 0; |
| 322 | int ret, i; |
Maarten Lankhorst | c354c89 | 2013-01-15 14:57:20 +0100 | [diff] [blame^] | 323 | struct nouveau_bo *res_bo = NULL; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 324 | |
Maarten Lankhorst | 979ee29 | 2013-01-15 14:54:22 +0100 | [diff] [blame] | 325 | sequence = atomic_add_return(1, &drm->ttm.validate_sequence); |
Maarten Lankhorst | c354c89 | 2013-01-15 14:57:20 +0100 | [diff] [blame^] | 326 | retry: |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 327 | if (++trycnt > 100000) { |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 328 | NV_ERROR(drm, "%s failed and gave up.\n", __func__); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 329 | return -EINVAL; |
| 330 | } |
| 331 | |
| 332 | for (i = 0; i < nr_buffers; i++) { |
| 333 | struct drm_nouveau_gem_pushbuf_bo *b = &pbbo[i]; |
| 334 | struct drm_gem_object *gem; |
| 335 | struct nouveau_bo *nvbo; |
| 336 | |
| 337 | gem = drm_gem_object_lookup(dev, file_priv, b->handle); |
| 338 | if (!gem) { |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 339 | NV_ERROR(drm, "Unknown handle 0x%08x\n", b->handle); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 340 | validate_fini(op, NULL); |
Chris Wilson | bf79cb9 | 2010-08-04 14:19:46 +0100 | [diff] [blame] | 341 | return -ENOENT; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 342 | } |
| 343 | nvbo = gem->driver_private; |
Maarten Lankhorst | c354c89 | 2013-01-15 14:57:20 +0100 | [diff] [blame^] | 344 | if (nvbo == res_bo) { |
| 345 | res_bo = NULL; |
| 346 | drm_gem_object_unreference_unlocked(gem); |
| 347 | continue; |
| 348 | } |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 349 | |
| 350 | if (nvbo->reserved_by && nvbo->reserved_by == file_priv) { |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 351 | NV_ERROR(drm, "multiple instances of buffer %d on " |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 352 | "validation list\n", b->handle); |
Ben Skeggs | 5086f69 | 2012-06-25 18:04:27 +1000 | [diff] [blame] | 353 | drm_gem_object_unreference_unlocked(gem); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 354 | validate_fini(op, NULL); |
| 355 | return -EINVAL; |
| 356 | } |
| 357 | |
Ben Skeggs | 938c40e | 2010-10-12 09:54:54 +1000 | [diff] [blame] | 358 | ret = ttm_bo_reserve(&nvbo->bo, true, false, true, sequence); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 359 | if (ret) { |
| 360 | validate_fini(op, NULL); |
Maarten Lankhorst | c354c89 | 2013-01-15 14:57:20 +0100 | [diff] [blame^] | 361 | if (unlikely(ret == -EAGAIN)) { |
| 362 | sequence = atomic_add_return(1, &drm->ttm.validate_sequence); |
| 363 | ret = ttm_bo_reserve_slowpath(&nvbo->bo, true, |
| 364 | sequence); |
| 365 | if (!ret) |
| 366 | res_bo = nvbo; |
| 367 | } |
Ben Skeggs | 938c40e | 2010-10-12 09:54:54 +1000 | [diff] [blame] | 368 | if (unlikely(ret)) { |
Maarten Lankhorst | c354c89 | 2013-01-15 14:57:20 +0100 | [diff] [blame^] | 369 | drm_gem_object_unreference_unlocked(gem); |
Ben Skeggs | 938c40e | 2010-10-12 09:54:54 +1000 | [diff] [blame] | 370 | if (ret != -ERESTARTSYS) |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 371 | NV_ERROR(drm, "fail reserve\n"); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 372 | return ret; |
Ben Skeggs | a1606a9 | 2010-02-12 10:27:35 +1000 | [diff] [blame] | 373 | } |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 374 | } |
| 375 | |
Ben Skeggs | a1606a9 | 2010-02-12 10:27:35 +1000 | [diff] [blame] | 376 | b->user_priv = (uint64_t)(unsigned long)nvbo; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 377 | nvbo->reserved_by = file_priv; |
| 378 | nvbo->pbbo_index = i; |
| 379 | if ((b->valid_domains & NOUVEAU_GEM_DOMAIN_VRAM) && |
| 380 | (b->valid_domains & NOUVEAU_GEM_DOMAIN_GART)) |
| 381 | list_add_tail(&nvbo->entry, &op->both_list); |
| 382 | else |
| 383 | if (b->valid_domains & NOUVEAU_GEM_DOMAIN_VRAM) |
| 384 | list_add_tail(&nvbo->entry, &op->vram_list); |
| 385 | else |
| 386 | if (b->valid_domains & NOUVEAU_GEM_DOMAIN_GART) |
| 387 | list_add_tail(&nvbo->entry, &op->gart_list); |
| 388 | else { |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 389 | NV_ERROR(drm, "invalid valid domains: 0x%08x\n", |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 390 | b->valid_domains); |
Ben Skeggs | 0208843 | 2010-01-21 15:03:23 +1000 | [diff] [blame] | 391 | list_add_tail(&nvbo->entry, &op->both_list); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 392 | validate_fini(op, NULL); |
| 393 | return -EINVAL; |
| 394 | } |
Maarten Lankhorst | c354c89 | 2013-01-15 14:57:20 +0100 | [diff] [blame^] | 395 | if (nvbo == res_bo) |
| 396 | goto retry; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 397 | } |
| 398 | |
| 399 | return 0; |
| 400 | } |
| 401 | |
| 402 | static int |
Ben Skeggs | 525895b | 2012-01-10 10:18:28 +1000 | [diff] [blame] | 403 | validate_sync(struct nouveau_channel *chan, struct nouveau_bo *nvbo) |
| 404 | { |
| 405 | struct nouveau_fence *fence = NULL; |
| 406 | int ret = 0; |
| 407 | |
| 408 | spin_lock(&nvbo->bo.bdev->fence_lock); |
| 409 | if (nvbo->bo.sync_obj) |
| 410 | fence = nouveau_fence_ref(nvbo->bo.sync_obj); |
| 411 | spin_unlock(&nvbo->bo.bdev->fence_lock); |
| 412 | |
| 413 | if (fence) { |
| 414 | ret = nouveau_fence_sync(fence, chan); |
| 415 | nouveau_fence_unref(&fence); |
| 416 | } |
| 417 | |
| 418 | return ret; |
| 419 | } |
| 420 | |
| 421 | static int |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 422 | validate_list(struct nouveau_channel *chan, struct list_head *list, |
| 423 | struct drm_nouveau_gem_pushbuf_bo *pbbo, uint64_t user_pbbo_ptr) |
| 424 | { |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 425 | struct nouveau_drm *drm = chan->drm; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 426 | struct drm_nouveau_gem_pushbuf_bo __user *upbbo = |
| 427 | (void __force __user *)(uintptr_t)user_pbbo_ptr; |
| 428 | struct nouveau_bo *nvbo; |
| 429 | int ret, relocs = 0; |
| 430 | |
| 431 | list_for_each_entry(nvbo, list, entry) { |
| 432 | struct drm_nouveau_gem_pushbuf_bo *b = &pbbo[nvbo->pbbo_index]; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 433 | |
Ben Skeggs | 525895b | 2012-01-10 10:18:28 +1000 | [diff] [blame] | 434 | ret = validate_sync(chan, nvbo); |
Ben Skeggs | 415e618 | 2010-07-23 09:06:52 +1000 | [diff] [blame] | 435 | if (unlikely(ret)) { |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 436 | NV_ERROR(drm, "fail pre-validate sync\n"); |
Ben Skeggs | 415e618 | 2010-07-23 09:06:52 +1000 | [diff] [blame] | 437 | return ret; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 438 | } |
| 439 | |
| 440 | ret = nouveau_gem_set_domain(nvbo->gem, b->read_domains, |
| 441 | b->write_domains, |
| 442 | b->valid_domains); |
Ben Skeggs | a1606a9 | 2010-02-12 10:27:35 +1000 | [diff] [blame] | 443 | if (unlikely(ret)) { |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 444 | NV_ERROR(drm, "fail set_domain\n"); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 445 | return ret; |
Ben Skeggs | a1606a9 | 2010-02-12 10:27:35 +1000 | [diff] [blame] | 446 | } |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 447 | |
Maarten Lankhorst | 97a875c | 2012-11-28 11:25:44 +0000 | [diff] [blame] | 448 | ret = nouveau_bo_validate(nvbo, true, false); |
Ben Skeggs | a1606a9 | 2010-02-12 10:27:35 +1000 | [diff] [blame] | 449 | if (unlikely(ret)) { |
Ben Skeggs | 938c40e | 2010-10-12 09:54:54 +1000 | [diff] [blame] | 450 | if (ret != -ERESTARTSYS) |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 451 | NV_ERROR(drm, "fail ttm_validate\n"); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 452 | return ret; |
Ben Skeggs | a1606a9 | 2010-02-12 10:27:35 +1000 | [diff] [blame] | 453 | } |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 454 | |
Ben Skeggs | 525895b | 2012-01-10 10:18:28 +1000 | [diff] [blame] | 455 | ret = validate_sync(chan, nvbo); |
Ben Skeggs | 415e618 | 2010-07-23 09:06:52 +1000 | [diff] [blame] | 456 | if (unlikely(ret)) { |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 457 | NV_ERROR(drm, "fail post-validate sync\n"); |
Ben Skeggs | 415e618 | 2010-07-23 09:06:52 +1000 | [diff] [blame] | 458 | return ret; |
| 459 | } |
| 460 | |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 461 | if (nv_device(drm->device)->card_type < NV_50) { |
Ben Skeggs | a3fcd0a | 2011-06-07 11:12:39 +1000 | [diff] [blame] | 462 | if (nvbo->bo.offset == b->presumed.offset && |
| 463 | ((nvbo->bo.mem.mem_type == TTM_PL_VRAM && |
| 464 | b->presumed.domain & NOUVEAU_GEM_DOMAIN_VRAM) || |
| 465 | (nvbo->bo.mem.mem_type == TTM_PL_TT && |
| 466 | b->presumed.domain & NOUVEAU_GEM_DOMAIN_GART))) |
| 467 | continue; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 468 | |
Ben Skeggs | a3fcd0a | 2011-06-07 11:12:39 +1000 | [diff] [blame] | 469 | if (nvbo->bo.mem.mem_type == TTM_PL_TT) |
| 470 | b->presumed.domain = NOUVEAU_GEM_DOMAIN_GART; |
| 471 | else |
| 472 | b->presumed.domain = NOUVEAU_GEM_DOMAIN_VRAM; |
| 473 | b->presumed.offset = nvbo->bo.offset; |
| 474 | b->presumed.valid = 0; |
| 475 | relocs++; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 476 | |
Ben Skeggs | a3fcd0a | 2011-06-07 11:12:39 +1000 | [diff] [blame] | 477 | if (DRM_COPY_TO_USER(&upbbo[nvbo->pbbo_index].presumed, |
| 478 | &b->presumed, sizeof(b->presumed))) |
| 479 | return -EFAULT; |
| 480 | } |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 481 | } |
| 482 | |
| 483 | return relocs; |
| 484 | } |
| 485 | |
| 486 | static int |
| 487 | nouveau_gem_pushbuf_validate(struct nouveau_channel *chan, |
| 488 | struct drm_file *file_priv, |
| 489 | struct drm_nouveau_gem_pushbuf_bo *pbbo, |
| 490 | uint64_t user_buffers, int nr_buffers, |
| 491 | struct validate_op *op, int *apply_relocs) |
| 492 | { |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 493 | struct nouveau_drm *drm = chan->drm; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 494 | int ret, relocs = 0; |
| 495 | |
| 496 | INIT_LIST_HEAD(&op->vram_list); |
| 497 | INIT_LIST_HEAD(&op->gart_list); |
| 498 | INIT_LIST_HEAD(&op->both_list); |
| 499 | |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 500 | if (nr_buffers == 0) |
| 501 | return 0; |
| 502 | |
| 503 | ret = validate_init(chan, file_priv, pbbo, nr_buffers, op); |
Ben Skeggs | a1606a9 | 2010-02-12 10:27:35 +1000 | [diff] [blame] | 504 | if (unlikely(ret)) { |
Ben Skeggs | 938c40e | 2010-10-12 09:54:54 +1000 | [diff] [blame] | 505 | if (ret != -ERESTARTSYS) |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 506 | NV_ERROR(drm, "validate_init\n"); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 507 | return ret; |
Ben Skeggs | a1606a9 | 2010-02-12 10:27:35 +1000 | [diff] [blame] | 508 | } |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 509 | |
| 510 | ret = validate_list(chan, &op->vram_list, pbbo, user_buffers); |
| 511 | if (unlikely(ret < 0)) { |
Ben Skeggs | 938c40e | 2010-10-12 09:54:54 +1000 | [diff] [blame] | 512 | if (ret != -ERESTARTSYS) |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 513 | NV_ERROR(drm, "validate vram_list\n"); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 514 | validate_fini(op, NULL); |
| 515 | return ret; |
| 516 | } |
| 517 | relocs += ret; |
| 518 | |
| 519 | ret = validate_list(chan, &op->gart_list, pbbo, user_buffers); |
| 520 | if (unlikely(ret < 0)) { |
Ben Skeggs | 938c40e | 2010-10-12 09:54:54 +1000 | [diff] [blame] | 521 | if (ret != -ERESTARTSYS) |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 522 | NV_ERROR(drm, "validate gart_list\n"); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 523 | validate_fini(op, NULL); |
| 524 | return ret; |
| 525 | } |
| 526 | relocs += ret; |
| 527 | |
| 528 | ret = validate_list(chan, &op->both_list, pbbo, user_buffers); |
| 529 | if (unlikely(ret < 0)) { |
Ben Skeggs | 938c40e | 2010-10-12 09:54:54 +1000 | [diff] [blame] | 530 | if (ret != -ERESTARTSYS) |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 531 | NV_ERROR(drm, "validate both_list\n"); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 532 | validate_fini(op, NULL); |
| 533 | return ret; |
| 534 | } |
| 535 | relocs += ret; |
| 536 | |
| 537 | *apply_relocs = relocs; |
| 538 | return 0; |
| 539 | } |
| 540 | |
| 541 | static inline void * |
| 542 | u_memcpya(uint64_t user, unsigned nmemb, unsigned size) |
| 543 | { |
| 544 | void *mem; |
| 545 | void __user *userptr = (void __force __user *)(uintptr_t)user; |
| 546 | |
| 547 | mem = kmalloc(nmemb * size, GFP_KERNEL); |
| 548 | if (!mem) |
| 549 | return ERR_PTR(-ENOMEM); |
| 550 | |
| 551 | if (DRM_COPY_FROM_USER(mem, userptr, nmemb * size)) { |
| 552 | kfree(mem); |
| 553 | return ERR_PTR(-EFAULT); |
| 554 | } |
| 555 | |
| 556 | return mem; |
| 557 | } |
| 558 | |
| 559 | static int |
Ben Skeggs | a1606a9 | 2010-02-12 10:27:35 +1000 | [diff] [blame] | 560 | nouveau_gem_pushbuf_reloc_apply(struct drm_device *dev, |
| 561 | struct drm_nouveau_gem_pushbuf *req, |
| 562 | struct drm_nouveau_gem_pushbuf_bo *bo) |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 563 | { |
Ben Skeggs | 77145f1 | 2012-07-31 16:16:21 +1000 | [diff] [blame] | 564 | struct nouveau_drm *drm = nouveau_drm(dev); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 565 | struct drm_nouveau_gem_pushbuf_reloc *reloc = NULL; |
Luca Barbieri | 12f735b | 2010-01-10 20:10:53 +0100 | [diff] [blame] | 566 | int ret = 0; |
| 567 | unsigned i; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 568 | |
Ben Skeggs | a1606a9 | 2010-02-12 10:27:35 +1000 | [diff] [blame] | 569 | reloc = u_memcpya(req->relocs, req->nr_relocs, sizeof(*reloc)); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 570 | if (IS_ERR(reloc)) |
| 571 | return PTR_ERR(reloc); |
| 572 | |
Ben Skeggs | a1606a9 | 2010-02-12 10:27:35 +1000 | [diff] [blame] | 573 | for (i = 0; i < req->nr_relocs; i++) { |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 574 | struct drm_nouveau_gem_pushbuf_reloc *r = &reloc[i]; |
| 575 | struct drm_nouveau_gem_pushbuf_bo *b; |
Ben Skeggs | a1606a9 | 2010-02-12 10:27:35 +1000 | [diff] [blame] | 576 | struct nouveau_bo *nvbo; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 577 | uint32_t data; |
| 578 | |
Ben Skeggs | a1606a9 | 2010-02-12 10:27:35 +1000 | [diff] [blame] | 579 | if (unlikely(r->bo_index > req->nr_buffers)) { |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 580 | NV_ERROR(drm, "reloc bo index invalid\n"); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 581 | ret = -EINVAL; |
| 582 | break; |
| 583 | } |
| 584 | |
| 585 | b = &bo[r->bo_index]; |
Ben Skeggs | a1606a9 | 2010-02-12 10:27:35 +1000 | [diff] [blame] | 586 | if (b->presumed.valid) |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 587 | continue; |
| 588 | |
Ben Skeggs | a1606a9 | 2010-02-12 10:27:35 +1000 | [diff] [blame] | 589 | if (unlikely(r->reloc_bo_index > req->nr_buffers)) { |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 590 | NV_ERROR(drm, "reloc container bo index invalid\n"); |
Ben Skeggs | a1606a9 | 2010-02-12 10:27:35 +1000 | [diff] [blame] | 591 | ret = -EINVAL; |
| 592 | break; |
| 593 | } |
| 594 | nvbo = (void *)(unsigned long)bo[r->reloc_bo_index].user_priv; |
| 595 | |
| 596 | if (unlikely(r->reloc_bo_offset + 4 > |
| 597 | nvbo->bo.mem.num_pages << PAGE_SHIFT)) { |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 598 | NV_ERROR(drm, "reloc outside of bo\n"); |
Ben Skeggs | a1606a9 | 2010-02-12 10:27:35 +1000 | [diff] [blame] | 599 | ret = -EINVAL; |
| 600 | break; |
| 601 | } |
| 602 | |
| 603 | if (!nvbo->kmap.virtual) { |
| 604 | ret = ttm_bo_kmap(&nvbo->bo, 0, nvbo->bo.mem.num_pages, |
| 605 | &nvbo->kmap); |
| 606 | if (ret) { |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 607 | NV_ERROR(drm, "failed kmap for reloc\n"); |
Ben Skeggs | a1606a9 | 2010-02-12 10:27:35 +1000 | [diff] [blame] | 608 | break; |
| 609 | } |
| 610 | nvbo->validate_mapped = true; |
| 611 | } |
| 612 | |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 613 | if (r->flags & NOUVEAU_GEM_RELOC_LOW) |
Ben Skeggs | a1606a9 | 2010-02-12 10:27:35 +1000 | [diff] [blame] | 614 | data = b->presumed.offset + r->data; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 615 | else |
| 616 | if (r->flags & NOUVEAU_GEM_RELOC_HIGH) |
Ben Skeggs | a1606a9 | 2010-02-12 10:27:35 +1000 | [diff] [blame] | 617 | data = (b->presumed.offset + r->data) >> 32; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 618 | else |
| 619 | data = r->data; |
| 620 | |
| 621 | if (r->flags & NOUVEAU_GEM_RELOC_OR) { |
Ben Skeggs | a1606a9 | 2010-02-12 10:27:35 +1000 | [diff] [blame] | 622 | if (b->presumed.domain == NOUVEAU_GEM_DOMAIN_GART) |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 623 | data |= r->tor; |
| 624 | else |
| 625 | data |= r->vor; |
| 626 | } |
| 627 | |
Thomas Hellstrom | 702adba | 2010-11-17 12:28:29 +0000 | [diff] [blame] | 628 | spin_lock(&nvbo->bo.bdev->fence_lock); |
Ben Skeggs | a1606a9 | 2010-02-12 10:27:35 +1000 | [diff] [blame] | 629 | ret = ttm_bo_wait(&nvbo->bo, false, false, false); |
Thomas Hellstrom | 702adba | 2010-11-17 12:28:29 +0000 | [diff] [blame] | 630 | spin_unlock(&nvbo->bo.bdev->fence_lock); |
Ben Skeggs | a1606a9 | 2010-02-12 10:27:35 +1000 | [diff] [blame] | 631 | if (ret) { |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 632 | NV_ERROR(drm, "reloc wait_idle failed: %d\n", ret); |
Ben Skeggs | a1606a9 | 2010-02-12 10:27:35 +1000 | [diff] [blame] | 633 | break; |
| 634 | } |
Ben Skeggs | a1606a9 | 2010-02-12 10:27:35 +1000 | [diff] [blame] | 635 | |
| 636 | nouveau_bo_wr32(nvbo, r->reloc_bo_offset >> 2, data); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 637 | } |
| 638 | |
| 639 | kfree(reloc); |
| 640 | return ret; |
| 641 | } |
| 642 | |
| 643 | int |
| 644 | nouveau_gem_ioctl_pushbuf(struct drm_device *dev, void *data, |
| 645 | struct drm_file *file_priv) |
| 646 | { |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 647 | struct nouveau_abi16 *abi16 = nouveau_abi16_get(file_priv, dev); |
| 648 | struct nouveau_abi16_chan *temp; |
| 649 | struct nouveau_drm *drm = nouveau_drm(dev); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 650 | struct drm_nouveau_gem_pushbuf *req = data; |
Ben Skeggs | a1606a9 | 2010-02-12 10:27:35 +1000 | [diff] [blame] | 651 | struct drm_nouveau_gem_pushbuf_push *push; |
| 652 | struct drm_nouveau_gem_pushbuf_bo *bo; |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 653 | struct nouveau_channel *chan = NULL; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 654 | struct validate_op op; |
Francisco Jerez | 6e86e04 | 2010-07-03 18:36:39 +0200 | [diff] [blame] | 655 | struct nouveau_fence *fence = NULL; |
Ben Skeggs | a1606a9 | 2010-02-12 10:27:35 +1000 | [diff] [blame] | 656 | int i, j, ret = 0, do_reloc = 0; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 657 | |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 658 | if (unlikely(!abi16)) |
| 659 | return -ENOMEM; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 660 | |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 661 | list_for_each_entry(temp, &abi16->channels, head) { |
| 662 | if (temp->chan->handle == (NVDRM_CHAN | req->channel)) { |
| 663 | chan = temp->chan; |
| 664 | break; |
| 665 | } |
| 666 | } |
| 667 | |
| 668 | if (!chan) |
| 669 | return nouveau_abi16_put(abi16, -ENOENT); |
| 670 | |
| 671 | req->vram_available = drm->gem.vram_available; |
| 672 | req->gart_available = drm->gem.gart_available; |
Ben Skeggs | a1606a9 | 2010-02-12 10:27:35 +1000 | [diff] [blame] | 673 | if (unlikely(req->nr_push == 0)) |
| 674 | goto out_next; |
| 675 | |
| 676 | if (unlikely(req->nr_push > NOUVEAU_GEM_MAX_PUSH)) { |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 677 | NV_ERROR(drm, "pushbuf push count exceeds limit: %d max %d\n", |
Ben Skeggs | a1606a9 | 2010-02-12 10:27:35 +1000 | [diff] [blame] | 678 | req->nr_push, NOUVEAU_GEM_MAX_PUSH); |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 679 | return nouveau_abi16_put(abi16, -EINVAL); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 680 | } |
| 681 | |
Ben Skeggs | a1606a9 | 2010-02-12 10:27:35 +1000 | [diff] [blame] | 682 | if (unlikely(req->nr_buffers > NOUVEAU_GEM_MAX_BUFFERS)) { |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 683 | NV_ERROR(drm, "pushbuf bo count exceeds limit: %d max %d\n", |
Ben Skeggs | a1606a9 | 2010-02-12 10:27:35 +1000 | [diff] [blame] | 684 | req->nr_buffers, NOUVEAU_GEM_MAX_BUFFERS); |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 685 | return nouveau_abi16_put(abi16, -EINVAL); |
Ben Skeggs | a1606a9 | 2010-02-12 10:27:35 +1000 | [diff] [blame] | 686 | } |
| 687 | |
| 688 | if (unlikely(req->nr_relocs > NOUVEAU_GEM_MAX_RELOCS)) { |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 689 | NV_ERROR(drm, "pushbuf reloc count exceeds limit: %d max %d\n", |
Ben Skeggs | a1606a9 | 2010-02-12 10:27:35 +1000 | [diff] [blame] | 690 | req->nr_relocs, NOUVEAU_GEM_MAX_RELOCS); |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 691 | return nouveau_abi16_put(abi16, -EINVAL); |
Ben Skeggs | a1606a9 | 2010-02-12 10:27:35 +1000 | [diff] [blame] | 692 | } |
| 693 | |
| 694 | push = u_memcpya(req->push, req->nr_push, sizeof(*push)); |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 695 | if (IS_ERR(push)) |
| 696 | return nouveau_abi16_put(abi16, PTR_ERR(push)); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 697 | |
| 698 | bo = u_memcpya(req->buffers, req->nr_buffers, sizeof(*bo)); |
| 699 | if (IS_ERR(bo)) { |
Ben Skeggs | a1606a9 | 2010-02-12 10:27:35 +1000 | [diff] [blame] | 700 | kfree(push); |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 701 | return nouveau_abi16_put(abi16, PTR_ERR(bo)); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 702 | } |
| 703 | |
Ben Skeggs | accf949 | 2012-03-16 12:40:17 +1000 | [diff] [blame] | 704 | /* Ensure all push buffers are on validate list */ |
Ben Skeggs | 415e618 | 2010-07-23 09:06:52 +1000 | [diff] [blame] | 705 | for (i = 0; i < req->nr_push; i++) { |
| 706 | if (push[i].bo_index >= req->nr_buffers) { |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 707 | NV_ERROR(drm, "push %d buffer not in list\n", i); |
Ben Skeggs | 415e618 | 2010-07-23 09:06:52 +1000 | [diff] [blame] | 708 | ret = -EINVAL; |
Marcin Slusarz | 7fa0cba2 | 2011-03-07 12:31:35 +0100 | [diff] [blame] | 709 | goto out_prevalid; |
Ben Skeggs | 415e618 | 2010-07-23 09:06:52 +1000 | [diff] [blame] | 710 | } |
Ben Skeggs | 415e618 | 2010-07-23 09:06:52 +1000 | [diff] [blame] | 711 | } |
| 712 | |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 713 | /* Validate buffer list */ |
| 714 | ret = nouveau_gem_pushbuf_validate(chan, file_priv, bo, req->buffers, |
| 715 | req->nr_buffers, &op, &do_reloc); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 716 | if (ret) { |
Ben Skeggs | 938c40e | 2010-10-12 09:54:54 +1000 | [diff] [blame] | 717 | if (ret != -ERESTARTSYS) |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 718 | NV_ERROR(drm, "validate: %d\n", ret); |
Marcin Slusarz | 7fa0cba2 | 2011-03-07 12:31:35 +0100 | [diff] [blame] | 719 | goto out_prevalid; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 720 | } |
| 721 | |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 722 | /* Apply any relocations that are required */ |
| 723 | if (do_reloc) { |
Ben Skeggs | a1606a9 | 2010-02-12 10:27:35 +1000 | [diff] [blame] | 724 | ret = nouveau_gem_pushbuf_reloc_apply(dev, req, bo); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 725 | if (ret) { |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 726 | NV_ERROR(drm, "reloc apply: %d\n", ret); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 727 | goto out; |
| 728 | } |
| 729 | } |
| 730 | |
Ben Skeggs | 9a391ad | 2010-02-11 16:37:26 +1000 | [diff] [blame] | 731 | if (chan->dma.ib_max) { |
Ben Skeggs | 5e120f6 | 2012-04-30 13:55:29 +1000 | [diff] [blame] | 732 | ret = nouveau_dma_wait(chan, req->nr_push + 1, 16); |
Ben Skeggs | 9a391ad | 2010-02-11 16:37:26 +1000 | [diff] [blame] | 733 | if (ret) { |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 734 | NV_ERROR(drm, "nv50cal_space: %d\n", ret); |
Ben Skeggs | 9a391ad | 2010-02-11 16:37:26 +1000 | [diff] [blame] | 735 | goto out; |
| 736 | } |
| 737 | |
Ben Skeggs | a1606a9 | 2010-02-12 10:27:35 +1000 | [diff] [blame] | 738 | for (i = 0; i < req->nr_push; i++) { |
| 739 | struct nouveau_bo *nvbo = (void *)(unsigned long) |
| 740 | bo[push[i].bo_index].user_priv; |
| 741 | |
| 742 | nv50_dma_push(chan, nvbo, push[i].offset, |
| 743 | push[i].length); |
| 744 | } |
Ben Skeggs | 9a391ad | 2010-02-11 16:37:26 +1000 | [diff] [blame] | 745 | } else |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 746 | if (nv_device(drm->device)->chipset >= 0x25) { |
Ben Skeggs | a1606a9 | 2010-02-12 10:27:35 +1000 | [diff] [blame] | 747 | ret = RING_SPACE(chan, req->nr_push * 2); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 748 | if (ret) { |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 749 | NV_ERROR(drm, "cal_space: %d\n", ret); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 750 | goto out; |
| 751 | } |
Ben Skeggs | a1606a9 | 2010-02-12 10:27:35 +1000 | [diff] [blame] | 752 | |
| 753 | for (i = 0; i < req->nr_push; i++) { |
| 754 | struct nouveau_bo *nvbo = (void *)(unsigned long) |
| 755 | bo[push[i].bo_index].user_priv; |
Ben Skeggs | a1606a9 | 2010-02-12 10:27:35 +1000 | [diff] [blame] | 756 | |
Ben Skeggs | 3a92d37 | 2012-08-04 05:46:01 +1000 | [diff] [blame] | 757 | OUT_RING(chan, (nvbo->bo.offset + push[i].offset) | 2); |
Ben Skeggs | a1606a9 | 2010-02-12 10:27:35 +1000 | [diff] [blame] | 758 | OUT_RING(chan, 0); |
| 759 | } |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 760 | } else { |
Ben Skeggs | a1606a9 | 2010-02-12 10:27:35 +1000 | [diff] [blame] | 761 | ret = RING_SPACE(chan, req->nr_push * (2 + NOUVEAU_DMA_SKIPS)); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 762 | if (ret) { |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 763 | NV_ERROR(drm, "jmp_space: %d\n", ret); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 764 | goto out; |
| 765 | } |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 766 | |
Ben Skeggs | a1606a9 | 2010-02-12 10:27:35 +1000 | [diff] [blame] | 767 | for (i = 0; i < req->nr_push; i++) { |
| 768 | struct nouveau_bo *nvbo = (void *)(unsigned long) |
| 769 | bo[push[i].bo_index].user_priv; |
Ben Skeggs | a1606a9 | 2010-02-12 10:27:35 +1000 | [diff] [blame] | 770 | uint32_t cmd; |
| 771 | |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 772 | cmd = chan->push.vma.offset + ((chan->dma.cur + 2) << 2); |
Ben Skeggs | a1606a9 | 2010-02-12 10:27:35 +1000 | [diff] [blame] | 773 | cmd |= 0x20000000; |
| 774 | if (unlikely(cmd != req->suffix0)) { |
| 775 | if (!nvbo->kmap.virtual) { |
| 776 | ret = ttm_bo_kmap(&nvbo->bo, 0, |
| 777 | nvbo->bo.mem. |
| 778 | num_pages, |
| 779 | &nvbo->kmap); |
| 780 | if (ret) { |
| 781 | WIND_RING(chan); |
| 782 | goto out; |
| 783 | } |
| 784 | nvbo->validate_mapped = true; |
| 785 | } |
| 786 | |
| 787 | nouveau_bo_wr32(nvbo, (push[i].offset + |
| 788 | push[i].length - 8) / 4, cmd); |
| 789 | } |
| 790 | |
Ben Skeggs | 3a92d37 | 2012-08-04 05:46:01 +1000 | [diff] [blame] | 791 | OUT_RING(chan, 0x20000000 | |
| 792 | (nvbo->bo.offset + push[i].offset)); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 793 | OUT_RING(chan, 0); |
Ben Skeggs | a1606a9 | 2010-02-12 10:27:35 +1000 | [diff] [blame] | 794 | for (j = 0; j < NOUVEAU_DMA_SKIPS; j++) |
| 795 | OUT_RING(chan, 0); |
| 796 | } |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 797 | } |
| 798 | |
Ben Skeggs | d375e7d5 | 2012-04-30 13:30:00 +1000 | [diff] [blame] | 799 | ret = nouveau_fence_new(chan, &fence); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 800 | if (ret) { |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 801 | NV_ERROR(drm, "error fencing pushbuf: %d\n", ret); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 802 | WIND_RING(chan); |
| 803 | goto out; |
| 804 | } |
| 805 | |
| 806 | out: |
Luca Barbieri | 234896a | 2010-01-06 04:02:45 +0100 | [diff] [blame] | 807 | validate_fini(&op, fence); |
Marcin Slusarz | 382d62e | 2010-10-20 21:50:24 +0200 | [diff] [blame] | 808 | nouveau_fence_unref(&fence); |
Marcin Slusarz | 7fa0cba2 | 2011-03-07 12:31:35 +0100 | [diff] [blame] | 809 | |
| 810 | out_prevalid: |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 811 | kfree(bo); |
Ben Skeggs | a1606a9 | 2010-02-12 10:27:35 +1000 | [diff] [blame] | 812 | kfree(push); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 813 | |
| 814 | out_next: |
Ben Skeggs | 9a391ad | 2010-02-11 16:37:26 +1000 | [diff] [blame] | 815 | if (chan->dma.ib_max) { |
| 816 | req->suffix0 = 0x00000000; |
| 817 | req->suffix1 = 0x00000000; |
| 818 | } else |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 819 | if (nv_device(drm->device)->chipset >= 0x25) { |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 820 | req->suffix0 = 0x00020000; |
| 821 | req->suffix1 = 0x00000000; |
| 822 | } else { |
| 823 | req->suffix0 = 0x20000000 | |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 824 | (chan->push.vma.offset + ((chan->dma.cur + 2) << 2)); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 825 | req->suffix1 = 0x00000000; |
| 826 | } |
| 827 | |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 828 | return nouveau_abi16_put(abi16, ret); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 829 | } |
| 830 | |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 831 | static inline uint32_t |
| 832 | domain_to_ttm(struct nouveau_bo *nvbo, uint32_t domain) |
| 833 | { |
| 834 | uint32_t flags = 0; |
| 835 | |
| 836 | if (domain & NOUVEAU_GEM_DOMAIN_VRAM) |
| 837 | flags |= TTM_PL_FLAG_VRAM; |
| 838 | if (domain & NOUVEAU_GEM_DOMAIN_GART) |
| 839 | flags |= TTM_PL_FLAG_TT; |
| 840 | |
| 841 | return flags; |
| 842 | } |
| 843 | |
| 844 | int |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 845 | nouveau_gem_ioctl_cpu_prep(struct drm_device *dev, void *data, |
| 846 | struct drm_file *file_priv) |
| 847 | { |
| 848 | struct drm_nouveau_gem_cpu_prep *req = data; |
| 849 | struct drm_gem_object *gem; |
| 850 | struct nouveau_bo *nvbo; |
| 851 | bool no_wait = !!(req->flags & NOUVEAU_GEM_CPU_PREP_NOWAIT); |
| 852 | int ret = -EINVAL; |
| 853 | |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 854 | gem = drm_gem_object_lookup(dev, file_priv, req->handle); |
| 855 | if (!gem) |
Chris Wilson | bf79cb9 | 2010-08-04 14:19:46 +0100 | [diff] [blame] | 856 | return -ENOENT; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 857 | nvbo = nouveau_gem_object(gem); |
| 858 | |
Ben Skeggs | 21e86c1 | 2010-10-11 11:48:45 +1000 | [diff] [blame] | 859 | spin_lock(&nvbo->bo.bdev->fence_lock); |
| 860 | ret = ttm_bo_wait(&nvbo->bo, true, true, no_wait); |
| 861 | spin_unlock(&nvbo->bo.bdev->fence_lock); |
Luca Barbieri | bc9025b | 2010-02-09 05:49:12 +0000 | [diff] [blame] | 862 | drm_gem_object_unreference_unlocked(gem); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 863 | return ret; |
| 864 | } |
| 865 | |
| 866 | int |
| 867 | nouveau_gem_ioctl_cpu_fini(struct drm_device *dev, void *data, |
| 868 | struct drm_file *file_priv) |
| 869 | { |
Ben Skeggs | 21e86c1 | 2010-10-11 11:48:45 +1000 | [diff] [blame] | 870 | return 0; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 871 | } |
| 872 | |
| 873 | int |
| 874 | nouveau_gem_ioctl_info(struct drm_device *dev, void *data, |
| 875 | struct drm_file *file_priv) |
| 876 | { |
| 877 | struct drm_nouveau_gem_info *req = data; |
| 878 | struct drm_gem_object *gem; |
| 879 | int ret; |
| 880 | |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 881 | gem = drm_gem_object_lookup(dev, file_priv, req->handle); |
| 882 | if (!gem) |
Chris Wilson | bf79cb9 | 2010-08-04 14:19:46 +0100 | [diff] [blame] | 883 | return -ENOENT; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 884 | |
Ben Skeggs | e758a31 | 2011-06-07 13:28:11 +1000 | [diff] [blame] | 885 | ret = nouveau_gem_info(file_priv, gem, req); |
Luca Barbieri | bc9025b | 2010-02-09 05:49:12 +0000 | [diff] [blame] | 886 | drm_gem_object_unreference_unlocked(gem); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 887 | return ret; |
| 888 | } |
| 889 | |