| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * Copyright (C) 2015 Etnaviv Project |
|---|
| 3 | | - * |
|---|
| 4 | | - * This program is free software; you can redistribute it and/or modify it |
|---|
| 5 | | - * under the terms of the GNU General Public License version 2 as published by |
|---|
| 6 | | - * the Free Software Foundation. |
|---|
| 7 | | - * |
|---|
| 8 | | - * This program is distributed in the hope that it will be useful, but WITHOUT |
|---|
| 9 | | - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|---|
| 10 | | - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
|---|
| 11 | | - * more details. |
|---|
| 12 | | - * |
|---|
| 13 | | - * You should have received a copy of the GNU General Public License along with |
|---|
| 14 | | - * this program. If not, see <http://www.gnu.org/licenses/>. |
|---|
| 15 | 4 | */ |
|---|
| 16 | 5 | |
|---|
| 6 | +#include <drm/drm_file.h> |
|---|
| 17 | 7 | #include <linux/dma-fence-array.h> |
|---|
| 18 | | -#include <linux/reservation.h> |
|---|
| 8 | +#include <linux/file.h> |
|---|
| 9 | +#include <linux/pm_runtime.h> |
|---|
| 10 | +#include <linux/dma-resv.h> |
|---|
| 19 | 11 | #include <linux/sync_file.h> |
|---|
| 12 | +#include <linux/uaccess.h> |
|---|
| 13 | +#include <linux/vmalloc.h> |
|---|
| 14 | + |
|---|
| 20 | 15 | #include "etnaviv_cmdbuf.h" |
|---|
| 21 | 16 | #include "etnaviv_drv.h" |
|---|
| 22 | 17 | #include "etnaviv_gpu.h" |
|---|
| .. | .. |
|---|
| 77 | 72 | } |
|---|
| 78 | 73 | |
|---|
| 79 | 74 | submit->bos[i].flags = bo->flags; |
|---|
| 75 | + if (submit->flags & ETNA_SUBMIT_SOFTPIN) { |
|---|
| 76 | + if (bo->presumed < ETNAVIV_SOFTPIN_START_ADDRESS) { |
|---|
| 77 | + DRM_ERROR("invalid softpin address\n"); |
|---|
| 78 | + ret = -EINVAL; |
|---|
| 79 | + goto out_unlock; |
|---|
| 80 | + } |
|---|
| 81 | + submit->bos[i].va = bo->presumed; |
|---|
| 82 | + } |
|---|
| 80 | 83 | |
|---|
| 81 | 84 | /* normally use drm_gem_object_lookup(), but for bulk lookup |
|---|
| 82 | 85 | * all under single table_lock just hit object_idr directly: |
|---|
| .. | .. |
|---|
| 108 | 111 | static void submit_unlock_object(struct etnaviv_gem_submit *submit, int i) |
|---|
| 109 | 112 | { |
|---|
| 110 | 113 | if (submit->bos[i].flags & BO_LOCKED) { |
|---|
| 111 | | - struct etnaviv_gem_object *etnaviv_obj = submit->bos[i].obj; |
|---|
| 114 | + struct drm_gem_object *obj = &submit->bos[i].obj->base; |
|---|
| 112 | 115 | |
|---|
| 113 | | - ww_mutex_unlock(&etnaviv_obj->resv->lock); |
|---|
| 116 | + dma_resv_unlock(obj->resv); |
|---|
| 114 | 117 | submit->bos[i].flags &= ~BO_LOCKED; |
|---|
| 115 | 118 | } |
|---|
| 116 | 119 | } |
|---|
| .. | .. |
|---|
| 122 | 125 | |
|---|
| 123 | 126 | retry: |
|---|
| 124 | 127 | for (i = 0; i < submit->nr_bos; i++) { |
|---|
| 125 | | - struct etnaviv_gem_object *etnaviv_obj = submit->bos[i].obj; |
|---|
| 128 | + struct drm_gem_object *obj = &submit->bos[i].obj->base; |
|---|
| 126 | 129 | |
|---|
| 127 | 130 | if (slow_locked == i) |
|---|
| 128 | 131 | slow_locked = -1; |
|---|
| .. | .. |
|---|
| 130 | 133 | contended = i; |
|---|
| 131 | 134 | |
|---|
| 132 | 135 | if (!(submit->bos[i].flags & BO_LOCKED)) { |
|---|
| 133 | | - ret = ww_mutex_lock_interruptible(&etnaviv_obj->resv->lock, |
|---|
| 134 | | - ticket); |
|---|
| 136 | + ret = dma_resv_lock_interruptible(obj->resv, ticket); |
|---|
| 135 | 137 | if (ret == -EALREADY) |
|---|
| 136 | 138 | DRM_ERROR("BO at index %u already on submit list\n", |
|---|
| 137 | 139 | i); |
|---|
| .. | .. |
|---|
| 153 | 155 | submit_unlock_object(submit, slow_locked); |
|---|
| 154 | 156 | |
|---|
| 155 | 157 | if (ret == -EDEADLK) { |
|---|
| 156 | | - struct etnaviv_gem_object *etnaviv_obj; |
|---|
| 158 | + struct drm_gem_object *obj; |
|---|
| 157 | 159 | |
|---|
| 158 | | - etnaviv_obj = submit->bos[contended].obj; |
|---|
| 160 | + obj = &submit->bos[contended].obj->base; |
|---|
| 159 | 161 | |
|---|
| 160 | 162 | /* we lost out in a seqno race, lock and retry.. */ |
|---|
| 161 | | - ret = ww_mutex_lock_slow_interruptible(&etnaviv_obj->resv->lock, |
|---|
| 162 | | - ticket); |
|---|
| 163 | + ret = dma_resv_lock_slow_interruptible(obj->resv, ticket); |
|---|
| 163 | 164 | if (!ret) { |
|---|
| 164 | 165 | submit->bos[contended].flags |= BO_LOCKED; |
|---|
| 165 | 166 | slow_locked = contended; |
|---|
| .. | .. |
|---|
| 176 | 177 | |
|---|
| 177 | 178 | for (i = 0; i < submit->nr_bos; i++) { |
|---|
| 178 | 179 | struct etnaviv_gem_submit_bo *bo = &submit->bos[i]; |
|---|
| 179 | | - struct reservation_object *robj = bo->obj->resv; |
|---|
| 180 | + struct dma_resv *robj = bo->obj->base.resv; |
|---|
| 180 | 181 | |
|---|
| 181 | 182 | if (!(bo->flags & ETNA_SUBMIT_BO_WRITE)) { |
|---|
| 182 | | - ret = reservation_object_reserve_shared(robj); |
|---|
| 183 | + ret = dma_resv_reserve_shared(robj, 1); |
|---|
| 183 | 184 | if (ret) |
|---|
| 184 | 185 | return ret; |
|---|
| 185 | 186 | } |
|---|
| .. | .. |
|---|
| 188 | 189 | continue; |
|---|
| 189 | 190 | |
|---|
| 190 | 191 | if (bo->flags & ETNA_SUBMIT_BO_WRITE) { |
|---|
| 191 | | - ret = reservation_object_get_fences_rcu(robj, &bo->excl, |
|---|
| 192 | + ret = dma_resv_get_fences_rcu(robj, &bo->excl, |
|---|
| 192 | 193 | &bo->nr_shared, |
|---|
| 193 | 194 | &bo->shared); |
|---|
| 194 | 195 | if (ret) |
|---|
| 195 | 196 | return ret; |
|---|
| 196 | 197 | } else { |
|---|
| 197 | | - bo->excl = reservation_object_get_excl_rcu(robj); |
|---|
| 198 | + bo->excl = dma_resv_get_excl_rcu(robj); |
|---|
| 198 | 199 | } |
|---|
| 199 | 200 | |
|---|
| 200 | 201 | } |
|---|
| .. | .. |
|---|
| 207 | 208 | int i; |
|---|
| 208 | 209 | |
|---|
| 209 | 210 | for (i = 0; i < submit->nr_bos; i++) { |
|---|
| 210 | | - struct etnaviv_gem_object *etnaviv_obj = submit->bos[i].obj; |
|---|
| 211 | + struct drm_gem_object *obj = &submit->bos[i].obj->base; |
|---|
| 211 | 212 | |
|---|
| 212 | 213 | if (submit->bos[i].flags & ETNA_SUBMIT_BO_WRITE) |
|---|
| 213 | | - reservation_object_add_excl_fence(etnaviv_obj->resv, |
|---|
| 214 | + dma_resv_add_excl_fence(obj->resv, |
|---|
| 214 | 215 | submit->out_fence); |
|---|
| 215 | 216 | else |
|---|
| 216 | | - reservation_object_add_shared_fence(etnaviv_obj->resv, |
|---|
| 217 | + dma_resv_add_shared_fence(obj->resv, |
|---|
| 217 | 218 | submit->out_fence); |
|---|
| 218 | 219 | |
|---|
| 219 | 220 | submit_unlock_object(submit, i); |
|---|
| .. | .. |
|---|
| 229 | 230 | struct etnaviv_vram_mapping *mapping; |
|---|
| 230 | 231 | |
|---|
| 231 | 232 | mapping = etnaviv_gem_mapping_get(&etnaviv_obj->base, |
|---|
| 232 | | - submit->gpu); |
|---|
| 233 | + submit->mmu_context, |
|---|
| 234 | + submit->bos[i].va); |
|---|
| 233 | 235 | if (IS_ERR(mapping)) { |
|---|
| 234 | 236 | ret = PTR_ERR(mapping); |
|---|
| 235 | 237 | break; |
|---|
| 236 | 238 | } |
|---|
| 239 | + |
|---|
| 240 | + if ((submit->flags & ETNA_SUBMIT_SOFTPIN) && |
|---|
| 241 | + submit->bos[i].va != mapping->iova) { |
|---|
| 242 | + etnaviv_gem_mapping_unreference(mapping); |
|---|
| 243 | + return -EINVAL; |
|---|
| 244 | + } |
|---|
| 245 | + |
|---|
| 237 | 246 | atomic_inc(&etnaviv_obj->gpu_active); |
|---|
| 238 | 247 | |
|---|
| 239 | 248 | submit->bos[i].flags |= BO_PINNED; |
|---|
| .. | .. |
|---|
| 265 | 274 | u32 i, last_offset = 0; |
|---|
| 266 | 275 | u32 *ptr = stream; |
|---|
| 267 | 276 | int ret; |
|---|
| 277 | + |
|---|
| 278 | + /* Submits using softpin don't blend with relocs */ |
|---|
| 279 | + if ((submit->flags & ETNA_SUBMIT_SOFTPIN) && nr_relocs != 0) |
|---|
| 280 | + return -EINVAL; |
|---|
| 268 | 281 | |
|---|
| 269 | 282 | for (i = 0; i < nr_relocs; i++) { |
|---|
| 270 | 283 | const struct drm_etnaviv_gem_submit_reloc *r = relocs + i; |
|---|
| .. | .. |
|---|
| 366 | 379 | if (submit->cmdbuf.suballoc) |
|---|
| 367 | 380 | etnaviv_cmdbuf_free(&submit->cmdbuf); |
|---|
| 368 | 381 | |
|---|
| 382 | + if (submit->mmu_context) |
|---|
| 383 | + etnaviv_iommu_context_put(submit->mmu_context); |
|---|
| 384 | + |
|---|
| 385 | + if (submit->prev_mmu_context) |
|---|
| 386 | + etnaviv_iommu_context_put(submit->prev_mmu_context); |
|---|
| 387 | + |
|---|
| 369 | 388 | for (i = 0; i < submit->nr_bos; i++) { |
|---|
| 370 | 389 | struct etnaviv_gem_object *etnaviv_obj = submit->bos[i].obj; |
|---|
| 371 | 390 | |
|---|
| .. | .. |
|---|
| 379 | 398 | |
|---|
| 380 | 399 | /* if the GPU submit failed, objects might still be locked */ |
|---|
| 381 | 400 | submit_unlock_object(submit, i); |
|---|
| 382 | | - drm_gem_object_put_unlocked(&etnaviv_obj->base); |
|---|
| 401 | + drm_gem_object_put(&etnaviv_obj->base); |
|---|
| 383 | 402 | } |
|---|
| 384 | 403 | |
|---|
| 385 | 404 | wake_up_all(&submit->gpu->fence_event); |
|---|
| .. | .. |
|---|
| 441 | 460 | |
|---|
| 442 | 461 | if (args->flags & ~ETNA_SUBMIT_FLAGS) { |
|---|
| 443 | 462 | DRM_ERROR("invalid flags: 0x%x\n", args->flags); |
|---|
| 463 | + return -EINVAL; |
|---|
| 464 | + } |
|---|
| 465 | + |
|---|
| 466 | + if ((args->flags & ETNA_SUBMIT_SOFTPIN) && |
|---|
| 467 | + priv->mmu_global->version != ETNAVIV_IOMMU_V2) { |
|---|
| 468 | + DRM_ERROR("softpin requested on incompatible MMU\n"); |
|---|
| 444 | 469 | return -EINVAL; |
|---|
| 445 | 470 | } |
|---|
| 446 | 471 | |
|---|
| .. | .. |
|---|
| 507 | 532 | goto err_submit_ww_acquire; |
|---|
| 508 | 533 | } |
|---|
| 509 | 534 | |
|---|
| 510 | | - ret = etnaviv_cmdbuf_init(gpu->cmdbuf_suballoc, &submit->cmdbuf, |
|---|
| 535 | + ret = etnaviv_cmdbuf_init(priv->cmdbuf_suballoc, &submit->cmdbuf, |
|---|
| 511 | 536 | ALIGN(args->stream_size, 8) + 8); |
|---|
| 512 | 537 | if (ret) |
|---|
| 513 | 538 | goto err_submit_objects; |
|---|
| 514 | 539 | |
|---|
| 515 | | - submit->cmdbuf.ctx = file->driver_priv; |
|---|
| 540 | + submit->ctx = file->driver_priv; |
|---|
| 541 | + submit->mmu_context = etnaviv_iommu_context_get(submit->ctx->mmu); |
|---|
| 516 | 542 | submit->exec_state = args->exec_state; |
|---|
| 517 | 543 | submit->flags = args->flags; |
|---|
| 518 | 544 | |
|---|
| .. | .. |
|---|
| 520 | 546 | if (ret) |
|---|
| 521 | 547 | goto err_submit_objects; |
|---|
| 522 | 548 | |
|---|
| 523 | | - if (!etnaviv_cmd_validate_one(gpu, stream, args->stream_size / 4, |
|---|
| 549 | + if ((priv->mmu_global->version != ETNAVIV_IOMMU_V2) && |
|---|
| 550 | + !etnaviv_cmd_validate_one(gpu, stream, args->stream_size / 4, |
|---|
| 524 | 551 | relocs, args->nr_relocs)) { |
|---|
| 525 | 552 | ret = -EINVAL; |
|---|
| 526 | 553 | goto err_submit_objects; |
|---|