nouveau_nv10_fence.c revision 1.3.18.1 1 /* $NetBSD: nouveau_nv10_fence.c,v 1.3.18.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 <bskeggs (at) redhat.com>
25 */
26
27 #include <sys/cdefs.h>
28 __KERNEL_RCSID(0, "$NetBSD: nouveau_nv10_fence.c,v 1.3.18.1 2019/06/10 22:08:06 christos Exp $");
29
30 #include "nouveau_drm.h"
31 #include "nouveau_dma.h"
32 #include "nv10_fence.h"
33
34 int
35 nv10_fence_emit(struct nouveau_fence *fence)
36 {
37 struct nouveau_channel *chan = fence->channel;
38 int ret = RING_SPACE(chan, 2);
39 if (ret == 0) {
40 BEGIN_NV04(chan, 0, NV10_SUBCHAN_REF_CNT, 1);
41 OUT_RING (chan, fence->base.seqno);
42 FIRE_RING (chan);
43 }
44 return ret;
45 }
46
47
48 static int
49 nv10_fence_sync(struct nouveau_fence *fence,
50 struct nouveau_channel *prev, struct nouveau_channel *chan)
51 {
52 return -ENODEV;
53 }
54
55 u32
56 nv10_fence_read(struct nouveau_channel *chan)
57 {
58 return nvif_rd32(&chan->user, 0x0048);
59 }
60
61 void
62 nv10_fence_context_del(struct nouveau_channel *chan)
63 {
64 struct nv10_fence_chan *fctx = chan->fence;
65 int i;
66 nouveau_fence_context_del(&fctx->base);
67 for (i = 0; i < ARRAY_SIZE(fctx->head); i++)
68 nvif_object_fini(&fctx->head[i]);
69 nvif_object_fini(&fctx->sema);
70 chan->fence = NULL;
71 nouveau_fence_context_free(&fctx->base);
72 }
73
74 static int
75 nv10_fence_context_new(struct nouveau_channel *chan)
76 {
77 struct nv10_fence_chan *fctx;
78
79 fctx = chan->fence = kzalloc(sizeof(*fctx), GFP_KERNEL);
80 if (!fctx)
81 return -ENOMEM;
82
83 nouveau_fence_context_new(chan, &fctx->base);
84 fctx->base.emit = nv10_fence_emit;
85 fctx->base.read = nv10_fence_read;
86 fctx->base.sync = nv10_fence_sync;
87 return 0;
88 }
89
90 void
91 nv10_fence_destroy(struct nouveau_drm *drm)
92 {
93 struct nv10_fence_priv *priv = drm->fence;
94 nouveau_bo_unmap(priv->bo);
95 if (priv->bo)
96 nouveau_bo_unpin(priv->bo);
97 nouveau_bo_ref(NULL, &priv->bo);
98 drm->fence = NULL;
99 spin_lock_destroy(&priv->lock);
100 kfree(priv);
101 }
102
103 int
104 nv10_fence_create(struct nouveau_drm *drm)
105 {
106 struct nv10_fence_priv *priv;
107
108 priv = drm->fence = kzalloc(sizeof(*priv), GFP_KERNEL);
109 if (!priv)
110 return -ENOMEM;
111
112 priv->base.dtor = nv10_fence_destroy;
113 priv->base.context_new = nv10_fence_context_new;
114 priv->base.context_del = nv10_fence_context_del;
115 priv->base.contexts = 31;
116 priv->base.context_base = fence_context_alloc(priv->base.contexts);
117 spin_lock_init(&priv->lock);
118 return 0;
119 }
120