Home | History | Annotate | Line # | Download | only in nouveau
      1 /*	$NetBSD: nouveau_nv04_fence.c,v 1.4 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
     25  */
     26 
     27 #include <sys/cdefs.h>
     28 __KERNEL_RCSID(0, "$NetBSD: nouveau_nv04_fence.c,v 1.4 2021/12/18 23:45:32 riastradh Exp $");
     29 
     30 #include "nouveau_drv.h"
     31 #include "nouveau_dma.h"
     32 #include "nouveau_fence.h"
     33 
     34 #include <nvif/if0004.h>
     35 
     36 struct nv04_fence_chan {
     37 	struct nouveau_fence_chan base;
     38 };
     39 
     40 struct nv04_fence_priv {
     41 	struct nouveau_fence_priv base;
     42 };
     43 
     44 static int
     45 nv04_fence_emit(struct nouveau_fence *fence)
     46 {
     47 	struct nouveau_channel *chan = fence->channel;
     48 	int ret = RING_SPACE(chan, 2);
     49 	if (ret == 0) {
     50 		BEGIN_NV04(chan, NvSubSw, 0x0150, 1);
     51 		OUT_RING  (chan, fence->base.seqno);
     52 		FIRE_RING (chan);
     53 	}
     54 	return ret;
     55 }
     56 
     57 static int
     58 nv04_fence_sync(struct nouveau_fence *fence,
     59 		struct nouveau_channel *prev, struct nouveau_channel *chan)
     60 {
     61 	return -ENODEV;
     62 }
     63 
     64 static u32
     65 nv04_fence_read(struct nouveau_channel *chan)
     66 {
     67 	struct nv04_nvsw_get_ref_v0 args = {};
     68 	WARN_ON(nvif_object_mthd(&chan->nvsw, NV04_NVSW_GET_REF,
     69 				 &args, sizeof(args)));
     70 	return args.ref;
     71 }
     72 
     73 static void
     74 nv04_fence_context_del(struct nouveau_channel *chan)
     75 {
     76 	struct nv04_fence_chan *fctx = chan->fence;
     77 	nouveau_fence_context_del(&fctx->base);
     78 	chan->fence = NULL;
     79 	nouveau_fence_context_free(&fctx->base);
     80 }
     81 
     82 static int
     83 nv04_fence_context_new(struct nouveau_channel *chan)
     84 {
     85 	struct nv04_fence_chan *fctx = kzalloc(sizeof(*fctx), GFP_KERNEL);
     86 	if (fctx) {
     87 		nouveau_fence_context_new(chan, &fctx->base);
     88 		fctx->base.emit = nv04_fence_emit;
     89 		fctx->base.sync = nv04_fence_sync;
     90 		fctx->base.read = nv04_fence_read;
     91 		chan->fence = fctx;
     92 		return 0;
     93 	}
     94 	return -ENOMEM;
     95 }
     96 
     97 static void
     98 nv04_fence_destroy(struct nouveau_drm *drm)
     99 {
    100 	struct nv04_fence_priv *priv = drm->fence;
    101 	drm->fence = NULL;
    102 	kfree(priv);
    103 }
    104 
    105 int
    106 nv04_fence_create(struct nouveau_drm *drm)
    107 {
    108 	struct nv04_fence_priv *priv;
    109 
    110 	priv = drm->fence = kzalloc(sizeof(*priv), GFP_KERNEL);
    111 	if (!priv)
    112 		return -ENOMEM;
    113 
    114 	priv->base.dtor = nv04_fence_destroy;
    115 	priv->base.context_new = nv04_fence_context_new;
    116 	priv->base.context_del = nv04_fence_context_del;
    117 	return 0;
    118 }
    119