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); |
Marcin Slusarz | a84fa1a | 2013-02-03 22:02:47 +0100 | [diff] [blame^] | 208 | struct nouveau_cli *cli = nouveau_cli(file_priv); |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 209 | struct nouveau_fb *pfb = nouveau_fb(drm->device); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 210 | struct drm_nouveau_gem_new *req = data; |
| 211 | struct nouveau_bo *nvbo = NULL; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 212 | int ret = 0; |
| 213 | |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 214 | drm->ttm.bdev.dev_mapping = drm->dev->dev_mapping; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 215 | |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 216 | if (!pfb->memtype_valid(pfb, req->info.tile_flags)) { |
Marcin Slusarz | a84fa1a | 2013-02-03 22:02:47 +0100 | [diff] [blame^] | 217 | NV_ERROR(cli, "bad page flags: 0x%08x\n", req->info.tile_flags); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 218 | return -EINVAL; |
Ben Skeggs | 60d2a88 | 2010-12-06 15:28:54 +1000 | [diff] [blame] | 219 | } |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 220 | |
Ben Skeggs | f6d4e62 | 2011-06-07 12:25:36 +1000 | [diff] [blame] | 221 | ret = nouveau_gem_new(dev, req->info.size, req->align, |
Ben Skeggs | 6ba9a68 | 2011-02-10 14:42:08 +1000 | [diff] [blame] | 222 | req->info.domain, req->info.tile_mode, |
| 223 | req->info.tile_flags, &nvbo); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 224 | if (ret) |
| 225 | return ret; |
| 226 | |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 227 | ret = drm_gem_handle_create(file_priv, nvbo->gem, &req->info.handle); |
Ben Skeggs | e758a31 | 2011-06-07 13:28:11 +1000 | [diff] [blame] | 228 | if (ret == 0) { |
| 229 | ret = nouveau_gem_info(file_priv, nvbo->gem, &req->info); |
| 230 | if (ret) |
| 231 | drm_gem_handle_delete(file_priv, req->info.handle); |
| 232 | } |
| 233 | |
Dave Airlie | 29d08b3 | 2010-09-27 16:17:17 +1000 | [diff] [blame] | 234 | /* drop reference from allocate - handle holds it now */ |
| 235 | drm_gem_object_unreference_unlocked(nvbo->gem); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 236 | return ret; |
| 237 | } |
| 238 | |
| 239 | static int |
| 240 | nouveau_gem_set_domain(struct drm_gem_object *gem, uint32_t read_domains, |
| 241 | uint32_t write_domains, uint32_t valid_domains) |
| 242 | { |
| 243 | struct nouveau_bo *nvbo = gem->driver_private; |
| 244 | struct ttm_buffer_object *bo = &nvbo->bo; |
Ben Skeggs | db5c8e2 | 2011-02-10 13:41:01 +1000 | [diff] [blame] | 245 | uint32_t domains = valid_domains & nvbo->valid_domains & |
Francisco Jerez | 78ad0f7 | 2010-03-18 13:07:47 +0100 | [diff] [blame] | 246 | (write_domains ? write_domains : read_domains); |
| 247 | uint32_t pref_flags = 0, valid_flags = 0; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 248 | |
Francisco Jerez | 78ad0f7 | 2010-03-18 13:07:47 +0100 | [diff] [blame] | 249 | if (!domains) |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 250 | return -EINVAL; |
| 251 | |
Francisco Jerez | 78ad0f7 | 2010-03-18 13:07:47 +0100 | [diff] [blame] | 252 | if (valid_domains & NOUVEAU_GEM_DOMAIN_VRAM) |
| 253 | valid_flags |= TTM_PL_FLAG_VRAM; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 254 | |
Francisco Jerez | 78ad0f7 | 2010-03-18 13:07:47 +0100 | [diff] [blame] | 255 | if (valid_domains & NOUVEAU_GEM_DOMAIN_GART) |
| 256 | valid_flags |= TTM_PL_FLAG_TT; |
| 257 | |
| 258 | if ((domains & NOUVEAU_GEM_DOMAIN_VRAM) && |
| 259 | bo->mem.mem_type == TTM_PL_VRAM) |
| 260 | pref_flags |= TTM_PL_FLAG_VRAM; |
| 261 | |
| 262 | else if ((domains & NOUVEAU_GEM_DOMAIN_GART) && |
| 263 | bo->mem.mem_type == TTM_PL_TT) |
| 264 | pref_flags |= TTM_PL_FLAG_TT; |
| 265 | |
| 266 | else if (domains & NOUVEAU_GEM_DOMAIN_VRAM) |
| 267 | pref_flags |= TTM_PL_FLAG_VRAM; |
| 268 | |
| 269 | else |
| 270 | pref_flags |= TTM_PL_FLAG_TT; |
| 271 | |
| 272 | nouveau_bo_placement_set(nvbo, pref_flags, valid_flags); |
| 273 | |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 274 | return 0; |
| 275 | } |
| 276 | |
| 277 | struct validate_op { |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 278 | struct list_head vram_list; |
| 279 | struct list_head gart_list; |
| 280 | struct list_head both_list; |
| 281 | }; |
| 282 | |
| 283 | static void |
| 284 | validate_fini_list(struct list_head *list, struct nouveau_fence *fence) |
| 285 | { |
| 286 | struct list_head *entry, *tmp; |
| 287 | struct nouveau_bo *nvbo; |
| 288 | |
| 289 | list_for_each_safe(entry, tmp, list) { |
| 290 | nvbo = list_entry(entry, struct nouveau_bo, entry); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 291 | |
Francisco Jerez | 332b242 | 2010-10-20 23:35:40 +0200 | [diff] [blame] | 292 | nouveau_bo_fence(nvbo, fence); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 293 | |
Ben Skeggs | a1606a9 | 2010-02-12 10:27:35 +1000 | [diff] [blame] | 294 | if (unlikely(nvbo->validate_mapped)) { |
| 295 | ttm_bo_kunmap(&nvbo->kmap); |
| 296 | nvbo->validate_mapped = false; |
| 297 | } |
| 298 | |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 299 | list_del(&nvbo->entry); |
| 300 | nvbo->reserved_by = NULL; |
| 301 | ttm_bo_unreserve(&nvbo->bo); |
Francisco Jerez | 374c3af | 2010-08-29 12:21:16 +0200 | [diff] [blame] | 302 | drm_gem_object_unreference_unlocked(nvbo->gem); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 303 | } |
| 304 | } |
| 305 | |
| 306 | static void |
Luca Barbieri | 234896a | 2010-01-06 04:02:45 +0100 | [diff] [blame] | 307 | validate_fini(struct validate_op *op, struct nouveau_fence* fence) |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 308 | { |
Luca Barbieri | 234896a | 2010-01-06 04:02:45 +0100 | [diff] [blame] | 309 | validate_fini_list(&op->vram_list, fence); |
| 310 | validate_fini_list(&op->gart_list, fence); |
| 311 | validate_fini_list(&op->both_list, fence); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 312 | } |
| 313 | |
| 314 | static int |
| 315 | validate_init(struct nouveau_channel *chan, struct drm_file *file_priv, |
| 316 | struct drm_nouveau_gem_pushbuf_bo *pbbo, |
| 317 | int nr_buffers, struct validate_op *op) |
| 318 | { |
Marcin Slusarz | a84fa1a | 2013-02-03 22:02:47 +0100 | [diff] [blame^] | 319 | struct nouveau_cli *cli = nouveau_cli(file_priv); |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 320 | struct drm_device *dev = chan->drm->dev; |
| 321 | struct nouveau_drm *drm = nouveau_drm(dev); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 322 | uint32_t sequence; |
| 323 | int trycnt = 0; |
| 324 | int ret, i; |
| 325 | |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 326 | sequence = atomic_add_return(1, &drm->ttm.validate_sequence); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 327 | retry: |
| 328 | if (++trycnt > 100000) { |
Marcin Slusarz | a84fa1a | 2013-02-03 22:02:47 +0100 | [diff] [blame^] | 329 | NV_ERROR(cli, "%s failed and gave up.\n", __func__); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 330 | return -EINVAL; |
| 331 | } |
| 332 | |
| 333 | for (i = 0; i < nr_buffers; i++) { |
| 334 | struct drm_nouveau_gem_pushbuf_bo *b = &pbbo[i]; |
| 335 | struct drm_gem_object *gem; |
| 336 | struct nouveau_bo *nvbo; |
| 337 | |
| 338 | gem = drm_gem_object_lookup(dev, file_priv, b->handle); |
| 339 | if (!gem) { |
Marcin Slusarz | a84fa1a | 2013-02-03 22:02:47 +0100 | [diff] [blame^] | 340 | NV_ERROR(cli, "Unknown handle 0x%08x\n", b->handle); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 341 | validate_fini(op, NULL); |
Chris Wilson | bf79cb9 | 2010-08-04 14:19:46 +0100 | [diff] [blame] | 342 | return -ENOENT; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 343 | } |
| 344 | nvbo = gem->driver_private; |
| 345 | |
| 346 | if (nvbo->reserved_by && nvbo->reserved_by == file_priv) { |
Marcin Slusarz | a84fa1a | 2013-02-03 22:02:47 +0100 | [diff] [blame^] | 347 | NV_ERROR(cli, "multiple instances of buffer %d on " |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 348 | "validation list\n", b->handle); |
Ben Skeggs | 5086f69 | 2012-06-25 18:04:27 +1000 | [diff] [blame] | 349 | drm_gem_object_unreference_unlocked(gem); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 350 | validate_fini(op, NULL); |
| 351 | return -EINVAL; |
| 352 | } |
| 353 | |
Ben Skeggs | 938c40e | 2010-10-12 09:54:54 +1000 | [diff] [blame] | 354 | ret = ttm_bo_reserve(&nvbo->bo, true, false, true, sequence); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 355 | if (ret) { |
| 356 | validate_fini(op, NULL); |
Ben Skeggs | 938c40e | 2010-10-12 09:54:54 +1000 | [diff] [blame] | 357 | if (unlikely(ret == -EAGAIN)) |
| 358 | ret = ttm_bo_wait_unreserved(&nvbo->bo, true); |
Francisco Jerez | 374c3af | 2010-08-29 12:21:16 +0200 | [diff] [blame] | 359 | drm_gem_object_unreference_unlocked(gem); |
Ben Skeggs | 938c40e | 2010-10-12 09:54:54 +1000 | [diff] [blame] | 360 | if (unlikely(ret)) { |
| 361 | if (ret != -ERESTARTSYS) |
Marcin Slusarz | a84fa1a | 2013-02-03 22:02:47 +0100 | [diff] [blame^] | 362 | NV_ERROR(cli, "fail reserve\n"); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 363 | return ret; |
Ben Skeggs | a1606a9 | 2010-02-12 10:27:35 +1000 | [diff] [blame] | 364 | } |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 365 | goto retry; |
| 366 | } |
| 367 | |
Ben Skeggs | a1606a9 | 2010-02-12 10:27:35 +1000 | [diff] [blame] | 368 | b->user_priv = (uint64_t)(unsigned long)nvbo; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 369 | nvbo->reserved_by = file_priv; |
| 370 | nvbo->pbbo_index = i; |
| 371 | if ((b->valid_domains & NOUVEAU_GEM_DOMAIN_VRAM) && |
| 372 | (b->valid_domains & NOUVEAU_GEM_DOMAIN_GART)) |
| 373 | list_add_tail(&nvbo->entry, &op->both_list); |
| 374 | else |
| 375 | if (b->valid_domains & NOUVEAU_GEM_DOMAIN_VRAM) |
| 376 | list_add_tail(&nvbo->entry, &op->vram_list); |
| 377 | else |
| 378 | if (b->valid_domains & NOUVEAU_GEM_DOMAIN_GART) |
| 379 | list_add_tail(&nvbo->entry, &op->gart_list); |
| 380 | else { |
Marcin Slusarz | a84fa1a | 2013-02-03 22:02:47 +0100 | [diff] [blame^] | 381 | NV_ERROR(cli, "invalid valid domains: 0x%08x\n", |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 382 | b->valid_domains); |
Ben Skeggs | 0208843 | 2010-01-21 15:03:23 +1000 | [diff] [blame] | 383 | list_add_tail(&nvbo->entry, &op->both_list); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 384 | validate_fini(op, NULL); |
| 385 | return -EINVAL; |
| 386 | } |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 387 | } |
| 388 | |
| 389 | return 0; |
| 390 | } |
| 391 | |
| 392 | static int |
Ben Skeggs | 525895b | 2012-01-10 10:18:28 +1000 | [diff] [blame] | 393 | validate_sync(struct nouveau_channel *chan, struct nouveau_bo *nvbo) |
| 394 | { |
| 395 | struct nouveau_fence *fence = NULL; |
| 396 | int ret = 0; |
| 397 | |
| 398 | spin_lock(&nvbo->bo.bdev->fence_lock); |
| 399 | if (nvbo->bo.sync_obj) |
| 400 | fence = nouveau_fence_ref(nvbo->bo.sync_obj); |
| 401 | spin_unlock(&nvbo->bo.bdev->fence_lock); |
| 402 | |
| 403 | if (fence) { |
| 404 | ret = nouveau_fence_sync(fence, chan); |
| 405 | nouveau_fence_unref(&fence); |
| 406 | } |
| 407 | |
| 408 | return ret; |
| 409 | } |
| 410 | |
| 411 | static int |
Marcin Slusarz | a84fa1a | 2013-02-03 22:02:47 +0100 | [diff] [blame^] | 412 | validate_list(struct nouveau_channel *chan, struct nouveau_cli *cli, |
| 413 | struct list_head *list, struct drm_nouveau_gem_pushbuf_bo *pbbo, |
| 414 | uint64_t user_pbbo_ptr) |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 415 | { |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 416 | struct nouveau_drm *drm = chan->drm; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 417 | struct drm_nouveau_gem_pushbuf_bo __user *upbbo = |
| 418 | (void __force __user *)(uintptr_t)user_pbbo_ptr; |
| 419 | struct nouveau_bo *nvbo; |
| 420 | int ret, relocs = 0; |
| 421 | |
| 422 | list_for_each_entry(nvbo, list, entry) { |
| 423 | struct drm_nouveau_gem_pushbuf_bo *b = &pbbo[nvbo->pbbo_index]; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 424 | |
Ben Skeggs | 525895b | 2012-01-10 10:18:28 +1000 | [diff] [blame] | 425 | ret = validate_sync(chan, nvbo); |
Ben Skeggs | 415e618 | 2010-07-23 09:06:52 +1000 | [diff] [blame] | 426 | if (unlikely(ret)) { |
Marcin Slusarz | a84fa1a | 2013-02-03 22:02:47 +0100 | [diff] [blame^] | 427 | NV_ERROR(cli, "fail pre-validate sync\n"); |
Ben Skeggs | 415e618 | 2010-07-23 09:06:52 +1000 | [diff] [blame] | 428 | return ret; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 429 | } |
| 430 | |
| 431 | ret = nouveau_gem_set_domain(nvbo->gem, b->read_domains, |
| 432 | b->write_domains, |
| 433 | b->valid_domains); |
Ben Skeggs | a1606a9 | 2010-02-12 10:27:35 +1000 | [diff] [blame] | 434 | if (unlikely(ret)) { |
Marcin Slusarz | a84fa1a | 2013-02-03 22:02:47 +0100 | [diff] [blame^] | 435 | NV_ERROR(cli, "fail set_domain\n"); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 436 | return ret; |
Ben Skeggs | a1606a9 | 2010-02-12 10:27:35 +1000 | [diff] [blame] | 437 | } |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 438 | |
Maarten Lankhorst | 97a875c | 2012-11-28 11:25:44 +0000 | [diff] [blame] | 439 | ret = nouveau_bo_validate(nvbo, true, false); |
Ben Skeggs | a1606a9 | 2010-02-12 10:27:35 +1000 | [diff] [blame] | 440 | if (unlikely(ret)) { |
Ben Skeggs | 938c40e | 2010-10-12 09:54:54 +1000 | [diff] [blame] | 441 | if (ret != -ERESTARTSYS) |
Marcin Slusarz | a84fa1a | 2013-02-03 22:02:47 +0100 | [diff] [blame^] | 442 | NV_ERROR(cli, "fail ttm_validate\n"); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 443 | return ret; |
Ben Skeggs | a1606a9 | 2010-02-12 10:27:35 +1000 | [diff] [blame] | 444 | } |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 445 | |
Ben Skeggs | 525895b | 2012-01-10 10:18:28 +1000 | [diff] [blame] | 446 | ret = validate_sync(chan, nvbo); |
Ben Skeggs | 415e618 | 2010-07-23 09:06:52 +1000 | [diff] [blame] | 447 | if (unlikely(ret)) { |
Marcin Slusarz | a84fa1a | 2013-02-03 22:02:47 +0100 | [diff] [blame^] | 448 | NV_ERROR(cli, "fail post-validate sync\n"); |
Ben Skeggs | 415e618 | 2010-07-23 09:06:52 +1000 | [diff] [blame] | 449 | return ret; |
| 450 | } |
| 451 | |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 452 | if (nv_device(drm->device)->card_type < NV_50) { |
Ben Skeggs | a3fcd0a | 2011-06-07 11:12:39 +1000 | [diff] [blame] | 453 | if (nvbo->bo.offset == b->presumed.offset && |
| 454 | ((nvbo->bo.mem.mem_type == TTM_PL_VRAM && |
| 455 | b->presumed.domain & NOUVEAU_GEM_DOMAIN_VRAM) || |
| 456 | (nvbo->bo.mem.mem_type == TTM_PL_TT && |
| 457 | b->presumed.domain & NOUVEAU_GEM_DOMAIN_GART))) |
| 458 | continue; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 459 | |
Ben Skeggs | a3fcd0a | 2011-06-07 11:12:39 +1000 | [diff] [blame] | 460 | if (nvbo->bo.mem.mem_type == TTM_PL_TT) |
| 461 | b->presumed.domain = NOUVEAU_GEM_DOMAIN_GART; |
| 462 | else |
| 463 | b->presumed.domain = NOUVEAU_GEM_DOMAIN_VRAM; |
| 464 | b->presumed.offset = nvbo->bo.offset; |
| 465 | b->presumed.valid = 0; |
| 466 | relocs++; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 467 | |
Ben Skeggs | a3fcd0a | 2011-06-07 11:12:39 +1000 | [diff] [blame] | 468 | if (DRM_COPY_TO_USER(&upbbo[nvbo->pbbo_index].presumed, |
| 469 | &b->presumed, sizeof(b->presumed))) |
| 470 | return -EFAULT; |
| 471 | } |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 472 | } |
| 473 | |
| 474 | return relocs; |
| 475 | } |
| 476 | |
| 477 | static int |
| 478 | nouveau_gem_pushbuf_validate(struct nouveau_channel *chan, |
| 479 | struct drm_file *file_priv, |
| 480 | struct drm_nouveau_gem_pushbuf_bo *pbbo, |
| 481 | uint64_t user_buffers, int nr_buffers, |
| 482 | struct validate_op *op, int *apply_relocs) |
| 483 | { |
Marcin Slusarz | a84fa1a | 2013-02-03 22:02:47 +0100 | [diff] [blame^] | 484 | struct nouveau_cli *cli = nouveau_cli(file_priv); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 485 | int ret, relocs = 0; |
| 486 | |
| 487 | INIT_LIST_HEAD(&op->vram_list); |
| 488 | INIT_LIST_HEAD(&op->gart_list); |
| 489 | INIT_LIST_HEAD(&op->both_list); |
| 490 | |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 491 | if (nr_buffers == 0) |
| 492 | return 0; |
| 493 | |
| 494 | ret = validate_init(chan, file_priv, pbbo, nr_buffers, op); |
Ben Skeggs | a1606a9 | 2010-02-12 10:27:35 +1000 | [diff] [blame] | 495 | if (unlikely(ret)) { |
Ben Skeggs | 938c40e | 2010-10-12 09:54:54 +1000 | [diff] [blame] | 496 | if (ret != -ERESTARTSYS) |
Marcin Slusarz | a84fa1a | 2013-02-03 22:02:47 +0100 | [diff] [blame^] | 497 | NV_ERROR(cli, "validate_init\n"); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 498 | return ret; |
Ben Skeggs | a1606a9 | 2010-02-12 10:27:35 +1000 | [diff] [blame] | 499 | } |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 500 | |
Marcin Slusarz | a84fa1a | 2013-02-03 22:02:47 +0100 | [diff] [blame^] | 501 | ret = validate_list(chan, cli, &op->vram_list, pbbo, user_buffers); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 502 | if (unlikely(ret < 0)) { |
Ben Skeggs | 938c40e | 2010-10-12 09:54:54 +1000 | [diff] [blame] | 503 | if (ret != -ERESTARTSYS) |
Marcin Slusarz | a84fa1a | 2013-02-03 22:02:47 +0100 | [diff] [blame^] | 504 | NV_ERROR(cli, "validate vram_list\n"); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 505 | validate_fini(op, NULL); |
| 506 | return ret; |
| 507 | } |
| 508 | relocs += ret; |
| 509 | |
Marcin Slusarz | a84fa1a | 2013-02-03 22:02:47 +0100 | [diff] [blame^] | 510 | ret = validate_list(chan, cli, &op->gart_list, pbbo, user_buffers); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 511 | if (unlikely(ret < 0)) { |
Ben Skeggs | 938c40e | 2010-10-12 09:54:54 +1000 | [diff] [blame] | 512 | if (ret != -ERESTARTSYS) |
Marcin Slusarz | a84fa1a | 2013-02-03 22:02:47 +0100 | [diff] [blame^] | 513 | NV_ERROR(cli, "validate gart_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 | |
Marcin Slusarz | a84fa1a | 2013-02-03 22:02:47 +0100 | [diff] [blame^] | 519 | ret = validate_list(chan, cli, &op->both_list, pbbo, user_buffers); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 520 | if (unlikely(ret < 0)) { |
Ben Skeggs | 938c40e | 2010-10-12 09:54:54 +1000 | [diff] [blame] | 521 | if (ret != -ERESTARTSYS) |
Marcin Slusarz | a84fa1a | 2013-02-03 22:02:47 +0100 | [diff] [blame^] | 522 | NV_ERROR(cli, "validate both_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 | *apply_relocs = relocs; |
| 529 | return 0; |
| 530 | } |
| 531 | |
| 532 | static inline void * |
| 533 | u_memcpya(uint64_t user, unsigned nmemb, unsigned size) |
| 534 | { |
| 535 | void *mem; |
| 536 | void __user *userptr = (void __force __user *)(uintptr_t)user; |
| 537 | |
| 538 | mem = kmalloc(nmemb * size, GFP_KERNEL); |
| 539 | if (!mem) |
| 540 | return ERR_PTR(-ENOMEM); |
| 541 | |
| 542 | if (DRM_COPY_FROM_USER(mem, userptr, nmemb * size)) { |
| 543 | kfree(mem); |
| 544 | return ERR_PTR(-EFAULT); |
| 545 | } |
| 546 | |
| 547 | return mem; |
| 548 | } |
| 549 | |
| 550 | static int |
Marcin Slusarz | a84fa1a | 2013-02-03 22:02:47 +0100 | [diff] [blame^] | 551 | nouveau_gem_pushbuf_reloc_apply(struct nouveau_cli *cli, |
Ben Skeggs | a1606a9 | 2010-02-12 10:27:35 +1000 | [diff] [blame] | 552 | struct drm_nouveau_gem_pushbuf *req, |
| 553 | struct drm_nouveau_gem_pushbuf_bo *bo) |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 554 | { |
| 555 | struct drm_nouveau_gem_pushbuf_reloc *reloc = NULL; |
Luca Barbieri | 12f735b | 2010-01-10 20:10:53 +0100 | [diff] [blame] | 556 | int ret = 0; |
| 557 | unsigned i; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 558 | |
Ben Skeggs | a1606a9 | 2010-02-12 10:27:35 +1000 | [diff] [blame] | 559 | reloc = u_memcpya(req->relocs, req->nr_relocs, sizeof(*reloc)); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 560 | if (IS_ERR(reloc)) |
| 561 | return PTR_ERR(reloc); |
| 562 | |
Ben Skeggs | a1606a9 | 2010-02-12 10:27:35 +1000 | [diff] [blame] | 563 | for (i = 0; i < req->nr_relocs; i++) { |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 564 | struct drm_nouveau_gem_pushbuf_reloc *r = &reloc[i]; |
| 565 | struct drm_nouveau_gem_pushbuf_bo *b; |
Ben Skeggs | a1606a9 | 2010-02-12 10:27:35 +1000 | [diff] [blame] | 566 | struct nouveau_bo *nvbo; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 567 | uint32_t data; |
| 568 | |
Ben Skeggs | a1606a9 | 2010-02-12 10:27:35 +1000 | [diff] [blame] | 569 | if (unlikely(r->bo_index > req->nr_buffers)) { |
Marcin Slusarz | a84fa1a | 2013-02-03 22:02:47 +0100 | [diff] [blame^] | 570 | NV_ERROR(cli, "reloc bo index invalid\n"); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 571 | ret = -EINVAL; |
| 572 | break; |
| 573 | } |
| 574 | |
| 575 | b = &bo[r->bo_index]; |
Ben Skeggs | a1606a9 | 2010-02-12 10:27:35 +1000 | [diff] [blame] | 576 | if (b->presumed.valid) |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 577 | continue; |
| 578 | |
Ben Skeggs | a1606a9 | 2010-02-12 10:27:35 +1000 | [diff] [blame] | 579 | if (unlikely(r->reloc_bo_index > req->nr_buffers)) { |
Marcin Slusarz | a84fa1a | 2013-02-03 22:02:47 +0100 | [diff] [blame^] | 580 | NV_ERROR(cli, "reloc container bo index invalid\n"); |
Ben Skeggs | a1606a9 | 2010-02-12 10:27:35 +1000 | [diff] [blame] | 581 | ret = -EINVAL; |
| 582 | break; |
| 583 | } |
| 584 | nvbo = (void *)(unsigned long)bo[r->reloc_bo_index].user_priv; |
| 585 | |
| 586 | if (unlikely(r->reloc_bo_offset + 4 > |
| 587 | nvbo->bo.mem.num_pages << PAGE_SHIFT)) { |
Marcin Slusarz | a84fa1a | 2013-02-03 22:02:47 +0100 | [diff] [blame^] | 588 | NV_ERROR(cli, "reloc outside of bo\n"); |
Ben Skeggs | a1606a9 | 2010-02-12 10:27:35 +1000 | [diff] [blame] | 589 | ret = -EINVAL; |
| 590 | break; |
| 591 | } |
| 592 | |
| 593 | if (!nvbo->kmap.virtual) { |
| 594 | ret = ttm_bo_kmap(&nvbo->bo, 0, nvbo->bo.mem.num_pages, |
| 595 | &nvbo->kmap); |
| 596 | if (ret) { |
Marcin Slusarz | a84fa1a | 2013-02-03 22:02:47 +0100 | [diff] [blame^] | 597 | NV_ERROR(cli, "failed kmap for reloc\n"); |
Ben Skeggs | a1606a9 | 2010-02-12 10:27:35 +1000 | [diff] [blame] | 598 | break; |
| 599 | } |
| 600 | nvbo->validate_mapped = true; |
| 601 | } |
| 602 | |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 603 | if (r->flags & NOUVEAU_GEM_RELOC_LOW) |
Ben Skeggs | a1606a9 | 2010-02-12 10:27:35 +1000 | [diff] [blame] | 604 | data = b->presumed.offset + r->data; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 605 | else |
| 606 | if (r->flags & NOUVEAU_GEM_RELOC_HIGH) |
Ben Skeggs | a1606a9 | 2010-02-12 10:27:35 +1000 | [diff] [blame] | 607 | data = (b->presumed.offset + r->data) >> 32; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 608 | else |
| 609 | data = r->data; |
| 610 | |
| 611 | if (r->flags & NOUVEAU_GEM_RELOC_OR) { |
Ben Skeggs | a1606a9 | 2010-02-12 10:27:35 +1000 | [diff] [blame] | 612 | if (b->presumed.domain == NOUVEAU_GEM_DOMAIN_GART) |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 613 | data |= r->tor; |
| 614 | else |
| 615 | data |= r->vor; |
| 616 | } |
| 617 | |
Thomas Hellstrom | 702adba | 2010-11-17 12:28:29 +0000 | [diff] [blame] | 618 | spin_lock(&nvbo->bo.bdev->fence_lock); |
Ben Skeggs | a1606a9 | 2010-02-12 10:27:35 +1000 | [diff] [blame] | 619 | ret = ttm_bo_wait(&nvbo->bo, false, false, false); |
Thomas Hellstrom | 702adba | 2010-11-17 12:28:29 +0000 | [diff] [blame] | 620 | spin_unlock(&nvbo->bo.bdev->fence_lock); |
Ben Skeggs | a1606a9 | 2010-02-12 10:27:35 +1000 | [diff] [blame] | 621 | if (ret) { |
Marcin Slusarz | a84fa1a | 2013-02-03 22:02:47 +0100 | [diff] [blame^] | 622 | NV_ERROR(cli, "reloc wait_idle failed: %d\n", ret); |
Ben Skeggs | a1606a9 | 2010-02-12 10:27:35 +1000 | [diff] [blame] | 623 | break; |
| 624 | } |
Ben Skeggs | a1606a9 | 2010-02-12 10:27:35 +1000 | [diff] [blame] | 625 | |
| 626 | nouveau_bo_wr32(nvbo, r->reloc_bo_offset >> 2, data); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 627 | } |
| 628 | |
| 629 | kfree(reloc); |
| 630 | return ret; |
| 631 | } |
| 632 | |
| 633 | int |
| 634 | nouveau_gem_ioctl_pushbuf(struct drm_device *dev, void *data, |
| 635 | struct drm_file *file_priv) |
| 636 | { |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 637 | struct nouveau_abi16 *abi16 = nouveau_abi16_get(file_priv, dev); |
Marcin Slusarz | a84fa1a | 2013-02-03 22:02:47 +0100 | [diff] [blame^] | 638 | struct nouveau_cli *cli = nouveau_cli(file_priv); |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 639 | struct nouveau_abi16_chan *temp; |
| 640 | struct nouveau_drm *drm = nouveau_drm(dev); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 641 | struct drm_nouveau_gem_pushbuf *req = data; |
Ben Skeggs | a1606a9 | 2010-02-12 10:27:35 +1000 | [diff] [blame] | 642 | struct drm_nouveau_gem_pushbuf_push *push; |
| 643 | struct drm_nouveau_gem_pushbuf_bo *bo; |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 644 | struct nouveau_channel *chan = NULL; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 645 | struct validate_op op; |
Francisco Jerez | 6e86e04 | 2010-07-03 18:36:39 +0200 | [diff] [blame] | 646 | struct nouveau_fence *fence = NULL; |
Ben Skeggs | a1606a9 | 2010-02-12 10:27:35 +1000 | [diff] [blame] | 647 | int i, j, ret = 0, do_reloc = 0; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 648 | |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 649 | if (unlikely(!abi16)) |
| 650 | return -ENOMEM; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 651 | |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 652 | list_for_each_entry(temp, &abi16->channels, head) { |
| 653 | if (temp->chan->handle == (NVDRM_CHAN | req->channel)) { |
| 654 | chan = temp->chan; |
| 655 | break; |
| 656 | } |
| 657 | } |
| 658 | |
| 659 | if (!chan) |
| 660 | return nouveau_abi16_put(abi16, -ENOENT); |
| 661 | |
| 662 | req->vram_available = drm->gem.vram_available; |
| 663 | req->gart_available = drm->gem.gart_available; |
Ben Skeggs | a1606a9 | 2010-02-12 10:27:35 +1000 | [diff] [blame] | 664 | if (unlikely(req->nr_push == 0)) |
| 665 | goto out_next; |
| 666 | |
| 667 | if (unlikely(req->nr_push > NOUVEAU_GEM_MAX_PUSH)) { |
Marcin Slusarz | a84fa1a | 2013-02-03 22:02:47 +0100 | [diff] [blame^] | 668 | NV_ERROR(cli, "pushbuf push count exceeds limit: %d max %d\n", |
Ben Skeggs | a1606a9 | 2010-02-12 10:27:35 +1000 | [diff] [blame] | 669 | req->nr_push, NOUVEAU_GEM_MAX_PUSH); |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 670 | return nouveau_abi16_put(abi16, -EINVAL); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 671 | } |
| 672 | |
Ben Skeggs | a1606a9 | 2010-02-12 10:27:35 +1000 | [diff] [blame] | 673 | if (unlikely(req->nr_buffers > NOUVEAU_GEM_MAX_BUFFERS)) { |
Marcin Slusarz | a84fa1a | 2013-02-03 22:02:47 +0100 | [diff] [blame^] | 674 | NV_ERROR(cli, "pushbuf bo count exceeds limit: %d max %d\n", |
Ben Skeggs | a1606a9 | 2010-02-12 10:27:35 +1000 | [diff] [blame] | 675 | req->nr_buffers, NOUVEAU_GEM_MAX_BUFFERS); |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 676 | return nouveau_abi16_put(abi16, -EINVAL); |
Ben Skeggs | a1606a9 | 2010-02-12 10:27:35 +1000 | [diff] [blame] | 677 | } |
| 678 | |
| 679 | if (unlikely(req->nr_relocs > NOUVEAU_GEM_MAX_RELOCS)) { |
Marcin Slusarz | a84fa1a | 2013-02-03 22:02:47 +0100 | [diff] [blame^] | 680 | NV_ERROR(cli, "pushbuf reloc count exceeds limit: %d max %d\n", |
Ben Skeggs | a1606a9 | 2010-02-12 10:27:35 +1000 | [diff] [blame] | 681 | req->nr_relocs, NOUVEAU_GEM_MAX_RELOCS); |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 682 | return nouveau_abi16_put(abi16, -EINVAL); |
Ben Skeggs | a1606a9 | 2010-02-12 10:27:35 +1000 | [diff] [blame] | 683 | } |
| 684 | |
| 685 | push = u_memcpya(req->push, req->nr_push, sizeof(*push)); |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 686 | if (IS_ERR(push)) |
| 687 | return nouveau_abi16_put(abi16, PTR_ERR(push)); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 688 | |
| 689 | bo = u_memcpya(req->buffers, req->nr_buffers, sizeof(*bo)); |
| 690 | if (IS_ERR(bo)) { |
Ben Skeggs | a1606a9 | 2010-02-12 10:27:35 +1000 | [diff] [blame] | 691 | kfree(push); |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 692 | return nouveau_abi16_put(abi16, PTR_ERR(bo)); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 693 | } |
| 694 | |
Ben Skeggs | accf949 | 2012-03-16 12:40:17 +1000 | [diff] [blame] | 695 | /* Ensure all push buffers are on validate list */ |
Ben Skeggs | 415e618 | 2010-07-23 09:06:52 +1000 | [diff] [blame] | 696 | for (i = 0; i < req->nr_push; i++) { |
| 697 | if (push[i].bo_index >= req->nr_buffers) { |
Marcin Slusarz | a84fa1a | 2013-02-03 22:02:47 +0100 | [diff] [blame^] | 698 | NV_ERROR(cli, "push %d buffer not in list\n", i); |
Ben Skeggs | 415e618 | 2010-07-23 09:06:52 +1000 | [diff] [blame] | 699 | ret = -EINVAL; |
Marcin Slusarz | 7fa0cba2 | 2011-03-07 12:31:35 +0100 | [diff] [blame] | 700 | goto out_prevalid; |
Ben Skeggs | 415e618 | 2010-07-23 09:06:52 +1000 | [diff] [blame] | 701 | } |
Ben Skeggs | 415e618 | 2010-07-23 09:06:52 +1000 | [diff] [blame] | 702 | } |
| 703 | |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 704 | /* Validate buffer list */ |
| 705 | ret = nouveau_gem_pushbuf_validate(chan, file_priv, bo, req->buffers, |
| 706 | req->nr_buffers, &op, &do_reloc); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 707 | if (ret) { |
Ben Skeggs | 938c40e | 2010-10-12 09:54:54 +1000 | [diff] [blame] | 708 | if (ret != -ERESTARTSYS) |
Marcin Slusarz | a84fa1a | 2013-02-03 22:02:47 +0100 | [diff] [blame^] | 709 | NV_ERROR(cli, "validate: %d\n", ret); |
Marcin Slusarz | 7fa0cba2 | 2011-03-07 12:31:35 +0100 | [diff] [blame] | 710 | goto out_prevalid; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 711 | } |
| 712 | |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 713 | /* Apply any relocations that are required */ |
| 714 | if (do_reloc) { |
Marcin Slusarz | a84fa1a | 2013-02-03 22:02:47 +0100 | [diff] [blame^] | 715 | ret = nouveau_gem_pushbuf_reloc_apply(cli, req, bo); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 716 | if (ret) { |
Marcin Slusarz | a84fa1a | 2013-02-03 22:02:47 +0100 | [diff] [blame^] | 717 | NV_ERROR(cli, "reloc apply: %d\n", ret); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 718 | goto out; |
| 719 | } |
| 720 | } |
| 721 | |
Ben Skeggs | 9a391ad | 2010-02-11 16:37:26 +1000 | [diff] [blame] | 722 | if (chan->dma.ib_max) { |
Ben Skeggs | 5e120f6 | 2012-04-30 13:55:29 +1000 | [diff] [blame] | 723 | ret = nouveau_dma_wait(chan, req->nr_push + 1, 16); |
Ben Skeggs | 9a391ad | 2010-02-11 16:37:26 +1000 | [diff] [blame] | 724 | if (ret) { |
Marcin Slusarz | a84fa1a | 2013-02-03 22:02:47 +0100 | [diff] [blame^] | 725 | NV_ERROR(cli, "nv50cal_space: %d\n", ret); |
Ben Skeggs | 9a391ad | 2010-02-11 16:37:26 +1000 | [diff] [blame] | 726 | goto out; |
| 727 | } |
| 728 | |
Ben Skeggs | a1606a9 | 2010-02-12 10:27:35 +1000 | [diff] [blame] | 729 | for (i = 0; i < req->nr_push; i++) { |
| 730 | struct nouveau_bo *nvbo = (void *)(unsigned long) |
| 731 | bo[push[i].bo_index].user_priv; |
| 732 | |
| 733 | nv50_dma_push(chan, nvbo, push[i].offset, |
| 734 | push[i].length); |
| 735 | } |
Ben Skeggs | 9a391ad | 2010-02-11 16:37:26 +1000 | [diff] [blame] | 736 | } else |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 737 | if (nv_device(drm->device)->chipset >= 0x25) { |
Ben Skeggs | a1606a9 | 2010-02-12 10:27:35 +1000 | [diff] [blame] | 738 | ret = RING_SPACE(chan, req->nr_push * 2); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 739 | if (ret) { |
Marcin Slusarz | a84fa1a | 2013-02-03 22:02:47 +0100 | [diff] [blame^] | 740 | NV_ERROR(cli, "cal_space: %d\n", ret); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 741 | goto out; |
| 742 | } |
Ben Skeggs | a1606a9 | 2010-02-12 10:27:35 +1000 | [diff] [blame] | 743 | |
| 744 | for (i = 0; i < req->nr_push; i++) { |
| 745 | struct nouveau_bo *nvbo = (void *)(unsigned long) |
| 746 | bo[push[i].bo_index].user_priv; |
Ben Skeggs | a1606a9 | 2010-02-12 10:27:35 +1000 | [diff] [blame] | 747 | |
Ben Skeggs | 3a92d37 | 2012-08-04 05:46:01 +1000 | [diff] [blame] | 748 | OUT_RING(chan, (nvbo->bo.offset + push[i].offset) | 2); |
Ben Skeggs | a1606a9 | 2010-02-12 10:27:35 +1000 | [diff] [blame] | 749 | OUT_RING(chan, 0); |
| 750 | } |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 751 | } else { |
Ben Skeggs | a1606a9 | 2010-02-12 10:27:35 +1000 | [diff] [blame] | 752 | ret = RING_SPACE(chan, req->nr_push * (2 + NOUVEAU_DMA_SKIPS)); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 753 | if (ret) { |
Marcin Slusarz | a84fa1a | 2013-02-03 22:02:47 +0100 | [diff] [blame^] | 754 | NV_ERROR(cli, "jmp_space: %d\n", ret); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 755 | goto out; |
| 756 | } |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 757 | |
Ben Skeggs | a1606a9 | 2010-02-12 10:27:35 +1000 | [diff] [blame] | 758 | for (i = 0; i < req->nr_push; i++) { |
| 759 | struct nouveau_bo *nvbo = (void *)(unsigned long) |
| 760 | bo[push[i].bo_index].user_priv; |
Ben Skeggs | a1606a9 | 2010-02-12 10:27:35 +1000 | [diff] [blame] | 761 | uint32_t cmd; |
| 762 | |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 763 | cmd = chan->push.vma.offset + ((chan->dma.cur + 2) << 2); |
Ben Skeggs | a1606a9 | 2010-02-12 10:27:35 +1000 | [diff] [blame] | 764 | cmd |= 0x20000000; |
| 765 | if (unlikely(cmd != req->suffix0)) { |
| 766 | if (!nvbo->kmap.virtual) { |
| 767 | ret = ttm_bo_kmap(&nvbo->bo, 0, |
| 768 | nvbo->bo.mem. |
| 769 | num_pages, |
| 770 | &nvbo->kmap); |
| 771 | if (ret) { |
| 772 | WIND_RING(chan); |
| 773 | goto out; |
| 774 | } |
| 775 | nvbo->validate_mapped = true; |
| 776 | } |
| 777 | |
| 778 | nouveau_bo_wr32(nvbo, (push[i].offset + |
| 779 | push[i].length - 8) / 4, cmd); |
| 780 | } |
| 781 | |
Ben Skeggs | 3a92d37 | 2012-08-04 05:46:01 +1000 | [diff] [blame] | 782 | OUT_RING(chan, 0x20000000 | |
| 783 | (nvbo->bo.offset + push[i].offset)); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 784 | OUT_RING(chan, 0); |
Ben Skeggs | a1606a9 | 2010-02-12 10:27:35 +1000 | [diff] [blame] | 785 | for (j = 0; j < NOUVEAU_DMA_SKIPS; j++) |
| 786 | OUT_RING(chan, 0); |
| 787 | } |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 788 | } |
| 789 | |
Ben Skeggs | d375e7d5 | 2012-04-30 13:30:00 +1000 | [diff] [blame] | 790 | ret = nouveau_fence_new(chan, &fence); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 791 | if (ret) { |
Marcin Slusarz | a84fa1a | 2013-02-03 22:02:47 +0100 | [diff] [blame^] | 792 | NV_ERROR(cli, "error fencing pushbuf: %d\n", ret); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 793 | WIND_RING(chan); |
| 794 | goto out; |
| 795 | } |
| 796 | |
| 797 | out: |
Luca Barbieri | 234896a | 2010-01-06 04:02:45 +0100 | [diff] [blame] | 798 | validate_fini(&op, fence); |
Marcin Slusarz | 382d62e | 2010-10-20 21:50:24 +0200 | [diff] [blame] | 799 | nouveau_fence_unref(&fence); |
Marcin Slusarz | 7fa0cba2 | 2011-03-07 12:31:35 +0100 | [diff] [blame] | 800 | |
| 801 | out_prevalid: |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 802 | kfree(bo); |
Ben Skeggs | a1606a9 | 2010-02-12 10:27:35 +1000 | [diff] [blame] | 803 | kfree(push); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 804 | |
| 805 | out_next: |
Ben Skeggs | 9a391ad | 2010-02-11 16:37:26 +1000 | [diff] [blame] | 806 | if (chan->dma.ib_max) { |
| 807 | req->suffix0 = 0x00000000; |
| 808 | req->suffix1 = 0x00000000; |
| 809 | } else |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 810 | if (nv_device(drm->device)->chipset >= 0x25) { |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 811 | req->suffix0 = 0x00020000; |
| 812 | req->suffix1 = 0x00000000; |
| 813 | } else { |
| 814 | req->suffix0 = 0x20000000 | |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 815 | (chan->push.vma.offset + ((chan->dma.cur + 2) << 2)); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 816 | req->suffix1 = 0x00000000; |
| 817 | } |
| 818 | |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 819 | return nouveau_abi16_put(abi16, ret); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 820 | } |
| 821 | |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 822 | static inline uint32_t |
| 823 | domain_to_ttm(struct nouveau_bo *nvbo, uint32_t domain) |
| 824 | { |
| 825 | uint32_t flags = 0; |
| 826 | |
| 827 | if (domain & NOUVEAU_GEM_DOMAIN_VRAM) |
| 828 | flags |= TTM_PL_FLAG_VRAM; |
| 829 | if (domain & NOUVEAU_GEM_DOMAIN_GART) |
| 830 | flags |= TTM_PL_FLAG_TT; |
| 831 | |
| 832 | return flags; |
| 833 | } |
| 834 | |
| 835 | int |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 836 | nouveau_gem_ioctl_cpu_prep(struct drm_device *dev, void *data, |
| 837 | struct drm_file *file_priv) |
| 838 | { |
| 839 | struct drm_nouveau_gem_cpu_prep *req = data; |
| 840 | struct drm_gem_object *gem; |
| 841 | struct nouveau_bo *nvbo; |
| 842 | bool no_wait = !!(req->flags & NOUVEAU_GEM_CPU_PREP_NOWAIT); |
| 843 | int ret = -EINVAL; |
| 844 | |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 845 | gem = drm_gem_object_lookup(dev, file_priv, req->handle); |
| 846 | if (!gem) |
Chris Wilson | bf79cb9 | 2010-08-04 14:19:46 +0100 | [diff] [blame] | 847 | return -ENOENT; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 848 | nvbo = nouveau_gem_object(gem); |
| 849 | |
Ben Skeggs | 21e86c1 | 2010-10-11 11:48:45 +1000 | [diff] [blame] | 850 | spin_lock(&nvbo->bo.bdev->fence_lock); |
| 851 | ret = ttm_bo_wait(&nvbo->bo, true, true, no_wait); |
| 852 | spin_unlock(&nvbo->bo.bdev->fence_lock); |
Luca Barbieri | bc9025b | 2010-02-09 05:49:12 +0000 | [diff] [blame] | 853 | drm_gem_object_unreference_unlocked(gem); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 854 | return ret; |
| 855 | } |
| 856 | |
| 857 | int |
| 858 | nouveau_gem_ioctl_cpu_fini(struct drm_device *dev, void *data, |
| 859 | struct drm_file *file_priv) |
| 860 | { |
Ben Skeggs | 21e86c1 | 2010-10-11 11:48:45 +1000 | [diff] [blame] | 861 | return 0; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 862 | } |
| 863 | |
| 864 | int |
| 865 | nouveau_gem_ioctl_info(struct drm_device *dev, void *data, |
| 866 | struct drm_file *file_priv) |
| 867 | { |
| 868 | struct drm_nouveau_gem_info *req = data; |
| 869 | struct drm_gem_object *gem; |
| 870 | int ret; |
| 871 | |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 872 | gem = drm_gem_object_lookup(dev, file_priv, req->handle); |
| 873 | if (!gem) |
Chris Wilson | bf79cb9 | 2010-08-04 14:19:46 +0100 | [diff] [blame] | 874 | return -ENOENT; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 875 | |
Ben Skeggs | e758a31 | 2011-06-07 13:28:11 +1000 | [diff] [blame] | 876 | ret = nouveau_gem_info(file_priv, gem, req); |
Luca Barbieri | bc9025b | 2010-02-09 05:49:12 +0000 | [diff] [blame] | 877 | drm_gem_object_unreference_unlocked(gem); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 878 | return ret; |
| 879 | } |
| 880 | |