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