Home | History | Annotate | Line # | Download | only in nouveau
      1  1.4  riastrad /*	$NetBSD: nouveau_nvc0_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_nvc0_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.1  riastrad #include "nv50_display.h"
     35  1.1  riastrad 
     36  1.1  riastrad static int
     37  1.1  riastrad nvc0_fence_emit32(struct nouveau_channel *chan, u64 virtual, u32 sequence)
     38  1.1  riastrad {
     39  1.1  riastrad 	int ret = RING_SPACE(chan, 6);
     40  1.1  riastrad 	if (ret == 0) {
     41  1.1  riastrad 		BEGIN_NVC0(chan, 0, NV84_SUBCHAN_SEMAPHORE_ADDRESS_HIGH, 5);
     42  1.1  riastrad 		OUT_RING  (chan, upper_32_bits(virtual));
     43  1.1  riastrad 		OUT_RING  (chan, lower_32_bits(virtual));
     44  1.1  riastrad 		OUT_RING  (chan, sequence);
     45  1.1  riastrad 		OUT_RING  (chan, NV84_SUBCHAN_SEMAPHORE_TRIGGER_WRITE_LONG);
     46  1.1  riastrad 		OUT_RING  (chan, 0x00000000);
     47  1.1  riastrad 		FIRE_RING (chan);
     48  1.1  riastrad 	}
     49  1.1  riastrad 	return ret;
     50  1.1  riastrad }
     51  1.1  riastrad 
     52  1.1  riastrad static int
     53  1.1  riastrad nvc0_fence_sync32(struct nouveau_channel *chan, u64 virtual, u32 sequence)
     54  1.1  riastrad {
     55  1.1  riastrad 	int ret = RING_SPACE(chan, 5);
     56  1.1  riastrad 	if (ret == 0) {
     57  1.1  riastrad 		BEGIN_NVC0(chan, 0, NV84_SUBCHAN_SEMAPHORE_ADDRESS_HIGH, 4);
     58  1.1  riastrad 		OUT_RING  (chan, upper_32_bits(virtual));
     59  1.1  riastrad 		OUT_RING  (chan, lower_32_bits(virtual));
     60  1.1  riastrad 		OUT_RING  (chan, sequence);
     61  1.1  riastrad 		OUT_RING  (chan, NV84_SUBCHAN_SEMAPHORE_TRIGGER_ACQUIRE_GEQUAL |
     62  1.1  riastrad 				 NVC0_SUBCHAN_SEMAPHORE_TRIGGER_YIELD);
     63  1.1  riastrad 		FIRE_RING (chan);
     64  1.1  riastrad 	}
     65  1.1  riastrad 	return ret;
     66  1.1  riastrad }
     67  1.1  riastrad 
     68  1.1  riastrad static int
     69  1.1  riastrad nvc0_fence_context_new(struct nouveau_channel *chan)
     70  1.1  riastrad {
     71  1.1  riastrad 	int ret = nv84_fence_context_new(chan);
     72  1.1  riastrad 	if (ret == 0) {
     73  1.1  riastrad 		struct nv84_fence_chan *fctx = chan->fence;
     74  1.1  riastrad 		fctx->base.emit32 = nvc0_fence_emit32;
     75  1.1  riastrad 		fctx->base.sync32 = nvc0_fence_sync32;
     76  1.1  riastrad 	}
     77  1.1  riastrad 	return ret;
     78  1.1  riastrad }
     79  1.1  riastrad 
     80  1.1  riastrad int
     81  1.1  riastrad nvc0_fence_create(struct nouveau_drm *drm)
     82  1.1  riastrad {
     83  1.1  riastrad 	int ret = nv84_fence_create(drm);
     84  1.1  riastrad 	if (ret == 0) {
     85  1.1  riastrad 		struct nv84_fence_priv *priv = drm->fence;
     86  1.1  riastrad 		priv->base.context_new = nvc0_fence_context_new;
     87  1.1  riastrad 	}
     88  1.1  riastrad 	return ret;
     89  1.1  riastrad }
     90