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