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