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