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