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