1 1.6 riastrad /* $NetBSD: nouveau_nv10_fence.c,v 1.6 2021/12/18 23:45:32 riastradh Exp $ */ 2 1.1 riastrad 3 1.1 riastrad /* 4 1.1 riastrad * Copyright 2012 Red Hat Inc. 5 1.1 riastrad * 6 1.1 riastrad * Permission is hereby granted, free of charge, to any person obtaining a 7 1.1 riastrad * copy of this software and associated documentation files (the "Software"), 8 1.1 riastrad * to deal in the Software without restriction, including without limitation 9 1.1 riastrad * the rights to use, copy, modify, merge, publish, distribute, sublicense, 10 1.1 riastrad * and/or sell copies of the Software, and to permit persons to whom the 11 1.1 riastrad * Software is furnished to do so, subject to the following conditions: 12 1.1 riastrad * 13 1.1 riastrad * The above copyright notice and this permission notice shall be included in 14 1.1 riastrad * all copies or substantial portions of the Software. 15 1.1 riastrad * 16 1.1 riastrad * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 1.1 riastrad * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 1.1 riastrad * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 19 1.1 riastrad * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR 20 1.1 riastrad * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 21 1.1 riastrad * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 22 1.1 riastrad * OTHER DEALINGS IN THE SOFTWARE. 23 1.1 riastrad * 24 1.1 riastrad * Authors: Ben Skeggs <bskeggs (at) redhat.com> 25 1.1 riastrad */ 26 1.1 riastrad 27 1.1 riastrad #include <sys/cdefs.h> 28 1.4 riastrad __KERNEL_RCSID(0, "$NetBSD: nouveau_nv10_fence.c,v 1.6 2021/12/18 23:45:32 riastradh Exp $"); 29 1.1 riastrad 30 1.6 riastrad #include "nouveau_drv.h" 31 1.1 riastrad #include "nouveau_dma.h" 32 1.1 riastrad #include "nv10_fence.h" 33 1.1 riastrad 34 1.1 riastrad int 35 1.1 riastrad nv10_fence_emit(struct nouveau_fence *fence) 36 1.1 riastrad { 37 1.1 riastrad struct nouveau_channel *chan = fence->channel; 38 1.1 riastrad int ret = RING_SPACE(chan, 2); 39 1.1 riastrad if (ret == 0) { 40 1.1 riastrad BEGIN_NV04(chan, 0, NV10_SUBCHAN_REF_CNT, 1); 41 1.4 riastrad OUT_RING (chan, fence->base.seqno); 42 1.1 riastrad FIRE_RING (chan); 43 1.1 riastrad } 44 1.1 riastrad return ret; 45 1.1 riastrad } 46 1.1 riastrad 47 1.1 riastrad 48 1.1 riastrad static int 49 1.1 riastrad nv10_fence_sync(struct nouveau_fence *fence, 50 1.1 riastrad struct nouveau_channel *prev, struct nouveau_channel *chan) 51 1.1 riastrad { 52 1.1 riastrad return -ENODEV; 53 1.1 riastrad } 54 1.1 riastrad 55 1.1 riastrad u32 56 1.1 riastrad nv10_fence_read(struct nouveau_channel *chan) 57 1.1 riastrad { 58 1.4 riastrad return nvif_rd32(&chan->user, 0x0048); 59 1.1 riastrad } 60 1.1 riastrad 61 1.1 riastrad void 62 1.1 riastrad nv10_fence_context_del(struct nouveau_channel *chan) 63 1.1 riastrad { 64 1.1 riastrad struct nv10_fence_chan *fctx = chan->fence; 65 1.1 riastrad nouveau_fence_context_del(&fctx->base); 66 1.4 riastrad nvif_object_fini(&fctx->sema); 67 1.1 riastrad chan->fence = NULL; 68 1.4 riastrad nouveau_fence_context_free(&fctx->base); 69 1.1 riastrad } 70 1.1 riastrad 71 1.2 riastrad static int 72 1.1 riastrad nv10_fence_context_new(struct nouveau_channel *chan) 73 1.1 riastrad { 74 1.1 riastrad struct nv10_fence_chan *fctx; 75 1.1 riastrad 76 1.1 riastrad fctx = chan->fence = kzalloc(sizeof(*fctx), GFP_KERNEL); 77 1.1 riastrad if (!fctx) 78 1.1 riastrad return -ENOMEM; 79 1.1 riastrad 80 1.4 riastrad nouveau_fence_context_new(chan, &fctx->base); 81 1.1 riastrad fctx->base.emit = nv10_fence_emit; 82 1.1 riastrad fctx->base.read = nv10_fence_read; 83 1.1 riastrad fctx->base.sync = nv10_fence_sync; 84 1.1 riastrad return 0; 85 1.1 riastrad } 86 1.1 riastrad 87 1.1 riastrad void 88 1.1 riastrad nv10_fence_destroy(struct nouveau_drm *drm) 89 1.1 riastrad { 90 1.1 riastrad struct nv10_fence_priv *priv = drm->fence; 91 1.1 riastrad nouveau_bo_unmap(priv->bo); 92 1.1 riastrad if (priv->bo) 93 1.1 riastrad nouveau_bo_unpin(priv->bo); 94 1.1 riastrad nouveau_bo_ref(NULL, &priv->bo); 95 1.1 riastrad drm->fence = NULL; 96 1.3 riastrad spin_lock_destroy(&priv->lock); 97 1.1 riastrad kfree(priv); 98 1.1 riastrad } 99 1.1 riastrad 100 1.1 riastrad int 101 1.1 riastrad nv10_fence_create(struct nouveau_drm *drm) 102 1.1 riastrad { 103 1.1 riastrad struct nv10_fence_priv *priv; 104 1.1 riastrad 105 1.1 riastrad priv = drm->fence = kzalloc(sizeof(*priv), GFP_KERNEL); 106 1.1 riastrad if (!priv) 107 1.1 riastrad return -ENOMEM; 108 1.1 riastrad 109 1.1 riastrad priv->base.dtor = nv10_fence_destroy; 110 1.1 riastrad priv->base.context_new = nv10_fence_context_new; 111 1.1 riastrad priv->base.context_del = nv10_fence_context_del; 112 1.1 riastrad spin_lock_init(&priv->lock); 113 1.1 riastrad return 0; 114 1.1 riastrad } 115